Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,6 +47,7 @@ def chat_history(session_id):
|
|
| 47 |
# Generate unique session ID
|
| 48 |
if "session_id" not in st.session_state:
|
| 49 |
st.session_state.session_id = str(uuid.uuid4())
|
|
|
|
| 50 |
|
| 51 |
# Sidebar for session management
|
| 52 |
with st.sidebar:
|
|
@@ -116,16 +117,17 @@ st.markdown("""
|
|
| 116 |
</style>
|
| 117 |
""", unsafe_allow_html=True)
|
| 118 |
|
| 119 |
-
#
|
| 120 |
-
st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
|
| 121 |
-
|
| 122 |
if "messages" not in st.session_state:
|
| 123 |
st.session_state.messages = load_chat_history(session_id)
|
|
|
|
|
|
|
| 124 |
|
|
|
|
|
|
|
| 125 |
for role, content in st.session_state.messages:
|
| 126 |
role_class = "user-message" if role == "user" else "assistant-message"
|
| 127 |
st.markdown(f"<div class='chat-message {role_class}'><b>{role.capitalize()}:</b> {content}</div>", unsafe_allow_html=True)
|
| 128 |
-
|
| 129 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 130 |
|
| 131 |
# User Input Box
|
|
|
|
| 47 |
# Generate unique session ID
|
| 48 |
if "session_id" not in st.session_state:
|
| 49 |
st.session_state.session_id = str(uuid.uuid4())
|
| 50 |
+
st.session_state.messages = []
|
| 51 |
|
| 52 |
# Sidebar for session management
|
| 53 |
with st.sidebar:
|
|
|
|
| 117 |
</style>
|
| 118 |
""", unsafe_allow_html=True)
|
| 119 |
|
| 120 |
+
# Load chat history
|
|
|
|
|
|
|
| 121 |
if "messages" not in st.session_state:
|
| 122 |
st.session_state.messages = load_chat_history(session_id)
|
| 123 |
+
else:
|
| 124 |
+
st.session_state.messages = [(role, content) for role, content in load_chat_history(session_id)]
|
| 125 |
|
| 126 |
+
# Display Chat Messages
|
| 127 |
+
st.markdown("<div class='chat-container'>", unsafe_allow_html=True)
|
| 128 |
for role, content in st.session_state.messages:
|
| 129 |
role_class = "user-message" if role == "user" else "assistant-message"
|
| 130 |
st.markdown(f"<div class='chat-message {role_class}'><b>{role.capitalize()}:</b> {content}</div>", unsafe_allow_html=True)
|
|
|
|
| 131 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 132 |
|
| 133 |
# User Input Box
|