kxx-kkk commited on
Commit
3361ae0
1 Parent(s): baaec0e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -21,6 +21,16 @@ def question_model():
21
  question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer)
22
  return question_answerer
23
 
 
 
 
 
 
 
 
 
 
 
24
  # choose the source with different tabs
25
  tab1, tab2 = st.tabs(["Input text", "Upload File"])
26
 
@@ -48,16 +58,9 @@ with tab1:
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..."):
54
- question_answerer = question_model()
55
- with st.spinner(text="Getting answer..."):
56
- answer = question_answerer(context=context, question=question)
57
- answer = answer["answer"]
58
- # display the result in container
59
- container = st.container(border=True)
60
- container.write("<h5><b>Answer:</b></h5>" + answer + "<br>", unsafe_allow_html=True)
61
 
62
 
63
  # if upload file as input
@@ -72,16 +75,9 @@ with tab2:
72
  question = st.text_input(label="Enter your question", value=sample_question)
73
 
74
  # perform question answering when "get answer" button clicked
75
- button2 = st.button("Get answer")
76
  if button2:
77
- with st.spinner(text="Loading question model..."):
78
- question_answerer = question_model()
79
- with st.spinner(text="Getting answer..."):
80
- answer = question_answerer(context=context, question=question)
81
- answer = answer["answer"]
82
- # display the result in container
83
- container = st.container(border=True)
84
- container.write("<h5><b>Answer:</b></h5>" + answer + "<br>", unsafe_allow_html=True)
85
 
86
  st.markdown("<br><br><br><br><br>", unsafe_allow_html=True)
87
 
 
21
  question_answerer = pipeline("question-answering", model=model, tokenizer=tokenizer)
22
  return question_answerer
23
 
24
+ def question_answering(context, question):
25
+ with st.spinner(text="Loading question model..."):
26
+ question_answerer = question_model()
27
+ with st.spinner(text="Getting answer..."):
28
+ answer = question_answerer(context=context, question=question)
29
+ answer = answer["answer"]
30
+ # display the result in container
31
+ container = st.container(border=True)
32
+ container.write("<h5><b>Answer:</b></h5>" + answer + "<br>", unsafe_allow_html=True)
33
+
34
  # choose the source with different tabs
35
  tab1, tab2 = st.tabs(["Input text", "Upload File"])
36
 
 
58
  question = st.text_input(label="Enter the question: ", value=question, key="questionInput")
59
 
60
  # perform question answering when "get answer" button clicked
61
+ button = st.button("Get answer", key="textInput")
62
  if button:
63
+ question_answering(context, question)
 
 
 
 
 
 
 
64
 
65
 
66
  # if upload file as input
 
75
  question = st.text_input(label="Enter your question", value=sample_question)
76
 
77
  # perform question answering when "get answer" button clicked
78
+ button2 = st.button("Get answer", key="fileInput")
79
  if button2:
80
+ question_answering(context, question)
 
 
 
 
 
 
 
81
 
82
  st.markdown("<br><br><br><br><br>", unsafe_allow_html=True)
83