Spaces:
Running
Running
Update ui/voice_agent_ui.py
Browse files- ui/voice_agent_ui.py +18 -18
ui/voice_agent_ui.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Voice Agent UI - Autonomous voice-controlled agent
|
| 3 |
-
FIXED:
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -79,11 +79,10 @@ def create_voice_agent_ui(agent):
|
|
| 79 |
with gr.Column(scale=2):
|
| 80 |
gr.Markdown("### π€ Agent Execution & Results")
|
| 81 |
|
| 82 |
-
# Agent Reasoning Trace (Chatbot
|
| 83 |
thought_trace = gr.Chatbot(
|
| 84 |
label="π§ Agent Reasoning Steps",
|
| 85 |
height=400,
|
| 86 |
-
type="messages", # REQUIRED for dict format
|
| 87 |
show_copy_button=True
|
| 88 |
)
|
| 89 |
|
|
@@ -142,7 +141,7 @@ def create_voice_agent_ui(agent):
|
|
| 142 |
|
| 143 |
# MAIN COMMAND PROCESSOR
|
| 144 |
async def process_audio_command(audio_file, text_command, files_list):
|
| 145 |
-
"""Process voice + text commands - FIXED for
|
| 146 |
|
| 147 |
# Step 1 β Identify user command
|
| 148 |
if audio_file and not text_command:
|
|
@@ -168,9 +167,12 @@ def create_voice_agent_ui(agent):
|
|
| 168 |
# Call agent (non-streaming)
|
| 169 |
final_answer, thoughts = await agent.execute(cmd, files_list)
|
| 170 |
|
| 171 |
-
# Convert AgentThought objects to Gradio
|
| 172 |
-
#
|
| 173 |
messages = []
|
|
|
|
|
|
|
|
|
|
| 174 |
for t in thoughts:
|
| 175 |
# Handle both AgentThought objects and dicts
|
| 176 |
if hasattr(t, "type"):
|
|
@@ -202,14 +204,15 @@ def create_voice_agent_ui(agent):
|
|
| 202 |
icon = "β
"
|
| 203 |
title = "Answer"
|
| 204 |
|
| 205 |
-
#
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
|
|
|
| 210 |
|
| 211 |
# Show results
|
| 212 |
-
yield messages, "
|
| 213 |
|
| 214 |
# TTS (optional - may fail if no API key)
|
| 215 |
try:
|
|
@@ -230,11 +233,8 @@ def create_voice_agent_ui(agent):
|
|
| 230 |
import traceback
|
| 231 |
err_msg = f"β οΈ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 232 |
|
| 233 |
-
# Error message in
|
| 234 |
-
error_messages = [{
|
| 235 |
-
"role": "assistant",
|
| 236 |
-
"content": f"β **Error**\n\n{str(e)}"
|
| 237 |
-
}]
|
| 238 |
yield error_messages, f"β Error: {str(e)}", err_msg, None, None
|
| 239 |
|
| 240 |
# CONNECT EVENTS
|
|
@@ -254,4 +254,4 @@ def create_voice_agent_ui(agent):
|
|
| 254 |
outputs=[thought_trace, status_box, final_response, audio_output, outputs_files]
|
| 255 |
)
|
| 256 |
|
| 257 |
-
return gr.Column()
|
|
|
|
| 1 |
"""
|
| 2 |
Voice Agent UI - Autonomous voice-controlled agent
|
| 3 |
+
FIXED: Removed type="messages" parameter for Gradio compatibility
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 79 |
with gr.Column(scale=2):
|
| 80 |
gr.Markdown("### π€ Agent Execution & Results")
|
| 81 |
|
| 82 |
+
# Agent Reasoning Trace (Simple Chatbot without type parameter)
|
| 83 |
thought_trace = gr.Chatbot(
|
| 84 |
label="π§ Agent Reasoning Steps",
|
| 85 |
height=400,
|
|
|
|
| 86 |
show_copy_button=True
|
| 87 |
)
|
| 88 |
|
|
|
|
| 141 |
|
| 142 |
# MAIN COMMAND PROCESSOR
|
| 143 |
async def process_audio_command(audio_file, text_command, files_list):
|
| 144 |
+
"""Process voice + text commands - FIXED for standard Gradbot format"""
|
| 145 |
|
| 146 |
# Step 1 β Identify user command
|
| 147 |
if audio_file and not text_command:
|
|
|
|
| 167 |
# Call agent (non-streaming)
|
| 168 |
final_answer, thoughts = await agent.execute(cmd, files_list)
|
| 169 |
|
| 170 |
+
# Convert AgentThought objects to standard Gradio Chatbot format
|
| 171 |
+
# Format: List of tuples [(user_msg, bot_msg), ...]
|
| 172 |
messages = []
|
| 173 |
+
current_user_msg = "π― Task Progress:"
|
| 174 |
+
current_bot_msgs = []
|
| 175 |
+
|
| 176 |
for t in thoughts:
|
| 177 |
# Handle both AgentThought objects and dicts
|
| 178 |
if hasattr(t, "type"):
|
|
|
|
| 204 |
icon = "β
"
|
| 205 |
title = "Answer"
|
| 206 |
|
| 207 |
+
# Add to current bot messages
|
| 208 |
+
current_bot_msgs.append(f"{icon} **{title}**\n\n{t_content}")
|
| 209 |
+
|
| 210 |
+
# Create single chat entry with all thoughts
|
| 211 |
+
if current_bot_msgs:
|
| 212 |
+
messages.append((current_user_msg, "\n\n---\n\n".join(current_bot_msgs)))
|
| 213 |
|
| 214 |
# Show results
|
| 215 |
+
yield messages, "π Generating voice response...", final_answer, None, None
|
| 216 |
|
| 217 |
# TTS (optional - may fail if no API key)
|
| 218 |
try:
|
|
|
|
| 233 |
import traceback
|
| 234 |
err_msg = f"β οΈ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
| 235 |
|
| 236 |
+
# Error message in standard format
|
| 237 |
+
error_messages = [("β Error occurred", f"**Error**\n\n{str(e)}")]
|
|
|
|
|
|
|
|
|
|
| 238 |
yield error_messages, f"β Error: {str(e)}", err_msg, None, None
|
| 239 |
|
| 240 |
# CONNECT EVENTS
|
|
|
|
| 254 |
outputs=[thought_trace, status_box, final_response, audio_output, outputs_files]
|
| 255 |
)
|
| 256 |
|
| 257 |
+
return gr.Column()
|