test / app.py
MarcosRodrigo's picture
Create app.py
ada589a verified
raw
history blame contribute delete
818 Bytes
import streamlit as st
from transformers import pipeline
# Load the pre-trained model and tokenizer
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
def answer_question(context: str, question: str) -> str:
result = qa_pipeline(question=question, context=context)
return result['answer']
# Streamlit app
st.title("Question-Answering Bot")
st.write("Enter the context text and ask a question about it.")
context = st.text_area("Context", height=300)
question = st.text_input("Question")
if st.button("Get Answer"):
if context and question:
answer = answer_question(context, question)
st.write(f"**Question:** {question}")
st.write(f"**Answer:** {answer}")
else:
st.write("Please enter both the context and the question.")