Spaces:
Sleeping
Sleeping
shambhuDATA
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForQuestionAnswering,
|
2 |
+
AutoTokenizer,pipeline
|
3 |
+
import streamlit as st
|
4 |
+
import ast
|
5 |
+
model_name="deepset/roberta-base-squade2"
|
6 |
+
pipe=pipeline('question-answering',model=model_name,tokenizer=model_name)
|
7 |
+
def answer_question(question,context):
|
8 |
+
text="{"+"'question': '"+question + "',''context':'"+context+"'}"
|
9 |
+
di= ast.literal_eval(text)
|
10 |
+
response= pipe(di)
|
11 |
+
return response
|
12 |
+
|
13 |
+
st.title("Q&A App")
|
14 |
+
|
15 |
+
context = st.text_area("Enter the context:")
|
16 |
+
question = st.text_input("Enter your question:")
|
17 |
+
|
18 |
+
if st.button("Get Answer"):
|
19 |
+
answer = answer_question(context, question)
|
20 |
+
st.write(f"Answer: {answer}")
|
21 |
+
|