Spaces:
Runtime error
Runtime error
File size: 1,364 Bytes
e3c9c8c 33855af 21c037f 33855af e3c9c8c 4d18090 9de557a 21c037f e3c9c8c f26d1dc e3c9c8c f808445 e3c9c8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import streamlit as st
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
from streamlit_extras.let_it_rain import rain
rain(
emoji="❔",
font_size=54,
falling_speed=5,
animation_length="infinite",
)
model_name = "timpal0l/mdeberta-v3-base-squad2"
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def get_answer(context, question):
nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
QA_input = {'question': question, 'context': context}
res = nlp(QA_input)
answer = res['answer']
return answer
def main():
st.title("Question Answering App :robot_face:")
st.divider()
st.markdown("### **Enter the context and question, then click on ':blue[Get Answer]' to retrieve the answer:**")
context = st.text_area("**:blue[Context]**", "Enter the context here...")
question = st.text_input("**:blue[Question]**", "Enter the question here...")
if st.button(":blue[**Get Answer**]"):
if context.strip() == "" or question.strip() == "":
st.warning("Please enter the context and question.")
else:
answer = get_answer(context, question)
st.success(f"Answer: {answer}")
if __name__ == "__main__":
main()
|