File size: 1,095 Bytes
4d7cf03
 
 
 
 
 
 
 
 
d7ddd71
4d7cf03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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("text-generation", 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.")