Spaces:
Runtime error
Runtime error
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) | |