kxx-kkk commited on
Commit
109a51e
1 Parent(s): 7896d94

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
  st.set_page_config(page_title="Automated Question Answering System")
5
  st.title("Automated Question Answering System")
@@ -8,7 +9,9 @@ st.subheader("Try")
8
  @st.cache_resource(show_spinner=True)
9
  def question_model():
10
  model_name = "deepset/roberta-base-squad2"
11
- question_answerer = pipeline(model=model_name, tokenizer=model_name, task="question-answering")
 
 
12
  return question_answerer
13
 
14
  st.markdown("<h2 style='text-align: center; color:grey;'>Question Answering on Academic Essays</h2>", unsafe_allow_html=True)
@@ -33,7 +36,7 @@ with tab1:
33
  answer = question_answerer(context=context, question=question)
34
  answer = answer["answer"]
35
  container = st.container(border=True)
36
- container.write("<h5><b>Answer:</b></h5><hr>" + answer, unsafe_allow_html=True)
37
 
38
  with tab2:
39
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer
4
 
5
  st.set_page_config(page_title="Automated Question Answering System")
6
  st.title("Automated Question Answering System")
 
9
  @st.cache_resource(show_spinner=True)
10
  def question_model():
11
  model_name = "deepset/roberta-base-squad2"
12
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
13
+ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
14
+ question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer)
15
  return question_answerer
16
 
17
  st.markdown("<h2 style='text-align: center; color:grey;'>Question Answering on Academic Essays</h2>", unsafe_allow_html=True)
 
36
  answer = question_answerer(context=context, question=question)
37
  answer = answer["answer"]
38
  container = st.container(border=True)
39
+ container.write("<h5><b>Answer:</b></h5>" + answer, unsafe_allow_html=True)
40
 
41
  with tab2:
42
  uploaded_file = st.file_uploader("Choose a .txt file to upload", type=["txt"])