tech-bot / app.py
abdulllah01's picture
Update app.py
4d7cf03 verified
raw
history blame
1.1 kB
import streamlit as st
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
# Load the model and tokenizer from your Hugging Face Hub repository
model_checkpoint = "abdulllah01/checkpoints" # Replace with your actual checkpoint
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForQuestionAnswering.from_pretrained(model_checkpoint)
# Create a pipeline for question answering
qa_pipeline = pipeline("question-answering", model=model, tokenizer=tokenizer)
# Streamlit UI setup
st.title("Question Answering App")
st.write("Enter a context and ask a question based on that context.")
# Text area for context input
context = st.text_area("Context:", "")
# Text input for the question
question = st.text_input("Question:", "")
if st.button("Get Answer"):
if context and question:
# Generate the answer using the pipeline
result = qa_pipeline(question=question, context=context)
answer = result['answer']
st.write("**Answer:**", answer)
else:
st.write("Please enter both context and question.")