Spaces:
Sleeping
Sleeping
Update app.py
Browse fileschat. history. sum. journal marathon
app.py
CHANGED
|
@@ -35,14 +35,14 @@ def groq_with_memory(message: str, topic: str = "general") -> tuple:
|
|
| 35 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 36 |
})
|
| 37 |
|
| 38 |
-
# Prepare messages for API call (last
|
| 39 |
-
recent_history = chat_history[-
|
| 40 |
messages = [{"role": msg["role"], "content": msg["content"]} for msg in recent_history]
|
| 41 |
|
| 42 |
payload = {
|
| 43 |
"model": "gemma2-9b-it",
|
| 44 |
"messages": messages,
|
| 45 |
-
"max_tokens":
|
| 46 |
"temperature": 0.7
|
| 47 |
}
|
| 48 |
|
|
@@ -227,7 +227,7 @@ with gr.Blocks(
|
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
clear_response_btn = gr.Button("ποΈ Clear Response", variant="secondary")
|
| 230 |
-
|
| 231 |
|
| 232 |
# HISTORY TAB
|
| 233 |
with gr.Tab("π Chat History"):
|
|
@@ -261,9 +261,28 @@ with gr.Blocks(
|
|
| 261 |
response, cleared_input = groq_with_memory(message, topic)
|
| 262 |
return response, cleared_input
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
def refresh_topic_choices():
|
| 265 |
return gr.Dropdown(choices=get_topics_list())
|
| 266 |
|
|
|
|
|
|
|
|
|
|
| 267 |
def filter_and_show_history(topic_filter):
|
| 268 |
filter_topic = None if topic_filter == "All Topics" else topic_filter
|
| 269 |
return get_full_history(filter_topic)
|
|
@@ -286,13 +305,13 @@ with gr.Blocks(
|
|
| 286 |
)
|
| 287 |
|
| 288 |
clear_response_btn.click(
|
| 289 |
-
|
| 290 |
outputs=[ai_response]
|
| 291 |
)
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
outputs=[
|
| 296 |
)
|
| 297 |
|
| 298 |
refresh_topics_btn.click(
|
|
|
|
| 35 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
|
| 36 |
})
|
| 37 |
|
| 38 |
+
# Prepare messages for API call (last 50 messages for longer context)
|
| 39 |
+
recent_history = chat_history[-50:]
|
| 40 |
messages = [{"role": msg["role"], "content": msg["content"]} for msg in recent_history]
|
| 41 |
|
| 42 |
payload = {
|
| 43 |
"model": "gemma2-9b-it",
|
| 44 |
"messages": messages,
|
| 45 |
+
"max_tokens": 3000, # Increased for longer responses
|
| 46 |
"temperature": 0.7
|
| 47 |
}
|
| 48 |
|
|
|
|
| 227 |
|
| 228 |
with gr.Row():
|
| 229 |
clear_response_btn = gr.Button("ποΈ Clear Response", variant="secondary")
|
| 230 |
+
show_context_btn = gr.Button("π Show Current Context", variant="secondary")
|
| 231 |
|
| 232 |
# HISTORY TAB
|
| 233 |
with gr.Tab("π Chat History"):
|
|
|
|
| 261 |
response, cleared_input = groq_with_memory(message, topic)
|
| 262 |
return response, cleared_input
|
| 263 |
|
| 264 |
+
def show_current_context():
|
| 265 |
+
"""Show current conversation context that AI can see"""
|
| 266 |
+
if not chat_history:
|
| 267 |
+
return "β No conversation context yet"
|
| 268 |
+
|
| 269 |
+
recent_history = chat_history[-50:] # Same as what AI sees
|
| 270 |
+
context_text = f"π§ **Current AI Context** ({len(recent_history)} messages)\n\n"
|
| 271 |
+
|
| 272 |
+
for msg in recent_history:
|
| 273 |
+
role_icon = "π€" if msg["role"] == "user" else "π€"
|
| 274 |
+
context_text += f"{role_icon} **{msg['timestamp']}** [{msg.get('topic', 'general')}]\n"
|
| 275 |
+
context_text += f"{msg['content'][:100]}{'...' if len(msg['content']) > 100 else ''}\n\n"
|
| 276 |
+
|
| 277 |
+
context_text += f"\nπ‘ *AI can remember these {len(recent_history)} messages in current conversation*"
|
| 278 |
+
return context_text
|
| 279 |
+
|
| 280 |
def refresh_topic_choices():
|
| 281 |
return gr.Dropdown(choices=get_topics_list())
|
| 282 |
|
| 283 |
+
def clear_only_response():
|
| 284 |
+
return ""
|
| 285 |
+
|
| 286 |
def filter_and_show_history(topic_filter):
|
| 287 |
filter_topic = None if topic_filter == "All Topics" else topic_filter
|
| 288 |
return get_full_history(filter_topic)
|
|
|
|
| 305 |
)
|
| 306 |
|
| 307 |
clear_response_btn.click(
|
| 308 |
+
clear_only_response,
|
| 309 |
outputs=[ai_response]
|
| 310 |
)
|
| 311 |
|
| 312 |
+
show_context_btn.click(
|
| 313 |
+
show_current_context,
|
| 314 |
+
outputs=[ai_response]
|
| 315 |
)
|
| 316 |
|
| 317 |
refresh_topics_btn.click(
|