Neil-YL commited on
Commit
cc31f45
·
verified ·
1 Parent(s): 7ef0467

test youtube video id update

Browse files
Files changed (1) hide show
  1. app.py +42 -16
app.py CHANGED
@@ -364,6 +364,8 @@ def add_to_queue(student_id, R, Y, B):
364
  result = result_queue.get()
365
  yield result
366
 
 
 
367
  def debug_experiment(student_id, R, Y, B):
368
  if student_id != "debug":
369
  return {"Status": "Error", "Message": "Invalid debug request"}
@@ -414,7 +416,24 @@ def debug_experiment(student_id, R, Y, B):
414
  }
415
 
416
  yield result_debug
417
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
 
419
  with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
420
  gr.Markdown("## OT-2 Liquid Color Matching Experiment Queue")
@@ -440,22 +459,29 @@ with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
440
  gr.Markdown("### Queue Status")
441
  queue_status = gr.Markdown("Loading queue status...")
442
  update_status_btn = gr.Button("Refresh Queue Status")
 
443
  gr.Markdown("### YouTube Livestream")
444
- #src="https://www.youtube.com/embed/live_stream?channel=UCHBzCfYpGwoqygH9YNh9A6g"
445
- iframe_html = f'''
446
- <div style="position: relative; width: 100%; padding-top: 56.25%;">
447
- <iframe
448
- style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
449
- src="https://www.youtube.com/embed/{video_id}"
450
- title="OT-2 Livestream"
451
- frameborder="0"
452
- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
453
- referrerpolicy="strict-origin-when-cross-origin"
454
- allowfullscreen>
455
- </iframe>
456
- </div>
457
- '''
458
- gr.HTML(iframe_html)
 
 
 
 
 
 
459
 
460
  verify_id_btn.click(
461
  verify_student_id,
 
364
  result = result_queue.get()
365
  yield result
366
 
367
+
368
+
369
  def debug_experiment(student_id, R, Y, B):
370
  if student_id != "debug":
371
  return {"Status": "Error", "Message": "Invalid debug request"}
 
416
  }
417
 
418
  yield result_debug
419
+
420
+ def refresh_video():
421
+ video_id = get_latest_video_id(channel_id, playlist_id)
422
+ print(f"[DEBUG]video id: {video_id}")
423
+ iframe_html = f'''
424
+ <div style="position: relative; width: 100%; padding-top: 56.25%;">
425
+ <iframe
426
+ style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
427
+ src="https://www.youtube.com/embed/{video_id}"
428
+ title="OT-2 Livestream"
429
+ frameborder="0"
430
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
431
+ referrerpolicy="strict-origin-when-cross-origin"
432
+ allowfullscreen>
433
+ </iframe>
434
+ </div>
435
+ '''
436
+ return iframe_html
437
 
438
  with gr.Blocks(title="OT-2 Liquid Color Matching Experiment Queue") as demo:
439
  gr.Markdown("## OT-2 Liquid Color Matching Experiment Queue")
 
459
  gr.Markdown("### Queue Status")
460
  queue_status = gr.Markdown("Loading queue status...")
461
  update_status_btn = gr.Button("Refresh Queue Status")
462
+
463
  gr.Markdown("### YouTube Livestream")
464
+
465
+ def refresh_iframe():
466
+ video_id = get_latest_video_id(channel_id, playlist_id="PL8uZlc2CEpenUCAo9PeiOtbU04lFv48yD")
467
+ print(f"[DEBUG]video id: {video_id}")
468
+ return f'''
469
+ <div style="position: relative; width: 100%; padding-top: 56.25%;">
470
+ <iframe
471
+ style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"
472
+ src="https://www.youtube.com/embed/{video_id}"
473
+ title="OT-2 Livestream"
474
+ frameborder="0"
475
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
476
+ referrerpolicy="strict-origin-when-cross-origin"
477
+ allowfullscreen>
478
+ </iframe>
479
+ </div>
480
+ '''
481
+
482
+ iframe_component = gr.HTML(refresh_iframe())
483
+ refresh_video_btn = gr.Button("Refresh Livestream")
484
+ refresh_video_btn.click(fn=refresh_iframe, outputs=iframe_component)
485
 
486
  verify_id_btn.click(
487
  verify_student_id,