Spaces:
Sleeping
Sleeping
Commit
·
b4ab6aa
1
Parent(s):
b45a3c5
Update pages/answers.py
Browse files- pages/answers.py +22 -14
pages/answers.py
CHANGED
@@ -1,7 +1,14 @@
|
|
1 |
import random
|
2 |
import streamlit as st
|
3 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
|
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
model_name = "deepset/roberta-base-squad2"
|
7 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
@@ -50,33 +57,34 @@ def get_answer(context, question):
|
|
50 |
answer = res['answer']
|
51 |
return answer
|
52 |
|
|
|
53 |
def main():
|
54 |
st.title("Question Answering App :robot_face:")
|
55 |
-
st.
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
context_placeholder =
|
59 |
-
question_placeholder =
|
60 |
-
|
61 |
-
context = st.sidebar.text_area("Context", value=context_placeholder)
|
62 |
-
question = st.sidebar.text_input("Question", value=question_placeholder)
|
63 |
|
64 |
-
|
|
|
|
|
|
|
65 |
pair = random.choice(pairs)
|
66 |
context = pair['context']
|
67 |
question = pair['question']
|
|
|
|
|
|
|
68 |
|
69 |
-
if st.button("Get Answer"):
|
70 |
if context.strip() == "" or question.strip() == "":
|
71 |
st.warning("Please enter the context and question.")
|
72 |
else:
|
73 |
answer = get_answer(context, question)
|
74 |
st.success(f"Answer: {answer}")
|
75 |
|
76 |
-
|
77 |
if __name__ == "__main__":
|
78 |
main()
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
1 |
import random
|
2 |
import streamlit as st
|
3 |
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
4 |
+
from streamlit_extras.let_it_rain import rain
|
5 |
|
6 |
+
rain(
|
7 |
+
emoji="❔",
|
8 |
+
font_size=54,
|
9 |
+
falling_speed=5,
|
10 |
+
animation_length="infinite",
|
11 |
+
)
|
12 |
|
13 |
model_name = "deepset/roberta-base-squad2"
|
14 |
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
|
|
57 |
answer = res['answer']
|
58 |
return answer
|
59 |
|
60 |
+
|
61 |
def main():
|
62 |
st.title("Question Answering App :robot_face:")
|
63 |
+
st.sidebar.markdown("### **Choose a Pair:**")
|
64 |
+
|
65 |
+
pair_names = [f"Pair {i+1}" for i in range(len(pairs))]
|
66 |
+
selected_pair_index = st.sidebar.selectbox("Select Pair", pair_names, key='pair_selection')
|
67 |
|
68 |
+
context_placeholder = pairs[selected_pair_index]['context']
|
69 |
+
question_placeholder = pairs[selected_pair_index]['question']
|
|
|
|
|
|
|
70 |
|
71 |
+
context = st.text_area("**:blue[Context]**", context_placeholder)
|
72 |
+
question = st.text_input("**:blue[Question]**", question_placeholder)
|
73 |
+
|
74 |
+
if st.button(":blue[**Random Example**]"):
|
75 |
pair = random.choice(pairs)
|
76 |
context = pair['context']
|
77 |
question = pair['question']
|
78 |
+
|
79 |
+
st.text_area("**:blue[Context]**", context)
|
80 |
+
st.text_input("**:blue[Question]**", question)
|
81 |
|
82 |
+
if st.button(":blue[**Get Answer**]"):
|
83 |
if context.strip() == "" or question.strip() == "":
|
84 |
st.warning("Please enter the context and question.")
|
85 |
else:
|
86 |
answer = get_answer(context, question)
|
87 |
st.success(f"Answer: {answer}")
|
88 |
|
|
|
89 |
if __name__ == "__main__":
|
90 |
main()
|
|
|
|
|
|
|
|