kxx-kkk commited on
Commit
03f073b
·
verified ·
1 Parent(s): 528e5aa

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -4,17 +4,9 @@ from transformers import pipeline
4
  st.set_page_config(page_title="Automated Question Answering System")
5
  st.title("Automated Question Answering System")
6
  st.subheader("Try")
7
- # """
8
- # [![](https://img.shields.io/github/followers/OOlajide?label=OOlajide&style=social)](https://gitHub.com/OOlajide)
9
- # [![](https://img.shields.io/twitter/follow/sageOlamide?label=@sageOlamide&style=social)](https://twitter.com/sageOlamide)
10
- # """
11
- # expander = st.sidebar.expander("About")
12
- # expander.write("This web app allows you to perform common Natural Language Processing tasks, select a task below to get started.")
13
 
14
- # st.sidebar.header("What will you like to do?")
15
- # option = st.sidebar.radio("", ["Text summarization", "Extractive question answering", "Text generation"])
16
 
17
- @st.cache_data(show_spinner=True)
18
  def question_model():
19
  model_name = "deepset/roberta-base-squad2"
20
  question_answerer = pipeline(model=model_name, tokenizer=model_name, task="question-answering")
@@ -23,20 +15,17 @@ def question_model():
23
  st.markdown("<h2 style='text-align: center; color:grey;'>Question Answering on Academic Essays</h2>", unsafe_allow_html=True)
24
  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)
25
  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.")
26
- st.markdown('___')
27
-
28
- # source = st.radio("How would you upload the essay? Choose an option below", ["I want to input some text", "I want to upload a file"])
29
-
30
- sample_question = "What is NLP?"
31
 
32
  tab1, tab2 = st.tabs(["Input text", "Upload File"])
33
 
34
- # if source == "I want to input some text":
35
- with tab1:
36
  with open("sample.txt", "r") as text_file:
37
  sample_text = text_file.read()
38
- 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)
39
- question = st.text_input(label="Use the question below or enter your own question", value=sample_question)
 
40
  button = st.button("Get answer")
41
  if button:
42
  with st.spinner(text="Loading question model..."):
@@ -44,10 +33,8 @@ with tab1:
44
  with st.spinner(text="Getting answer..."):
45
  answer = question_answerer(context=context, question=question)
46
  answer = answer["answer"]
47
-
48
- st.success(answer)
49
 
50
- # elif source == "I want to upload a file":
51
  with tab2:
52
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
53
  if uploaded_file is not None:
@@ -56,7 +43,7 @@ with tab2:
56
  question = st.text_input(label="Enter your question", value=sample_question)
57
  button = st.button("Get answer")
58
  if button:
59
- with st.spinner(text="Loading summarization model..."):
60
  question_answerer = question_model()
61
  with st.spinner(text="Getting answer..."):
62
  answer = question_answerer(context=context, question=question)
 
4
  st.set_page_config(page_title="Automated Question Answering System")
5
  st.title("Automated Question Answering System")
6
  st.subheader("Try")
 
 
 
 
 
 
7
 
8
+ @st.cache_resource(show_spinner=True)
 
9
 
 
10
  def question_model():
11
  model_name = "deepset/roberta-base-squad2"
12
  question_answerer = pipeline(model=model_name, tokenizer=model_name, task="question-answering")
 
15
  st.markdown("<h2 style='text-align: center; color:grey;'>Question Answering on Academic Essays</h2>", unsafe_allow_html=True)
16
  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)
17
  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.")
18
+ # st.markdown('___')
 
 
 
 
19
 
20
  tab1, tab2 = st.tabs(["Input text", "Upload File"])
21
 
22
+ with tab1:
23
+ sample_question = "What is NLP?"
24
  with open("sample.txt", "r") as text_file:
25
  sample_text = text_file.read()
26
+
27
+ context = st.text_area("Use the example below / input your essay in English (10,000 characters max)", value=sample_text, max_chars=10000, height=330)
28
+ question = st.text_input(label="Use the example question below / enter your own question", value=sample_question)
29
  button = st.button("Get answer")
30
  if button:
31
  with st.spinner(text="Loading question model..."):
 
33
  with st.spinner(text="Getting answer..."):
34
  answer = question_answerer(context=context, question=question)
35
  answer = answer["answer"]
36
+ st.success('___' + answer)
 
37
 
 
38
  with tab2:
39
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
40
  if uploaded_file is not None:
 
43
  question = st.text_input(label="Enter your question", value=sample_question)
44
  button = st.button("Get answer")
45
  if button:
46
+ with st.spinner(text="Loading question model..."):
47
  question_answerer = question_model()
48
  with st.spinner(text="Getting answer..."):
49
  answer = question_answerer(context=context, question=question)