Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -391,16 +391,48 @@ def create_interface():
|
|
| 391 |
# Control buttons (Task 3, 16-17)
|
| 392 |
with gr.Row():
|
| 393 |
connect_btn = gr.Button("π Connect", variant="primary")
|
|
|
|
| 394 |
screen_btn = gr.Button("π₯οΈ Show Your Screen", variant="secondary")
|
| 395 |
disconnect_btn = gr.Button("π΄ Disconnect", variant="stop")
|
| 396 |
|
| 397 |
-
# Stream interface
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
# Mount the FastRTC stream UI
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
else:
|
| 403 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
|
| 405 |
# Instructions (Task 1-3)
|
| 406 |
with gr.Accordion("π Instructions", open=True):
|
|
@@ -446,6 +478,12 @@ def create_interface():
|
|
| 446 |
outputs=[status_display]
|
| 447 |
)
|
| 448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
screen_btn.click(
|
| 450 |
fn=lambda: "π₯οΈ Requesting screen share...",
|
| 451 |
outputs=[status_display],
|
|
|
|
| 391 |
# Control buttons (Task 3, 16-17)
|
| 392 |
with gr.Row():
|
| 393 |
connect_btn = gr.Button("π Connect", variant="primary")
|
| 394 |
+
mic_btn = gr.Button("ποΈ Test Microphone", variant="secondary")
|
| 395 |
screen_btn = gr.Button("π₯οΈ Show Your Screen", variant="secondary")
|
| 396 |
disconnect_btn = gr.Button("π΄ Disconnect", variant="stop")
|
| 397 |
|
| 398 |
+
# Stream interface - FastRTC UI for microphone and video
|
| 399 |
+
gr.Markdown("### π‘ Live Audio/Video Stream")
|
| 400 |
+
if stream:
|
| 401 |
+
# Mount the FastRTC stream UI - this provides microphone access
|
| 402 |
+
gr.HTML("""
|
| 403 |
+
<div id="fastrtc-container">
|
| 404 |
+
<p>ποΈ Microphone and video streaming handled by FastRTC</p>
|
| 405 |
+
<p>Click 'Test Microphone' and 'Show Your Screen' to activate</p>
|
| 406 |
+
</div>
|
| 407 |
+
""")
|
| 408 |
else:
|
| 409 |
+
gr.HTML("<div>β οΈ Stream initialization failed - Check console for errors</div>")
|
| 410 |
+
|
| 411 |
+
# Microphone activation JavaScript
|
| 412 |
+
microphone_js = '''
|
| 413 |
+
(async function() {
|
| 414 |
+
try {
|
| 415 |
+
// Request microphone permission and start audio
|
| 416 |
+
const stream = await navigator.mediaDevices.getUserMedia({
|
| 417 |
+
audio: {
|
| 418 |
+
sampleRate: 16000,
|
| 419 |
+
channelCount: 1,
|
| 420 |
+
echoCancellation: true,
|
| 421 |
+
noiseSuppression: true
|
| 422 |
+
}
|
| 423 |
+
});
|
| 424 |
+
console.log("Microphone access granted");
|
| 425 |
+
return "ποΈ Microphone connected successfully";
|
| 426 |
+
} catch (error) {
|
| 427 |
+
console.error("Microphone error:", error);
|
| 428 |
+
if (error.name === "NotAllowedError") {
|
| 429 |
+
return "β Microphone permission denied - please allow microphone access";
|
| 430 |
+
} else {
|
| 431 |
+
return "β Microphone failed: " + error.message;
|
| 432 |
+
}
|
| 433 |
+
}
|
| 434 |
+
})()
|
| 435 |
+
'''
|
| 436 |
|
| 437 |
# Instructions (Task 1-3)
|
| 438 |
with gr.Accordion("π Instructions", open=True):
|
|
|
|
| 478 |
outputs=[status_display]
|
| 479 |
)
|
| 480 |
|
| 481 |
+
mic_btn.click(
|
| 482 |
+
fn=lambda: "ποΈ Testing microphone...",
|
| 483 |
+
outputs=[status_display],
|
| 484 |
+
js=microphone_js
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
screen_btn.click(
|
| 488 |
fn=lambda: "π₯οΈ Requesting screen share...",
|
| 489 |
outputs=[status_display],
|