File size: 2,450 Bytes
066f16b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ea121e
 
 
066f16b
b078c2d
2eb1656
dbbbaa3
8ea121e
066f16b
 
 
 
 
d45cfdb
 
 
 
227ba83
b1d5fea
d45cfdb
066f16b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcb1186
d45cfdb
 
 
 
 
 
066f16b
 
 
 
 
 
 
 
 
 
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
92
93
94
95
96
97
98
99
# import streamlit as st
# from transformers import pipeline

# st.title('Question Answering')
# model_checkpoint = 'Diezu/Viedumodel'
# question_answerer = pipeline("question-answering", model=model_checkpoint)

# context = st.text_area('CONTEXT')
# question = st.text_input('QUESTION')

# if st.button('ANSWER'):
#     i=question_answerer(question,context)
#     #st.write(i['answer'])
#     st.markdown(i['answer']) 
#     #st.write('<h1 style="font-size: 50px;">i['answer']</h1>')


import streamlit as st
from transformers import pipeline

# Thiết lập mô hình
st.title('Question Answering')
model_checkpoint = 'Diezu/Viedumodel'
question_answerer = pipeline("question-answering", model=model_checkpoint)

# Thêm Sidebar cho tùy chọn
st.sidebar.title("Cài đặt")
theme_color = st.sidebar.color_picker("Chọn màu chủ đạo", "#4CAF50")
font_size = st.sidebar.slider("Cỡ chữ câu trả lời", 14, 50, 20)

# Di chuyển CONTEXT vào Sidebar
context = st.sidebar.text_area('Nhập Nội Dung (CONTEXT)', height=200)

# Tạo câu hỏi mẫu hoặc cho phép người dùng chọn câu hỏi từ danh sách

question = st.text_input("Nhập câu hỏi ")

# Thêm CSS cho giao diện
st.markdown(
    f"""
    <style>
    .stTitle {{
        font-size: 32px;
        font-weight: bold;
        color: {theme_color};
    }}
    textarea {{
        border: 2px solid {theme_color};
        border-radius: 10px;
        padding: 10px;
        font-size: 16px;
    }}
    input[type="text"] {{
        border: 2px solid {theme_color};
        border-radius: 10px;
        padding: 10px;
        font-size: 16px;
    }}
    .stButton > button {{
        background-color: {theme_color};
        color: white;
        border-radius: 10px;
        padding: 10px 20px;
        font-size: 16px;
        border: none;
        transition: 0.3s;
    }}
    .stButton > button:hover {{
        background-color: #45a049;
    }}
    .stMarkdown {{
        font-size: {font_size}px;
        font-weight: bold;
        color: #333333;
    }}
    </style>
    """,
    unsafe_allow_html=True
)

# Xử lý câu trả lời
if st.button('ANSWER'):
    if context and question:
        with st.spinner('Đang xử lý...'):
            result = question_answerer(question=question, context=context)
        st.success(f"Trả lời: {result['answer']}")
    else:
        st.warning("Vui lòng nhập CONTEXT và chọn câu hỏi.")