Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,14 @@ from transformers import AutoModelForQuestionAnswering, AutoTokenizer
|
|
4 |
|
5 |
# set page title
|
6 |
st.set_page_config(page_title="Automated Question Answering System")
|
7 |
-
|
8 |
-
|
|
|
9 |
st.markdown("<h3 style='text-align: left; color:#F63366; font-size:18px;'><b>What is extractive question answering about?<b></h3>", unsafe_allow_html=True)
|
10 |
st.write("Extractive question answering is a Natural Language Processing task where text is provided for a model so that the model can refer to it and make predictions about where the answer to a question is.")
|
11 |
-
# st.markdown('___')
|
12 |
|
13 |
-
|
14 |
-
# ref: https://docs.streamlit.io/library/advanced-features/caching
|
15 |
@st.cache_resource(show_spinner=True)
|
16 |
def question_model():
|
17 |
# call my model for question answering
|
@@ -25,7 +25,8 @@ def question_model():
|
|
25 |
tab1, tab2 = st.tabs(["Input text", "Upload File"])
|
26 |
|
27 |
# if type the text as input
|
28 |
-
with tab1:
|
|
|
29 |
sample_question = "What is NLP?"
|
30 |
with open("sample.txt", "r") as text_file:
|
31 |
sample_text = text_file.read()
|
@@ -46,6 +47,7 @@ with tab1:
|
|
46 |
context = st.text_area("Enter the essay below:", value=context, key="contextInput", height=330)
|
47 |
question = st.text_input(label="Enter the question: ", value=question, key="questionInput")
|
48 |
|
|
|
49 |
button = st.button("Get answer")
|
50 |
if button:
|
51 |
with st.spinner(text="Loading question model..."):
|
@@ -56,13 +58,19 @@ with tab1:
|
|
56 |
container = st.container(border=True)
|
57 |
container.write("<h5><b>Answer:</b></h5>" + answer, unsafe_allow_html=True)
|
58 |
|
|
|
59 |
# if upload file as input
|
60 |
with tab2:
|
|
|
61 |
uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
|
|
|
|
|
62 |
if uploaded_file is not None:
|
63 |
raw_text = str(uploaded_file.read(),"utf-8")
|
64 |
context = st.text_area("", value=raw_text, height=330)
|
65 |
question = st.text_input(label="Enter your question", value=sample_question)
|
|
|
|
|
66 |
button = st.button("Get answer")
|
67 |
if button:
|
68 |
with st.spinner(text="Loading question model..."):
|
|
|
4 |
|
5 |
# set page title
|
6 |
st.set_page_config(page_title="Automated Question Answering System")
|
7 |
+
|
8 |
+
# heading and description
|
9 |
+
st.markdown("<h2 style='text-align: center;'>Question Answering on Academic Essays</h2>", unsafe_allow_html=True)
|
10 |
st.markdown("<h3 style='text-align: left; color:#F63366; font-size:18px;'><b>What is extractive question answering about?<b></h3>", unsafe_allow_html=True)
|
11 |
st.write("Extractive question answering is a Natural Language Processing task where text is provided for a model so that the model can refer to it and make predictions about where the answer to a question is.")
|
|
|
12 |
|
13 |
+
|
14 |
+
# store the model in cache resources to enhance efficiency (ref: https://docs.streamlit.io/library/advanced-features/caching)
|
15 |
@st.cache_resource(show_spinner=True)
|
16 |
def question_model():
|
17 |
# call my model for question answering
|
|
|
25 |
tab1, tab2 = st.tabs(["Input text", "Upload File"])
|
26 |
|
27 |
# if type the text as input
|
28 |
+
with tab1:
|
29 |
+
# set the example
|
30 |
sample_question = "What is NLP?"
|
31 |
with open("sample.txt", "r") as text_file:
|
32 |
sample_text = text_file.read()
|
|
|
47 |
context = st.text_area("Enter the essay below:", value=context, key="contextInput", height=330)
|
48 |
question = st.text_input(label="Enter the question: ", value=question, key="questionInput")
|
49 |
|
50 |
+
# perform question answering when "get answer" button clicked
|
51 |
button = st.button("Get answer")
|
52 |
if button:
|
53 |
with st.spinner(text="Loading question model..."):
|
|
|
58 |
container = st.container(border=True)
|
59 |
container.write("<h5><b>Answer:</b></h5>" + answer, unsafe_allow_html=True)
|
60 |
|
61 |
+
|
62 |
# if upload file as input
|
63 |
with tab2:
|
64 |
+
# provide upload place
|
65 |
uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
|
66 |
+
|
67 |
+
# transfer file to context and allow ask question, then perform question answering
|
68 |
if uploaded_file is not None:
|
69 |
raw_text = str(uploaded_file.read(),"utf-8")
|
70 |
context = st.text_area("", value=raw_text, height=330)
|
71 |
question = st.text_input(label="Enter your question", value=sample_question)
|
72 |
+
|
73 |
+
# perform question answering when "get answer" button clicked
|
74 |
button = st.button("Get answer")
|
75 |
if button:
|
76 |
with st.spinner(text="Loading question model..."):
|