Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,8 @@ def summarization_model():
|
|
| 25 |
|
| 26 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
| 27 |
def generation_model():
|
| 28 |
-
|
|
|
|
| 29 |
return generator
|
| 30 |
|
| 31 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
|
@@ -40,10 +41,11 @@ if option == "Extractive question answering":
|
|
| 40 |
with open("sample.txt", "r") as text_file:
|
| 41 |
sample_text = text_file.read()
|
| 42 |
context = st.text_area('Use the example below or input your own text in English (10,000 characters max)', value=sample_text, max_chars=10000, height=330)
|
| 43 |
-
question = st.text_input(label=
|
| 44 |
-
button = st.button(
|
| 45 |
if button:
|
| 46 |
-
|
|
|
|
| 47 |
with st.spinner(text="Getting answer..."):
|
| 48 |
answer = question_answerer(context=context, question=question)
|
| 49 |
answer = answer["answer"]
|
|
@@ -57,7 +59,8 @@ if option == "Extractive question answering":
|
|
| 57 |
question = st.text_input(label="Enter your question")
|
| 58 |
button = st.button("Get answer")
|
| 59 |
if button:
|
| 60 |
-
|
|
|
|
| 61 |
with st.spinner(text="Getting answer..."):
|
| 62 |
answer = question_answerer(context=context, question=question)
|
| 63 |
answer = answer["answer"]
|
|
@@ -72,7 +75,8 @@ elif option == "Text summarization":
|
|
| 72 |
text = st.text_area("Input a text in English (10,000 characters max) or use the example below", value=sample_text, max_chars=10000, height=330)
|
| 73 |
button = st.button("Get summary")
|
| 74 |
if button:
|
| 75 |
-
|
|
|
|
| 76 |
with st.spinner(text="Summarizing text..."):
|
| 77 |
summary = summarizer(text, max_length=130, min_length=30)
|
| 78 |
st.write(summary[0]["summary_text"])
|
|
@@ -90,22 +94,24 @@ elif option == "Text summarization":
|
|
| 90 |
summary = summarizer(text, max_length=130, min_length=30)
|
| 91 |
st.write(summary[0]["summary_text"])
|
| 92 |
|
| 93 |
-
elif option ==
|
| 94 |
st.markdown("<h2 style='text-align: center; color:grey;'>Generate text</h2>", unsafe_allow_html=True)
|
| 95 |
-
text = st.text_input(label=
|
| 96 |
-
button = st.button(
|
| 97 |
if button:
|
| 98 |
-
|
|
|
|
| 99 |
with st.spinner(text="Generating text..."):
|
| 100 |
generated_text = generator(text, max_length=50)
|
| 101 |
st.write(generated_text[0]["generated_text"])
|
| 102 |
|
| 103 |
-
elif option ==
|
| 104 |
st.markdown("<h2 style='text-align: center; color:grey;'>Classify review</h2>", unsafe_allow_html=True)
|
| 105 |
text = st.text_input(label='Enter a sentence to get its sentiment analysis')
|
| 106 |
-
button = st.button(
|
| 107 |
if button:
|
| 108 |
-
|
|
|
|
| 109 |
with st.spinner(text="Getting sentiment analysis..."):
|
| 110 |
sentiment = sentiment_analysis(text)
|
| 111 |
st.write(sentiment[0]["label"])
|
|
|
|
| 25 |
|
| 26 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
| 27 |
def generation_model():
|
| 28 |
+
model_name = "distilgpt2"
|
| 29 |
+
generator = pipeline(model=model_name, tokenizer=model_name, task="text-generation")
|
| 30 |
return generator
|
| 31 |
|
| 32 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
|
|
|
| 41 |
with open("sample.txt", "r") as text_file:
|
| 42 |
sample_text = text_file.read()
|
| 43 |
context = st.text_area('Use the example below or input your own text in English (10,000 characters max)', value=sample_text, max_chars=10000, height=330)
|
| 44 |
+
question = st.text_input(label="Enter your question")
|
| 45 |
+
button = st.button("Get answer")
|
| 46 |
if button:
|
| 47 |
+
with st.spinner(text="Loading question model..."):
|
| 48 |
+
question_answerer = question_model()
|
| 49 |
with st.spinner(text="Getting answer..."):
|
| 50 |
answer = question_answerer(context=context, question=question)
|
| 51 |
answer = answer["answer"]
|
|
|
|
| 59 |
question = st.text_input(label="Enter your question")
|
| 60 |
button = st.button("Get answer")
|
| 61 |
if button:
|
| 62 |
+
with st.spinner(text="Loading summarization model..."):
|
| 63 |
+
question_answerer = question_model()
|
| 64 |
with st.spinner(text="Getting answer..."):
|
| 65 |
answer = question_answerer(context=context, question=question)
|
| 66 |
answer = answer["answer"]
|
|
|
|
| 75 |
text = st.text_area("Input a text in English (10,000 characters max) or use the example below", value=sample_text, max_chars=10000, height=330)
|
| 76 |
button = st.button("Get summary")
|
| 77 |
if button:
|
| 78 |
+
with st.spinner(text="Loading summarization model..."):
|
| 79 |
+
summarizer = summarization_model()
|
| 80 |
with st.spinner(text="Summarizing text..."):
|
| 81 |
summary = summarizer(text, max_length=130, min_length=30)
|
| 82 |
st.write(summary[0]["summary_text"])
|
|
|
|
| 94 |
summary = summarizer(text, max_length=130, min_length=30)
|
| 95 |
st.write(summary[0]["summary_text"])
|
| 96 |
|
| 97 |
+
elif option == "Text generation":
|
| 98 |
st.markdown("<h2 style='text-align: center; color:grey;'>Generate text</h2>", unsafe_allow_html=True)
|
| 99 |
+
text = st.text_input(label="Enter one line of text and let the NLP model generate the rest for you")
|
| 100 |
+
button = st.button("Generate text")
|
| 101 |
if button:
|
| 102 |
+
with st.spinner(text="Loading text generation model..."):
|
| 103 |
+
generator = generation_model()
|
| 104 |
with st.spinner(text="Generating text..."):
|
| 105 |
generated_text = generator(text, max_length=50)
|
| 106 |
st.write(generated_text[0]["generated_text"])
|
| 107 |
|
| 108 |
+
elif option == "Sentiment analysis":
|
| 109 |
st.markdown("<h2 style='text-align: center; color:grey;'>Classify review</h2>", unsafe_allow_html=True)
|
| 110 |
text = st.text_input(label='Enter a sentence to get its sentiment analysis')
|
| 111 |
+
button = st.button("Get sentiment analysis")
|
| 112 |
if button:
|
| 113 |
+
with st.spinner(text="Loading sentiment analysis model..."):
|
| 114 |
+
sentiment_analysis = sentiment_model()
|
| 115 |
with st.spinner(text="Getting sentiment analysis..."):
|
| 116 |
sentiment = sentiment_analysis(text)
|
| 117 |
st.write(sentiment[0]["label"])
|