Spaces:
Sleeping
Sleeping
Delete answers.py
Browse files- answers.py +0 -35
answers.py
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
3 |
-
|
4 |
-
model_name = "deepset/roberta-base-squad2"
|
5 |
-
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
-
|
8 |
-
def get_answer(context, question):
|
9 |
-
nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
10 |
-
QA_input = {'question': question, 'context': context}
|
11 |
-
res = nlp(QA_input)
|
12 |
-
answer = res['answer']
|
13 |
-
return answer
|
14 |
-
|
15 |
-
def main():
|
16 |
-
st.title("Question Answering App")
|
17 |
-
st.markdown("Enter the context and question, then click on 'Get Answer' to retrieve the answer.")
|
18 |
-
|
19 |
-
|
20 |
-
context = st.text_area("Context", "Enter the context here...")
|
21 |
-
question = st.text_input("Question", "Enter the question here...")
|
22 |
-
|
23 |
-
|
24 |
-
if st.button("Get Answer"):
|
25 |
-
|
26 |
-
if context.strip() == "" or question.strip() == "":
|
27 |
-
st.warning("Please enter the context and question.")
|
28 |
-
else:
|
29 |
-
|
30 |
-
answer = get_answer(context, question)
|
31 |
-
st.success(f"Answer: {answer}")
|
32 |
-
|
33 |
-
|
34 |
-
if __name__ == "__main__":
|
35 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|