Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -339,15 +339,25 @@ def create_ui(app):
|
|
| 339 |
stop_button = gr.Button("Stop Conversation", variant="stop")
|
| 340 |
replay_button = gr.Button("Replay Last Response")
|
| 341 |
|
| 342 |
-
# Add microphone component
|
| 343 |
with gr.Row():
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
# Text input for all users
|
| 353 |
with gr.Row():
|
|
@@ -412,13 +422,17 @@ def create_ui(app):
|
|
| 412 |
else:
|
| 413 |
return "Please start the conversation first", live_transcription.value, None, text
|
| 414 |
|
| 415 |
-
# Connect the audio input to processing
|
| 416 |
-
if not is_huggingface_spaces():
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
|
| 423 |
# Connect the text input to the send function
|
| 424 |
send_button.click(
|
|
|
|
| 339 |
stop_button = gr.Button("Stop Conversation", variant="stop")
|
| 340 |
replay_button = gr.Button("Replay Last Response")
|
| 341 |
|
| 342 |
+
# Add microphone component - use params compatible with older Gradio versions
|
| 343 |
with gr.Row():
|
| 344 |
+
# Check if we're in HF Spaces and skip this component
|
| 345 |
+
if not is_huggingface_spaces():
|
| 346 |
+
try:
|
| 347 |
+
# Try with newer Gradio params
|
| 348 |
+
audio_input = gr.Audio(
|
| 349 |
+
source="microphone",
|
| 350 |
+
type="filepath",
|
| 351 |
+
streaming=True,
|
| 352 |
+
label="Speak here (if your browser supports it)"
|
| 353 |
+
)
|
| 354 |
+
except TypeError:
|
| 355 |
+
# Fall back to older Gradio version compatible params
|
| 356 |
+
audio_input = gr.Audio(
|
| 357 |
+
type="filepath",
|
| 358 |
+
streaming=True,
|
| 359 |
+
label="Speak here (if your browser supports it)"
|
| 360 |
+
)
|
| 361 |
|
| 362 |
# Text input for all users
|
| 363 |
with gr.Row():
|
|
|
|
| 422 |
else:
|
| 423 |
return "Please start the conversation first", live_transcription.value, None, text
|
| 424 |
|
| 425 |
+
# Connect the audio input to processing if we're not in HF Spaces
|
| 426 |
+
if not is_huggingface_spaces() and 'audio_input' in locals():
|
| 427 |
+
try:
|
| 428 |
+
audio_input.stream(
|
| 429 |
+
process_audio,
|
| 430 |
+
inputs=[audio_input],
|
| 431 |
+
outputs=None
|
| 432 |
+
)
|
| 433 |
+
except Exception as e:
|
| 434 |
+
print(f"Warning: Could not set up audio streaming: {e}")
|
| 435 |
+
print("Continuing with text input only")
|
| 436 |
|
| 437 |
# Connect the text input to the send function
|
| 438 |
send_button.click(
|