IT-distillbert / app.py
shambhuDATA's picture
Update app.py
cc11973 verified
raw
history blame contribute delete
640 Bytes
from transformers import AutoModelForQuestionAnswering,AutoTokenizer,pipeline
import streamlit as st
import ast
model_name="deepset/roberta-base-squad2"
pipe=pipeline('question-answering',model=model_name,tokenizer=model_name)
def answer_question(question,context):
text="{"+"'question': '"+question + "','context':'"+context+"'}"
di= ast.literal_eval(text)
response= pipe(di)
return response
st.title("Q&A App")
context = st.text_area("Enter the context:")
question = st.text_input("Enter your question:")
if st.button("Get Answer"):
answer = answer_question(context, question)
st.write(f"Answer: {answer}")