Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,47 +4,75 @@ import time
|
|
| 4 |
def bot_response(message, history):
|
| 5 |
print("\n=== Bot Response Function ===")
|
| 6 |
print(f"Received message: {message}")
|
| 7 |
-
print(f"Initial history: {history}")
|
| 8 |
|
| 9 |
history = history or []
|
| 10 |
-
messages = []
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
yield history
|
| 18 |
time.sleep(1)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
yield history
|
| 26 |
time.sleep(1)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
yield history
|
| 34 |
time.sleep(1)
|
| 35 |
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
history
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
yield history
|
| 42 |
|
| 43 |
with gr.Blocks() as demo:
|
| 44 |
chatbot = gr.Chatbot(
|
| 45 |
height=600,
|
| 46 |
group_consecutive_messages=False,
|
| 47 |
-
type="messages"
|
|
|
|
| 48 |
)
|
| 49 |
msg = gr.Textbox()
|
| 50 |
clear = gr.Button("Clear")
|
|
@@ -52,13 +80,10 @@ with gr.Blocks() as demo:
|
|
| 52 |
def user(user_message, history):
|
| 53 |
print("\n=== User Message Function ===")
|
| 54 |
print(f"User message: {user_message}")
|
| 55 |
-
print(f"Current history: {history}")
|
| 56 |
|
| 57 |
-
# Only add user message if it's not empty
|
| 58 |
if user_message.strip():
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
return "", new_history
|
| 62 |
return "", history
|
| 63 |
|
| 64 |
msg.submit(
|
|
|
|
| 4 |
def bot_response(message, history):
|
| 5 |
print("\n=== Bot Response Function ===")
|
| 6 |
print(f"Received message: {message}")
|
|
|
|
| 7 |
|
| 8 |
history = history or []
|
|
|
|
| 9 |
|
| 10 |
+
# Regular message without metadata
|
| 11 |
+
msg = gr.ChatMessage(
|
| 12 |
+
role="assistant",
|
| 13 |
+
content="Let me help you analyze that..."
|
| 14 |
+
)
|
| 15 |
+
history.append(msg)
|
| 16 |
+
yield history
|
| 17 |
+
time.sleep(1)
|
| 18 |
+
|
| 19 |
+
# Tool execution with metadata
|
| 20 |
+
parent_id = "tool_call_1"
|
| 21 |
+
tool_msg = gr.ChatMessage(
|
| 22 |
+
role="assistant",
|
| 23 |
+
content="```python\nprint('Running analysis...')\n```",
|
| 24 |
+
metadata={
|
| 25 |
+
"title": "🛠️ Using Python Interpreter",
|
| 26 |
+
"id": parent_id,
|
| 27 |
+
"status": "pending"
|
| 28 |
+
}
|
| 29 |
+
)
|
| 30 |
+
history.append(tool_msg)
|
| 31 |
yield history
|
| 32 |
time.sleep(1)
|
| 33 |
|
| 34 |
+
# Regular message showing progress
|
| 35 |
+
progress_msg = gr.ChatMessage(
|
| 36 |
+
role="assistant",
|
| 37 |
+
content="Processing your request..."
|
| 38 |
+
)
|
| 39 |
+
history.append(progress_msg)
|
| 40 |
yield history
|
| 41 |
time.sleep(1)
|
| 42 |
|
| 43 |
+
# Execution result with metadata
|
| 44 |
+
execution_msg = gr.ChatMessage(
|
| 45 |
+
role="assistant",
|
| 46 |
+
content="Output: Analysis complete",
|
| 47 |
+
metadata={
|
| 48 |
+
"title": "📝 Execution Result",
|
| 49 |
+
"parent_id": parent_id,
|
| 50 |
+
"status": "pending"
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
+
history.append(execution_msg)
|
| 54 |
yield history
|
| 55 |
time.sleep(1)
|
| 56 |
|
| 57 |
+
# Update tool messages to done
|
| 58 |
+
tool_msg.metadata["status"] = "done"
|
| 59 |
+
execution_msg.metadata["status"] = "done"
|
| 60 |
+
yield history
|
| 61 |
+
|
| 62 |
+
# Final message without metadata
|
| 63 |
+
final_msg = gr.ChatMessage(
|
| 64 |
+
role="assistant",
|
| 65 |
+
content="Based on the analysis, I can confirm the process completed successfully."
|
| 66 |
+
)
|
| 67 |
+
history.append(final_msg)
|
| 68 |
yield history
|
| 69 |
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
chatbot = gr.Chatbot(
|
| 72 |
height=600,
|
| 73 |
group_consecutive_messages=False,
|
| 74 |
+
type="messages",
|
| 75 |
+
bubble_full_width=False
|
| 76 |
)
|
| 77 |
msg = gr.Textbox()
|
| 78 |
clear = gr.Button("Clear")
|
|
|
|
| 80 |
def user(user_message, history):
|
| 81 |
print("\n=== User Message Function ===")
|
| 82 |
print(f"User message: {user_message}")
|
|
|
|
| 83 |
|
|
|
|
| 84 |
if user_message.strip():
|
| 85 |
+
history.append(gr.ChatMessage(role="user", content=user_message))
|
| 86 |
+
return "", history
|
|
|
|
| 87 |
return "", history
|
| 88 |
|
| 89 |
msg.submit(
|