Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import torch
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
|
@@ -6,11 +5,11 @@ st.set_page_config(page_title="Common NLP Tasks")
|
|
6 |
st.title("Common NLP Tasks")
|
7 |
st.subheader("Use the menu on the left to select a NLP task to do (click on > if closed).")
|
8 |
|
9 |
-
expander = st.sidebar.expander(
|
10 |
expander.write("This web app allows you to perform common Natural Language Processing tasks, select a task below to get started.")
|
11 |
|
12 |
-
st.sidebar.header(
|
13 |
-
option = st.sidebar.radio(
|
14 |
|
15 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
16 |
def question_model():
|
@@ -33,7 +32,7 @@ def sentiment_model():
|
|
33 |
sentiment_analysis = pipeline("sentiment-analysis")
|
34 |
return sentiment_analysis
|
35 |
|
36 |
-
if option ==
|
37 |
st.markdown("<h2 style='text-align: center; color:red;'>Extract answer from text</h2>", unsafe_allow_html=True)
|
38 |
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"])
|
39 |
if source == "I want to input some text":
|
@@ -46,7 +45,7 @@ if option == 'Extractive question answering':
|
|
46 |
question_answerer = question_model()
|
47 |
with st.spinner(text="Getting answer..."):
|
48 |
answer = question_answerer(context=context, question=question)
|
49 |
-
st.write(answer["answer"])
|
50 |
elif source == "I want to upload a file":
|
51 |
uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
|
52 |
question = st.text_input(label='Enter your question')
|
@@ -54,8 +53,8 @@ if option == 'Extractive question answering':
|
|
54 |
if button:
|
55 |
question_answerer = question_model()
|
56 |
with st.spinner(text="Getting answer..."):
|
57 |
-
answer = question_answerer(context=
|
58 |
-
st.write(answer["answer"])
|
59 |
|
60 |
elif option == 'Text summarization':
|
61 |
st.markdown("<h2 style='text-align: center; color:red;'>Summarize text</h2>", unsafe_allow_html=True)
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
|
|
5 |
st.title("Common NLP Tasks")
|
6 |
st.subheader("Use the menu on the left to select a NLP task to do (click on > if closed).")
|
7 |
|
8 |
+
expander = st.sidebar.expander("About")
|
9 |
expander.write("This web app allows you to perform common Natural Language Processing tasks, select a task below to get started.")
|
10 |
|
11 |
+
st.sidebar.header("What will you like to do?")
|
12 |
+
option = st.sidebar.radio("", ["Extractive question answering", "Text summarization", "Text generation", "Sentiment analysis"])
|
13 |
|
14 |
@st.cache(show_spinner=False, allow_output_mutation=True)
|
15 |
def question_model():
|
|
|
32 |
sentiment_analysis = pipeline("sentiment-analysis")
|
33 |
return sentiment_analysis
|
34 |
|
35 |
+
if option == "Extractive question answering":
|
36 |
st.markdown("<h2 style='text-align: center; color:red;'>Extract answer from text</h2>", unsafe_allow_html=True)
|
37 |
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"])
|
38 |
if source == "I want to input some text":
|
|
|
45 |
question_answerer = question_model()
|
46 |
with st.spinner(text="Getting answer..."):
|
47 |
answer = question_answerer(context=context, question=question)
|
48 |
+
st.write(f"Answer: {answer["answer"]}")
|
49 |
elif source == "I want to upload a file":
|
50 |
uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
|
51 |
question = st.text_input(label='Enter your question')
|
|
|
53 |
if button:
|
54 |
question_answerer = question_model()
|
55 |
with st.spinner(text="Getting answer..."):
|
56 |
+
answer = question_answerer(context=uploaded_file, question=question)
|
57 |
+
st.write(f"Answer: {answer["answer"]}")
|
58 |
|
59 |
elif option == 'Text summarization':
|
60 |
st.markdown("<h2 style='text-align: center; color:red;'>Summarize text</h2>", unsafe_allow_html=True)
|