Maheen001 commited on
Commit
b9e63ff
Β·
verified Β·
1 Parent(s): 019a10f

Update ui/voice_agent_ui.py

Browse files
Files changed (1) hide show
  1. 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 standard Gradbot format"""
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 standard Gradio Chatbot format
169
- # Format: List of tuples [(user_msg, bot_msg), ...]
 
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
- # Add to current bot messages
206
- current_bot_msgs.append(f"{icon} **{title}**\n\n{t_content}")
207
-
208
- # Create single chat entry with all thoughts
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 in standard format
235
- error_messages = [("❌ Error occurred", f"**Error**\n\n{str(e)}")]
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