Spaces:
Running
Running
Update ui/voice_agent_ui.py
Browse files- ui/voice_agent_ui.py +11 -14
ui/voice_agent_ui.py
CHANGED
|
@@ -139,7 +139,7 @@ def create_voice_agent_ui(agent):
|
|
| 139 |
|
| 140 |
# MAIN COMMAND PROCESSOR
|
| 141 |
async def process_audio_command(audio_file, text_command, files_list):
|
| 142 |
-
"""Process voice + text commands - FIXED for
|
| 143 |
|
| 144 |
# Step 1 β Identify user command
|
| 145 |
if audio_file and not text_command:
|
|
@@ -165,13 +165,12 @@ def create_voice_agent_ui(agent):
|
|
| 165 |
# Call agent (non-streaming)
|
| 166 |
final_answer, thoughts = await agent.execute(cmd, files_list)
|
| 167 |
|
| 168 |
-
# Convert AgentThought objects to
|
| 169 |
-
#
|
|
|
|
| 170 |
messages = []
|
| 171 |
-
current_user_msg = "π― Task Progress:"
|
| 172 |
-
current_bot_msgs = []
|
| 173 |
|
| 174 |
-
for t in thoughts:
|
| 175 |
# Handle both AgentThought objects and dicts
|
| 176 |
if hasattr(t, "type"):
|
| 177 |
t_type = t.type
|
|
@@ -202,12 +201,10 @@ def create_voice_agent_ui(agent):
|
|
| 202 |
icon = "β
"
|
| 203 |
title = "Answer"
|
| 204 |
|
| 205 |
-
#
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
if current_bot_msgs:
|
| 210 |
-
messages.append((current_user_msg, "\n\n---\n\n".join(current_bot_msgs)))
|
| 211 |
|
| 212 |
# Show results
|
| 213 |
yield messages, "π Generating voice response...", final_answer, None, None
|
|
@@ -231,8 +228,8 @@ def create_voice_agent_ui(agent):
|
|
| 231 |
import traceback
|
| 232 |
err_msg = f"β οΈ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 233 |
|
| 234 |
-
# Error message
|
| 235 |
-
error_messages = [("
|
| 236 |
yield error_messages, f"β Error: {str(e)}", err_msg, None, None
|
| 237 |
|
| 238 |
# CONNECT EVENTS
|
|
|
|
| 139 |
|
| 140 |
# MAIN COMMAND PROCESSOR
|
| 141 |
async def process_audio_command(audio_file, text_command, files_list):
|
| 142 |
+
"""Process voice + text commands - FIXED for tuple format"""
|
| 143 |
|
| 144 |
# Step 1 β Identify user command
|
| 145 |
if audio_file and not text_command:
|
|
|
|
| 165 |
# Call agent (non-streaming)
|
| 166 |
final_answer, thoughts = await agent.execute(cmd, files_list)
|
| 167 |
|
| 168 |
+
# Convert AgentThought objects to Gradio Chatbot tuple format
|
| 169 |
+
# MUST be: [(user_msg, bot_msg), (user_msg, bot_msg), ...]
|
| 170 |
+
# Each tuple is ONE chat exchange
|
| 171 |
messages = []
|
|
|
|
|
|
|
| 172 |
|
| 173 |
+
for i, t in enumerate(thoughts):
|
| 174 |
# Handle both AgentThought objects and dicts
|
| 175 |
if hasattr(t, "type"):
|
| 176 |
t_type = t.type
|
|
|
|
| 201 |
icon = "β
"
|
| 202 |
title = "Answer"
|
| 203 |
|
| 204 |
+
# Create a tuple for each thought: (user_msg, bot_msg)
|
| 205 |
+
user_msg = f"Step {i+1}"
|
| 206 |
+
bot_msg = f"{icon} **{title}**\n\n{t_content}"
|
| 207 |
+
messages.append((user_msg, bot_msg))
|
|
|
|
|
|
|
| 208 |
|
| 209 |
# Show results
|
| 210 |
yield messages, "π Generating voice response...", final_answer, None, None
|
|
|
|
| 228 |
import traceback
|
| 229 |
err_msg = f"β οΈ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 230 |
|
| 231 |
+
# Error message as tuple
|
| 232 |
+
error_messages = [("Error", f"β **Error**\n\n{str(e)}")]
|
| 233 |
yield error_messages, f"β Error: {str(e)}", err_msg, None, None
|
| 234 |
|
| 235 |
# CONNECT EVENTS
|