File size: 2,443 Bytes
749397b
 
 
ed4d54a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749397b
 
ed4d54a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
749397b
ed4d54a
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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(
    """
    <h1 style="text-align: center; color: #4CAF50; font-family: 'Helvetica';">
        πŸ“š Question Answering App
    </h1>
    <p style="text-align: center; color: #777; font-size: 18px;">
        Enter a context and question to get precise answers powered by AI.
    </p>
    """,
    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(
    """
    <small>Using default model: <code>Diezu/viedumrc</code>.</small>
    """,
    unsafe_allow_html=True,
)

# Initialize model pipeline
question_answerer = pipeline("question-answering", model=model_checkpoint)

# Main application
st.markdown(
    """
    <h2 style="color: #2196F3;">Provide Context and Question</h2>
    """,
    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"""
                <div style="background-color: #f1f8ff; border-left: 4px solid #2196F3; padding: 10px; margin-top: 10px;">
                    <strong>Answer:</strong> {result['answer']}
                </div>
                """,
                unsafe_allow_html=True,
            )
        except Exception as e:
            st.error(f"Error: {e}")

# Footer
st.markdown(
    """
    <hr>
    <footer style="text-align: center; font-size: small; color: #888;">
        Built with ❀️ using <strong>Streamlit</strong> and <strong>Transformers</strong>.
    </footer>
    """,
    unsafe_allow_html=True,
)