Spaces:
Running
Running
Update ui/voice_agent_ui.py
Browse files- ui/voice_agent_ui.py +19 -7
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,7 +79,7 @@ def create_voice_agent_ui(agent):
|
|
| 79 |
with gr.Column(scale=2):
|
| 80 |
gr.Markdown("### π€ Agent Execution & Results")
|
| 81 |
|
| 82 |
-
# Agent Reasoning Trace (Simple Chatbot - minimal parameters
|
| 83 |
thought_trace = gr.Chatbot(
|
| 84 |
label="π§ Agent Reasoning Steps",
|
| 85 |
height=400
|
|
@@ -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
|
| 143 |
|
| 144 |
# Step 1 β Identify user command
|
| 145 |
if audio_file and not text_command:
|
|
@@ -207,20 +207,32 @@ def create_voice_agent_ui(agent):
|
|
| 207 |
})
|
| 208 |
|
| 209 |
# Show results
|
| 210 |
-
yield messages, "π
|
| 211 |
|
| 212 |
# TTS (optional - may fail if no API key)
|
|
|
|
| 213 |
try:
|
| 214 |
audio_path = await text_to_speech(final_answer)
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
audio_path = None
|
| 217 |
|
| 218 |
-
# Collect recent outputs
|
| 219 |
output_dir = Path("data/outputs")
|
| 220 |
files_generated = []
|
| 221 |
if output_dir.exists():
|
| 222 |
cutoff = time.time() - 300 # Last 5 minutes
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
yield messages, "β
Complete!", final_answer, audio_path, files_generated
|
| 226 |
|
|
|
|
| 1 |
"""
|
| 2 |
Voice Agent UI - Autonomous voice-controlled agent
|
| 3 |
+
COMPLETE FIXED VERSION
|
| 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 - minimal parameters)
|
| 83 |
thought_trace = gr.Chatbot(
|
| 84 |
label="π§ Agent Reasoning Steps",
|
| 85 |
height=400
|
|
|
|
| 139 |
|
| 140 |
# MAIN COMMAND PROCESSOR
|
| 141 |
async def process_audio_command(audio_file, text_command, files_list):
|
| 142 |
+
"""Process voice + text commands - COMPLETE FIXED VERSION"""
|
| 143 |
|
| 144 |
# Step 1 β Identify user command
|
| 145 |
if audio_file and not text_command:
|
|
|
|
| 207 |
})
|
| 208 |
|
| 209 |
# Show results
|
| 210 |
+
yield messages, "π Processing complete...", final_answer, None, None
|
| 211 |
|
| 212 |
# TTS (optional - may fail if no API key)
|
| 213 |
+
audio_path = None
|
| 214 |
try:
|
| 215 |
audio_path = await text_to_speech(final_answer)
|
| 216 |
+
# Only yield audio if it's a valid file path, not a directory
|
| 217 |
+
if audio_path and Path(audio_path).is_file():
|
| 218 |
+
yield messages, "β
Complete!", final_answer, audio_path, None
|
| 219 |
+
else:
|
| 220 |
+
audio_path = None
|
| 221 |
+
except Exception as e:
|
| 222 |
+
print(f"TTS Error (non-critical): {e}")
|
| 223 |
audio_path = None
|
| 224 |
|
| 225 |
+
# Collect recent outputs (only files, not directories)
|
| 226 |
output_dir = Path("data/outputs")
|
| 227 |
files_generated = []
|
| 228 |
if output_dir.exists():
|
| 229 |
cutoff = time.time() - 300 # Last 5 minutes
|
| 230 |
+
try:
|
| 231 |
+
for f in output_dir.glob("*"):
|
| 232 |
+
if f.is_file() and f.stat().st_mtime > cutoff:
|
| 233 |
+
files_generated.append(str(f))
|
| 234 |
+
except Exception:
|
| 235 |
+
pass
|
| 236 |
|
| 237 |
yield messages, "β
Complete!", final_answer, audio_path, files_generated
|
| 238 |
|