import streamlit as st
from transformers import pipeline
# Set page configuration
st.set_page_config(
page_title="Question Answering App",
page_icon="❓",
layout="centered",
initial_sidebar_state="auto",
)
# Page title with custom style
st.markdown(
"""
📚 Question Answering App
Enter a context and question to get precise answers powered by AI.
""",
unsafe_allow_html=True,
)
# Sidebar
st.sidebar.header("Model Settings")
model_checkpoint = st.sidebar.text_input(
"Model Checkpoint", "Diezu/viedumrc", help="Specify the model checkpoint to use."
)
st.sidebar.markdown(
"""
Using default model: Diezu/viedumrc.
""",
unsafe_allow_html=True,
)
# Initialize model pipeline
question_answerer = pipeline("question-answering", model=model_checkpoint)
# Main application
st.markdown(
"""
Provide Context and Question
""",
unsafe_allow_html=True,
)
context = st.text_area(
"Context",
"",
help="Paste the context where the answer can be found.",
height=200,
placeholder="Enter your context here...",
)
question = st.text_input(
"Question",
"",
help="Write the question you want to ask about the provided context.",
placeholder="What is your question?",
)
if st.button("Get Answer"):
if context.strip() == "" or question.strip() == "":
st.warning("Please provide both context and a question!")
else:
try:
result = question_answerer(question=question, context=context)
st.success("Answer Found!")
st.markdown(
f"""