File size: 1,289 Bytes
3c5f44b
 
 
 
7ac345a
3c5f44b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from chatbot.core import get_chat_response

# Cấu hình giao diện Streamlit
st.set_page_config(page_title="Explorer Chatbot", layout="wide")

# Tiêu đề ứng dụng
st.markdown(
    """
    <style>
    .title {
        text-align: center;
        font-size: 2em;
        font-weight: bold;
    }
    </style>
    <h1 class="title">Explorer Chatbot</h1>
    """,
    unsafe_allow_html=True
)

# Khởi tạo session state để lưu lịch sử chat
if "messages" not in st.session_state:
    st.session_state.messages = []

# Hiển thị lịch sử chat
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])

# Ô nhập liệu chat
user_input = st.chat_input("Nhập tin nhắn của bạn...")

if user_input:
    # Hiển thị tin nhắn của user
    st.session_state.messages.append({"role": "user", "content": user_input})
    with st.chat_message("user"):
        st.markdown(user_input)

    # Gọi chatbot để lấy phản hồi
    response = get_chat_response(user_input)

    # Hiển thị phản hồi của chatbot
    st.session_state.messages.append({"role": "assistant", "content": response})
    with st.chat_message("assistant"):
        st.markdown(response)