Maheen001 commited on
Commit
398cd77
Β·
verified Β·
1 Parent(s): e9105b9

Update ui/voice_agent_ui.py

Browse files
Files changed (1) hide show
  1. ui/voice_agent_ui.py +13 -17
ui/voice_agent_ui.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- Voice Agent UI - Autonomous voice-controlled agent (Gradio-compatible)
3
  """
4
 
5
  import gradio as gr
@@ -69,11 +69,10 @@ def create_voice_agent_ui(agent):
69
  with gr.Column(scale=2):
70
  gr.Markdown("### πŸ€– Agent Reasoning & Execution Trace")
71
 
72
- # Chatbot (FIXED FORMAT)
73
  thought_trace = gr.Chatbot(
74
  label="Agent Reasoning",
75
- height=400,
76
- type="messages" # Use messages format
77
  )
78
 
79
  final_response = gr.Textbox(
@@ -125,7 +124,7 @@ def create_voice_agent_ui(agent):
125
 
126
  return "\n".join(file_info_text), file_paths
127
 
128
- # MAIN COMMAND PROCESSOR (FIXED FORMAT)
129
  async def process_audio_command(audio_file, text_command, files_list):
130
  """Process voice + text commands"""
131
 
@@ -153,7 +152,7 @@ def create_voice_agent_ui(agent):
153
  # Call agent (non-streaming)
154
  final_answer, thoughts = await agent.execute(cmd, files_list)
155
 
156
- # Convert AgentThought objects into CORRECT chatbot messages format
157
  messages = []
158
  for t in thoughts:
159
  # Handle both AgentThought objects and dicts
@@ -185,11 +184,11 @@ def create_voice_agent_ui(agent):
185
  icon = "βœ…"
186
  title = " Answer"
187
 
188
- # CORRECT FORMAT: dict with 'role' and 'content'
189
- messages.append({
190
- "role": "assistant",
191
- "content": f"{icon}{title} β€” {t_content}"
192
- })
193
 
194
  # Show results
195
  yield messages, "πŸ”Š Generating voice...", final_answer, None, None
@@ -211,11 +210,8 @@ def create_voice_agent_ui(agent):
211
 
212
  except Exception as e:
213
  err = f"⚠️ Error: {str(e)}"
214
- # Error message in correct format
215
- error_messages = [{
216
- "role": "assistant",
217
- "content": err
218
- }]
219
  yield error_messages, err, err, None, None
220
 
221
  # CONNECT EVENTS (using run_sync wrapper for async functions)
@@ -235,4 +231,4 @@ def create_voice_agent_ui(agent):
235
  outputs=[thought_trace, status_box, final_response, audio_output, outputs_files]
236
  )
237
 
238
- return ui
 
1
  """
2
+ Voice Agent UI - Autonomous voice-controlled agent (Gradio 6.0 compatible)
3
  """
4
 
5
  import gradio as gr
 
69
  with gr.Column(scale=2):
70
  gr.Markdown("### πŸ€– Agent Reasoning & Execution Trace")
71
 
72
+ # Chatbot (Gradio 6.0 - no type parameter)
73
  thought_trace = gr.Chatbot(
74
  label="Agent Reasoning",
75
+ height=400
 
76
  )
77
 
78
  final_response = gr.Textbox(
 
124
 
125
  return "\n".join(file_info_text), file_paths
126
 
127
+ # MAIN COMMAND PROCESSOR
128
  async def process_audio_command(audio_file, text_command, files_list):
129
  """Process voice + text commands"""
130
 
 
152
  # Call agent (non-streaming)
153
  final_answer, thoughts = await agent.execute(cmd, files_list)
154
 
155
+ # Convert AgentThought objects into Gradio 6.0 format (tuples)
156
  messages = []
157
  for t in thoughts:
158
  # Handle both AgentThought objects and dicts
 
184
  icon = "βœ…"
185
  title = " Answer"
186
 
187
+ # Gradio 6.0 format: tuple (role, content)
188
+ messages.append((
189
+ "assistant",
190
+ f"{icon}{title} β€” {t_content}"
191
+ ))
192
 
193
  # Show results
194
  yield messages, "πŸ”Š Generating voice...", final_answer, None, None
 
210
 
211
  except Exception as e:
212
  err = f"⚠️ Error: {str(e)}"
213
+ # Error message in Gradio 6.0 format: tuple
214
+ error_messages = [("assistant", err)]
 
 
 
215
  yield error_messages, err, err, None, None
216
 
217
  # CONNECT EVENTS (using run_sync wrapper for async functions)
 
231
  outputs=[thought_trace, status_box, final_response, audio_output, outputs_files]
232
  )
233
 
234
+ return gr.Column() # Return a component to avoid Gradio warning