arthrod commited on
Commit
0a778fe
Β·
verified Β·
1 Parent(s): ddf5b28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -6
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
- if stream and hasattr(stream, 'ui'):
399
- gr.Markdown("### πŸ“‘ Live Stream")
400
- # Mount the FastRTC stream UI
401
- stream_ui = stream.ui
 
 
 
 
 
402
  else:
403
- stream_ui = gr.HTML("<div>⚠️ Stream initialization failed</div>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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],