karthi311 commited on
Commit
a5a1104
·
verified ·
1 Parent(s): a9986f3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the summarization model (facebook/bart-large-cnn)
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+ # Use a smaller grammar correction model
8
+ grammar_correction_pipe = pipeline("text2text-generation", model="pszemraj/grammar-synthesis-small")
9
+
10
+ # Function for grammar correction
11
+ def correct_grammar(user_input):
12
+ if user_input.strip():
13
+ corrected_text = grammar_correction_pipe(user_input)[0]['generated_text']
14
+ return corrected_text
15
+ else:
16
+ return "Please enter some text for grammar correction."
17
+
18
+ # Function for text summarization
19
+ def summarize_text(user_input):
20
+ if user_input.strip():
21
+ summary = summarizer(user_input, max_length=150, min_length=50, do_sample=False)[0]['summary_text']
22
+ return summary
23
+ else:
24
+ return "Please enter some text to summarize."
25
+
26
+ # Function to combine grammar correction and summarization
27
+ def correct_and_summarize(user_input):
28
+ corrected_text = correct_grammar(user_input) # First correct the grammar
29
+ summary = summarize_text(corrected_text) # Then summarize the corrected text
30
+ return summary
31
+
32
+ # Streamlit UI setup
33
+ st.title("Text Summarization and Grammar Correction Assistant")
34
+
35
+ # Dropdown to select task
36
+ task = st.selectbox("Choose a task", ["Summarize Text", "Correct Grammar"])
37
+
38
+ # Input component for text
39
+ user_input = st.text_area("Enter your text here:")
40
+
41
+ # Button to submit the input
42
+ if st.button("Submit"):
43
+ if task == "Summarize Text":
44
+ output = correct_and_summarize(user_input) # Correct grammar, then summarize
45
+ elif task == "Correct Grammar":
46
+ output = correct_grammar(user_input) # Only correct grammar
47
+
48
+ # Display the result
49
+ st.text_area("Output", output, height=200)