Spaces:
Running
Running
File size: 1,426 Bytes
12b0cd8 a386893 12b0cd8 |
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 |
import streamlit as st
from simpletransformers.question_answering import QuestionAnsweringModel
# Load your model
model_path = "best_model"
model = QuestionAnsweringModel("distilbert", model_path, use_cuda=False)
# Streamlit app
st.title("Question Answering Model (DistilBERT)")
# Input fields
context = st.text_area("Context:")
question = st.text_input("Question:")
# Prediction button
if st.button("Predict"):
to_predict = [{"context": context, "qas": [{"question": question, "id": "0"}]}]
try:
answers, _ = model.predict(to_predict, n_best_size=1)
if answers and 'answer' in answers[0]:
st.text("Answer:")
st.write(f"<span style='color:cyan; font-weight:bold'>{answers[0]['answer'][0]}</span>", unsafe_allow_html=True)
else:
st.text("No answer found.")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
st.header("Sample Context:")
st.write("During the Renaissance period in Europe, the Medici family played a crucial role in fostering artistic and intellectual advancements. Their patronage of artists and scholars in Florence contributed significantly to the flourishing of Renaissance culture.")
st.write(f"Question: <span style='color:yellow;'>What family was influential during the Renaissance?</span>", unsafe_allow_html=True)
st.write(f"Answer: <span style='color:red;'>Medici family</span>", unsafe_allow_html=True) |