testcoder-ui commited on
Commit
fb37db9
·
1 Parent(s): c19d95e

Fix: Replace gr.Video with HTML video tag to prevent freezing

Browse files

Problem: Video display was freezing/hanging the webpage even though API calls were successful

Root Cause: Gradio Video component was trying to preload entire videos from CDN, causing hang

Solution: Use HTML5 video tag with gr.HTML component instead:
- Native browser video player (no preload issues)
- More responsive and faster
- Added download link and open in new tab options
- Prevents Gradio from trying to cache/preload large video files

Benefits:
- ✅ No more webpage freezing
- ✅ Instant video display with progressive loading
- ✅ User can download or open videos in new tab
- ✅ Works with CDN URLs without issues

Testing: Verified HTML video tag renders correctly and plays smoothly

Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -728,7 +728,7 @@ with gr.Blocks(title="Video Model Evaluator") as demo:
728
 
729
  for model_name in MODELS_TO_CALL:
730
  display_name = MODEL_DISPLAY_NAMES.get(model_name, model_name)
731
- video_components[model_name] = gr.Video(
732
  label=display_name,
733
  visible=False
734
  )
@@ -781,11 +781,29 @@ with gr.Blocks(title="Video Model Evaluator") as demo:
781
  # 为每个模型添加视频和评分组件更新
782
  for model_name in MODELS_TO_CALL:
783
  video_value = urls.get(model_name, None)
784
- # 返回视频组件更新(包括value和visible和评分滑块的visible
785
  if video_value:
786
- outputs.append(gr.update(value=video_value, visible=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
  else:
788
- outputs.append(gr.update(value=None, visible=False))
 
789
  outputs.append(gr.update(visible=has_results))
790
 
791
  # 添加提交按钮可见性、状态变量
 
728
 
729
  for model_name in MODELS_TO_CALL:
730
  display_name = MODEL_DISPLAY_NAMES.get(model_name, model_name)
731
+ video_components[model_name] = gr.HTML(
732
  label=display_name,
733
  visible=False
734
  )
 
781
  # 为每个模型添加视频和评分组件更新
782
  for model_name in MODELS_TO_CALL:
783
  video_value = urls.get(model_name, None)
784
+ # 返回视频组件更新(使用HTML video标签避免卡顿
785
  if video_value:
786
+ # 使用HTML video标签,更可控且不会卡顿
787
+ video_html = f"""
788
+ <div style="margin: 10px 0;">
789
+ <video controls style="width: 100%; max-width: 640px; border-radius: 8px;">
790
+ <source src="{video_value}" type="video/mp4">
791
+ Your browser does not support the video tag.
792
+ </video>
793
+ <p style="margin-top: 10px;">
794
+ <a href="{video_value}" target="_blank" download style="color: #007bff; text-decoration: none;">
795
+ 📥 下载视频
796
+ </a> |
797
+ <a href="{video_value}" target="_blank" style="color: #007bff; text-decoration: none;">
798
+ 🔗 在新标签页打开
799
+ </a>
800
+ </p>
801
+ </div>
802
+ """
803
+ outputs.append(gr.update(value=video_html, visible=True))
804
  else:
805
+ outputs.append(gr.update(value="", visible=False))
806
+ # 评分滑块可见性
807
  outputs.append(gr.update(visible=has_results))
808
 
809
  # 添加提交按钮可见性、状态变量