Spaces:
Paused
Paused
Update components/chat.py
Browse files- components/chat.py +20 -5
components/chat.py
CHANGED
|
@@ -15,6 +15,24 @@ def ensure_embeddings_initialized():
|
|
| 15 |
return False
|
| 16 |
return True
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def clean_ai_response(content):
|
| 19 |
"""Clean up AI response content and remove technical artifacts."""
|
| 20 |
content = str(content)
|
|
@@ -203,7 +221,7 @@ def display_chat_interface():
|
|
| 203 |
selected_session = st.selectbox(
|
| 204 |
"Select a previous conversation:",
|
| 205 |
options=[s['session_id'] for s in sessions],
|
| 206 |
-
format_func=lambda x: f"Chat from {
|
| 207 |
)
|
| 208 |
|
| 209 |
if selected_session and st.button("Load Selected Chat"):
|
|
@@ -230,10 +248,7 @@ def display_chat_interface():
|
|
| 230 |
|
| 231 |
# Display current session info if available
|
| 232 |
if 'current_session_id' in st.session_state:
|
| 233 |
-
session_date =
|
| 234 |
-
st.session_state.current_session_id.split('_')[1],
|
| 235 |
-
'%Y%m%d_%H%M%S'
|
| 236 |
-
).strftime('%B %d, %Y %I:%M %p')
|
| 237 |
st.markdown(f"""
|
| 238 |
<div class="session-info">
|
| 239 |
📅 Current Session: {session_date}
|
|
|
|
| 15 |
return False
|
| 16 |
return True
|
| 17 |
|
| 18 |
+
def format_session_date(session_id: str) -> str:
|
| 19 |
+
"""Format session ID into readable date."""
|
| 20 |
+
try:
|
| 21 |
+
# Handle different possible date formats
|
| 22 |
+
if '_' in session_id:
|
| 23 |
+
date_part = session_id.split('_')[1]
|
| 24 |
+
else:
|
| 25 |
+
date_part = session_id
|
| 26 |
+
|
| 27 |
+
if len(date_part) == 8: # Format: YYYYMMDD
|
| 28 |
+
return datetime.strptime(date_part, '%Y%m%d').strftime('%B %d, %Y')
|
| 29 |
+
elif len(date_part) == 14: # Format: YYYYMMDD_HHMMSS
|
| 30 |
+
return datetime.strptime(date_part, '%Y%m%d%H%M%S').strftime('%B %d, %Y %I:%M %p')
|
| 31 |
+
else:
|
| 32 |
+
return date_part # Return original if format unknown
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"Session: {session_id}" # Fallback display
|
| 35 |
+
|
| 36 |
def clean_ai_response(content):
|
| 37 |
"""Clean up AI response content and remove technical artifacts."""
|
| 38 |
content = str(content)
|
|
|
|
| 221 |
selected_session = st.selectbox(
|
| 222 |
"Select a previous conversation:",
|
| 223 |
options=[s['session_id'] for s in sessions],
|
| 224 |
+
format_func=lambda x: f"Chat from {format_session_date(x)}"
|
| 225 |
)
|
| 226 |
|
| 227 |
if selected_session and st.button("Load Selected Chat"):
|
|
|
|
| 248 |
|
| 249 |
# Display current session info if available
|
| 250 |
if 'current_session_id' in st.session_state:
|
| 251 |
+
session_date = format_session_date(st.session_state.current_session_id)
|
|
|
|
|
|
|
|
|
|
| 252 |
st.markdown(f"""
|
| 253 |
<div class="session-info">
|
| 254 |
📅 Current Session: {session_date}
|