Maheen001 commited on
Commit
ca3e20d
Β·
verified Β·
1 Parent(s): 143de80

Update ui/voice_agent_ui.py

Browse files
Files changed (1) hide show
  1. ui/voice_agent_ui.py +13 -10
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 tuple format"""
143
 
144
  # Step 1 β€” Identify user command
145
  if audio_file and not text_command:
@@ -165,9 +165,8 @@ 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 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):
@@ -201,10 +200,11 @@ def create_voice_agent_ui(agent):
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,8 +228,11 @@ def create_voice_agent_ui(agent):
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
 
139
 
140
  # MAIN COMMAND PROCESSOR
141
  async def process_audio_command(audio_file, text_command, files_list):
142
+ """Process voice + text commands - FIXED for Gradio 6.0 dictionary 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 6.0 format
169
+ # MUST be list of dicts with "role" and "content" keys
 
170
  messages = []
171
 
172
  for i, t in enumerate(thoughts):
 
200
  icon = "βœ…"
201
  title = "Answer"
202
 
203
+ # Add as assistant message
204
+ messages.append({
205
+ "role": "assistant",
206
+ "content": f"{icon} **{title}**\n\n{t_content}"
207
+ })
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 in dictionary format
232
+ error_messages = [{
233
+ "role": "assistant",
234
+ "content": f"❌ **Error**\n\n{str(e)}"
235
+ }]
236
  yield error_messages, f"❌ Error: {str(e)}", err_msg, None, None
237
 
238
  # CONNECT EVENTS