Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,7 +19,8 @@ def question_model():
|
|
| 19 |
|
| 20 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
| 21 |
def summarization_model():
|
| 22 |
-
|
|
|
|
| 23 |
return summarizer
|
| 24 |
|
| 25 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
|
@@ -62,17 +63,18 @@ if option == "Extractive question answering":
|
|
| 62 |
answer = answer["answer"]
|
| 63 |
st.text(answer)
|
| 64 |
|
| 65 |
-
elif option ==
|
| 66 |
st.markdown("<h2 style='text-align: center; color:red;'>Summarize text</h2>", unsafe_allow_html=True)
|
| 67 |
-
sample_text = "sample text"
|
| 68 |
source = st.radio("How would you like to start? Choose an option below", ["I want to input some text", "I want to upload a file"])
|
| 69 |
if source == "I want to input some text":
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
if button:
|
| 73 |
summarizer = summarization_model()
|
| 74 |
with st.spinner(text="Summarizing text..."):
|
| 75 |
-
summary = summarizer(text
|
| 76 |
st.write(summary)
|
| 77 |
|
| 78 |
elif source == "I want to upload a file":
|
|
|
|
| 19 |
|
| 20 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
| 21 |
def summarization_model():
|
| 22 |
+
model_name = "google/pegasus-xsum"
|
| 23 |
+
summarizer = pipeline(model=model_name, tokenizer=model_name, task="summarization")
|
| 24 |
return summarizer
|
| 25 |
|
| 26 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
|
|
|
| 63 |
answer = answer["answer"]
|
| 64 |
st.text(answer)
|
| 65 |
|
| 66 |
+
elif option == "Text summarization":
|
| 67 |
st.markdown("<h2 style='text-align: center; color:red;'>Summarize text</h2>", unsafe_allow_html=True)
|
|
|
|
| 68 |
source = st.radio("How would you like to start? Choose an option below", ["I want to input some text", "I want to upload a file"])
|
| 69 |
if source == "I want to input some text":
|
| 70 |
+
with open("sample.txt", "r") as text_file:
|
| 71 |
+
sample_text = text_file.read()
|
| 72 |
+
text = st.text_area("Input a text in English (10,000 characters max)", value=sample_text, max_chars=10000, height=330)
|
| 73 |
+
button = st.button("Get summary")
|
| 74 |
if button:
|
| 75 |
summarizer = summarization_model()
|
| 76 |
with st.spinner(text="Summarizing text..."):
|
| 77 |
+
summary = summarizer(text)
|
| 78 |
st.write(summary)
|
| 79 |
|
| 80 |
elif source == "I want to upload a file":
|