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

Fix: Ensure video display overwrite on regeneration

Browse files

Problem 1: Videos not overwritten when regenerating
- Previous videos remained visible even after new generation
- Users confused whether they're seeing old or new videos

Problem 2: Partial success handling unclear
- When some models fail, unclear which videos are new
- Score sliders showed for all models regardless of success

Solution:
1. Always update HTML content (success OR failure)
- Success: Show video with green border and model name
- Failure: Show warning message with orange border
- Both cases explicitly set value, ensuring overwrite

2. Individual score slider visibility per model
- Before: Used global has_results (all or nothing)
- After: Each model's slider shows only if that model succeeded

3. Visual distinction with color-coded borders
- Green (#4CAF50): Successful generation ✅
- Orange (#ff9800): Failed generation ⚠️
- Includes model name in display for clarity

Benefits:
- ✅ Every generation completely overwrites previous display
- ✅ Clear visual feedback for success/failure per model
- ✅ Score sliders only appear for successful models
- ✅ No confusion about which videos are current
- ✅ Better UX with color coding and model names

Testing: Verified with test_overwrite.py simulation

Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -782,10 +782,13 @@ with gr.Blocks(title="Video Model Evaluator") as demo:
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.
@@ -801,10 +804,20 @@ with gr.Blocks(title="Video Model Evaluator") as demo:
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
  # 添加提交按钮可见性、状态变量
810
  outputs.extend([
 
782
  for model_name in MODELS_TO_CALL:
783
  video_value = urls.get(model_name, None)
784
  # 返回视频组件更新(使用HTML video标签避免卡顿)
785
+ # 重要:每次都要明确设置value,确保覆盖之前的内容
786
  if video_value:
787
  # 使用HTML video标签,更可控且不会卡顿
788
+ display_name = MODEL_DISPLAY_NAMES.get(model_name, model_name)
789
  video_html = f"""
790
+ <div style="margin: 10px 0; padding: 15px; border: 2px solid #4CAF50; border-radius: 10px; background: #f1f8f4;">
791
+ <h4 style="margin-top: 0; color: #4CAF50;">✅ {display_name}</h4>
792
  <video controls style="width: 100%; max-width: 640px; border-radius: 8px;">
793
  <source src="{video_value}" type="video/mp4">
794
  Your browser does not support the video tag.
 
804
  </div>
805
  """
806
  outputs.append(gr.update(value=video_html, visible=True))
807
+ # 该模型成功,显示评分滑块
808
+ outputs.append(gr.update(visible=True))
809
  else:
810
+ # 该模型失败或未生成,清空并隐藏
811
+ display_name = MODEL_DISPLAY_NAMES.get(model_name, model_name)
812
+ failed_html = f"""
813
+ <div style="margin: 10px 0; padding: 15px; border: 2px solid #ff9800; border-radius: 10px; background: #fff3e0;">
814
+ <h4 style="margin-top: 0; color: #ff9800;">⚠️ {display_name}</h4>
815
+ <p style="color: #666;">视频生成失败或未完成</p>
816
+ </div>
817
+ """
818
+ outputs.append(gr.update(value=failed_html, visible=True))
819
+ # 该模型失败,隐藏评分滑块
820
+ outputs.append(gr.update(visible=False))
821
 
822
  # 添加提交按钮可见性、状态变量
823
  outputs.extend([