File size: 818 Bytes
ada589a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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.")