Pippen commited on
Commit
02712ba
·
1 Parent(s): b021144

Improve UI layout and add bilingual controls

Browse files
Files changed (1) hide show
  1. app.py +531 -83
app.py CHANGED
@@ -873,14 +873,13 @@ def make_mse_plot(mse_state, frame_idx=0):
873
  ax.plot(x, frame_errors, color="#111827", linewidth=2.4, label="总MSE", zorder=4)
874
  palette = ["#2563eb", "#059669", "#d97706", "#7c3aed", "#dc2626", "#0891b2", "#be123c", "#65a30d", "#9333ea"]
875
  for idx, name in enumerate(keypoint_names):
876
- label_name = JOINT_DISPLAY_NAMES.get(name, name)
877
- ax.plot(x, joint_frame_mse[:, idx], linewidth=1.2, alpha=0.78, color=palette[idx % len(palette)], label=label_name)
878
  ax.scatter([frame_idx], [joint_frame_mse[frame_idx, idx]], s=16, color=palette[idx % len(palette)], zorder=5)
879
  ax.scatter([frame_idx], [frame_errors[frame_idx]], s=38, color="#111827", zorder=6)
880
- ax.axvline(frame_idx, color="#f59e0b", linestyle=":", linewidth=1.8, label=f"当前帧 {frame_idx + 1}")
881
- ax.axhline(threshold, color="#ef4444", linestyle="--", linewidth=1.2, label="阈值")
882
- ax.set_title(f"{label} 每帧与各关节 MSE")
883
- ax.set_xlabel("归一化帧")
884
  ax.set_ylabel("MSE")
885
  ax.grid(alpha=0.24)
886
  ax.legend(loc="center left", bbox_to_anchor=(1.02, 0.5), fontsize=8, frameon=False)
@@ -1444,28 +1443,358 @@ def validate_cycle_and_compare(
1444
 
1445
 
1446
  custom_css = """
 
 
 
 
 
 
 
 
 
 
 
 
 
1447
  .gradio-container {
1448
- font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
1449
- background: #0a0e1a !important;
1450
- color: #e2e8f0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1451
  }
1452
- .report-container {
1453
- max-height: 400px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1454
  overflow-y: auto;
1455
- padding: 16px;
1456
- background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
1457
- border-radius: 12px;
1458
- border: 1px solid #334155;
1459
- color: #e2e8f0;
1460
  }
1461
- .gradio-video {
1462
- border-radius: 12px;
 
1463
  overflow: hidden;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1464
  }
1465
  """
1466
 
1467
 
1468
- with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1469
  clip_state = gr.State("")
1470
  cycles_state = gr.State([])
1471
  score_state = gr.State("")
@@ -1475,106 +1804,122 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1475
  mse_state = gr.State(None)
1476
  overlap_state = gr.State(None)
1477
 
1478
- gr.Markdown("# 🚣 划船动作验证器 v3")
1479
- gr.Markdown("上传划船视频,自动提取关键点并检测技术动作错误")
 
 
 
 
 
 
 
 
 
 
 
 
1480
 
1481
  with gr.Tabs():
1482
- with gr.TabItem("📹 视频上传与YOLO处理"):
1483
- gr.Markdown("## 第一步:上传视频并生成火柴人动画")
1484
 
1485
  with gr.Row():
1486
  with gr.Column(scale=1):
1487
  video_input = gr.Video(
1488
- label="上传视频",
1489
  format=None,
1490
  )
1491
 
1492
- gr.Markdown("### 视频裁剪设置")
1493
  with gr.Row():
1494
- start_input = gr.Number(value=0, precision=2, label="开始时间(秒)")
1495
- end_input = gr.Number(value=0, precision=2, label="结束时间(0=视频末尾)")
1496
- create_clip_button = gr.Button("创建裁剪片段")
1497
- clip_preview = gr.Video(label="裁剪预览", format="mp4", include_audio=False)
1498
- clip_summary = gr.Textbox(label="裁剪摘要", lines=3)
1499
 
1500
- gr.Markdown("### YOLO参数设置")
1501
- conf_input = gr.Slider(0.05, 0.90, value=0.30, step=0.05, label="检测置信度")
1502
- point_conf_input = gr.Slider(0.05, 0.90, value=0.25, step=0.05, label="关键点绘制置信度")
1503
- process_full_input = gr.Checkbox(value=True, label="处理完整视频")
1504
- max_frames_input = gr.Slider(0, 1200, value=300, step=30, label="最大处理帧数")
1505
- stride_input = gr.Slider(1, 10, value=1, step=1, label="帧步长")
1506
- smoothing_input = gr.Slider(1, 15, value=5, step=1, label="平滑窗口")
1507
- line_width_input = gr.Slider(1, 8, value=3, step=1, label="火柴人线宽")
1508
  upload_guard_input = gr.Textbox(value="empty", visible=False)
1509
 
1510
  with gr.Row():
1511
- process_button = gr.Button("处理视频生成火柴人", variant="primary")
1512
- stop_button = gr.Button("停止处理", variant="stop")
1513
 
1514
  with gr.Column(scale=1):
1515
- gr.Markdown("### 🎬 火柴人动画结果")
1516
- video_output = gr.Video(label="火柴人动画", format="mp4", include_audio=False)
1517
- file_output = gr.File(label="下载火柴人视频")
1518
- summary_output = gr.Textbox(label="处理摘要", lines=5)
1519
 
1520
- with gr.TabItem("🔄 周期选择与动作对比"):
1521
- gr.Markdown("## 第二步:选择周期并进行动作对比")
1522
 
1523
  with gr.Row():
1524
  with gr.Column(scale=1):
1525
- gr.Markdown("### 周期选择")
1526
- cycle_dropdown = gr.Dropdown(label="选择分析周期", choices=[], interactive=False)
1527
- validate_button = gr.Button("验证动作并生成对比", variant="primary")
1528
 
1529
- gr.Markdown("### 周期信息")
1530
- cycle_info_output = gr.Textbox(label="周期详情", lines=3)
1531
 
1532
  with gr.Column(scale=1):
1533
- gr.Markdown("### 🆚 动作对比")
1534
- comparison_output = gr.Image(label="逐帧对比:实际动作 vs 模型重建", type="filepath", height=560)
1535
- comparison_file = gr.File(label="下载对比视频")
1536
 
1537
- gr.Markdown("### 动作评分")
1538
- score_output = gr.Label(label="评分", value="")
1539
 
1540
- gr.Markdown("### MSE 逐帧分析")
1541
- frame_slider = gr.Slider(0, 99, value=0, step=1, label="选择归一化帧", interactive=False)
1542
- mse_plot_output = gr.Plot(label="总 MSE 与各关节 MSE")
1543
  frame_joint_mse_table = gr.Dataframe(
1544
- headers=["关键点", "原始名称", "当前帧 MSE"],
1545
  datatype=["str", "str", "str"],
1546
  row_count=0,
1547
- label="当前帧各关节 MSE",
1548
  )
1549
 
1550
- with gr.TabItem("📋 验证报告"):
1551
- gr.Markdown("## 第三步:查看验证报告")
1552
 
1553
- gr.Markdown("### 📊 诊断报告")
1554
- report_output = gr.Textbox(label="详细报告", lines=15, elem_classes=["report-container"])
1555
 
1556
- gr.Markdown("### ❌ 错误检测列表")
1557
  error_table = gr.Dataframe(
1558
- headers=["阶段", "错误类型", "严重程度"],
1559
  datatype=["str", "str", "str"],
1560
  row_count=0,
 
1561
  )
1562
 
1563
- gr.Markdown("### 📈 错误分布统计")
1564
  error_stats_output = gr.HTML()
1565
 
1566
- def update_cycle_widgets(cycles):
1567
  cycle_list = cycles.get("cycles", []) if isinstance(cycles, dict) else cycles
1568
  if not cycle_list:
1569
- return gr.update(choices=[], interactive=False, value=None), "未检测到可选周期。请尝试处理更长片段、降低帧步长,或确认人体关键点已被识别。"
 
 
 
 
1570
  choices = []
1571
  for i, c in enumerate(cycle_list):
1572
  cycle_type = "Drive" if "drive" in c[2] else "Recovery"
1573
  cycle_num = int(c[2].split('_')[0].replace('cycle', '')) if 'cycle' in c[2] else i+1
1574
  choices.append((f"Cycle {cycle_num} - {cycle_type}", i))
1575
- return gr.update(choices=choices, interactive=True, value=0), update_cycle_info(cycles, 0)
 
 
 
 
1576
 
1577
- def update_cycle_info(cycles, cycle_index):
1578
  cycle_list = cycles.get("cycles", []) if isinstance(cycles, dict) else cycles
1579
  if not cycle_list or cycle_index is None:
1580
  return ""
@@ -1583,7 +1928,7 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1583
  cycle_info = cycle_list[cycle_index]
1584
  start_frame, end_frame, label = cycle_info
1585
  phase_type = "Drive" if "drive" in label else "Recovery"
1586
- return f"周期: {label}\n阶段: {phase_type}\n帧数范围: {start_frame} - {end_frame}"
1587
 
1588
  def update_error_table(diagnoses):
1589
  if not diagnoses:
@@ -1595,7 +1940,7 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1595
 
1596
  def update_error_stats(diagnoses):
1597
  if not diagnoses:
1598
- return '<div style="text-align:center; padding:20px; color:#64748b;">暂无诊断数据</div>'
1599
 
1600
  severity_counts = {"normal": 0, "low": 0, "medium": 0, "high": 0}
1601
  for d in diagnoses:
@@ -1611,27 +1956,128 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1611
  <div style="display: flex; gap: 12px; justify-content: center;">
1612
  <div style="background: rgba(107, 203, 119, 0.1); border: 1px solid rgba(107, 203, 119, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1613
  <div style="font-size: 24px; font-weight: bold; color: #6BCB77;">{severity_counts['normal']}</div>
1614
- <div style="font-size: 12px; color: #94a3b8;">正常 ({normal_pct:.1f}%)</div>
1615
  </div>
1616
  <div style="background: rgba(255, 217, 61, 0.1); border: 1px solid rgba(255, 217, 61, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1617
  <div style="font-size: 24px; font-weight: bold; color: #FFD93D;">{severity_counts['low']}</div>
1618
- <div style="font-size: 12px; color: #94a3b8;">轻度 ({low_pct:.1f}%)</div>
1619
  </div>
1620
  <div style="background: rgba(255, 159, 67, 0.1); border: 1px solid rgba(255, 159, 67, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1621
  <div style="font-size: 24px; font-weight: bold; color: #FF9F43;">{severity_counts['medium']}</div>
1622
- <div style="font-size: 12px; color: #94a3b8;">中度 ({medium_pct:.1f}%)</div>
1623
  </div>
1624
  <div style="background: rgba(255, 107, 107, 0.1); border: 1px solid rgba(255, 107, 107, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1625
  <div style="font-size: 24px; font-weight: bold; color: #FF6B6B;">{severity_counts['high']}</div>
1626
- <div style="font-size: 12px; color: #94a3b8;">重度 ({high_pct:.1f}%)</div>
1627
  </div>
1628
  </div>
1629
  """
1630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1631
  clip_event = create_clip_button.click(
1632
  fn=create_monitored_clip,
1633
  inputs=[video_input, start_input, end_input, upload_guard_input],
1634
  outputs=[clip_state, clip_preview, clip_summary],
 
 
 
 
1635
  )
1636
 
1637
  process_event = process_button.click(
@@ -1644,17 +2090,17 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1644
  outputs=[video_output, file_output, summary_output, cycles_state],
1645
  ).then(
1646
  fn=update_cycle_widgets,
1647
- inputs=[cycles_state],
1648
- outputs=[cycle_dropdown, cycle_info_output],
1649
  )
1650
 
1651
  cycle_dropdown.change(
1652
  fn=update_cycle_info,
1653
- inputs=[cycles_state, cycle_dropdown],
1654
  outputs=[cycle_info_output],
1655
  )
1656
 
1657
- def validate_and_store(video_path, clip_path, cycles, cycle_index, progress=gr.Progress(track_tqdm=False)):
1658
  (
1659
  comp_video,
1660
  comp_file,
@@ -1681,11 +2127,12 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1681
  frame_update,
1682
  mse_plot,
1683
  frame_joint_rows,
 
1684
  )
1685
 
1686
  validate_event = validate_button.click(
1687
  fn=validate_and_store,
1688
- inputs=[video_input, clip_state, cycles_state, cycle_dropdown],
1689
  outputs=[
1690
  comparison_output,
1691
  comparison_file,
@@ -1700,6 +2147,7 @@ with gr.Blocks(title="🚣 划船动作验证器 v3") as demo:
1700
  frame_slider,
1701
  mse_plot_output,
1702
  frame_joint_mse_table,
 
1703
  ],
1704
  show_progress="full",
1705
  ).then(
 
873
  ax.plot(x, frame_errors, color="#111827", linewidth=2.4, label="总MSE", zorder=4)
874
  palette = ["#2563eb", "#059669", "#d97706", "#7c3aed", "#dc2626", "#0891b2", "#be123c", "#65a30d", "#9333ea"]
875
  for idx, name in enumerate(keypoint_names):
876
+ ax.plot(x, joint_frame_mse[:, idx], linewidth=1.2, alpha=0.78, color=palette[idx % len(palette)], label=name)
 
877
  ax.scatter([frame_idx], [joint_frame_mse[frame_idx, idx]], s=16, color=palette[idx % len(palette)], zorder=5)
878
  ax.scatter([frame_idx], [frame_errors[frame_idx]], s=38, color="#111827", zorder=6)
879
+ ax.axvline(frame_idx, color="#f59e0b", linestyle=":", linewidth=1.8, label=f"Selected frame {frame_idx + 1}")
880
+ ax.axhline(threshold, color="#ef4444", linestyle="--", linewidth=1.2, label="Threshold")
881
+ ax.set_title(f"{label} Frame and Joint MSE")
882
+ ax.set_xlabel("Normalized frame")
883
  ax.set_ylabel("MSE")
884
  ax.grid(alpha=0.24)
885
  ax.legend(loc="center left", bbox_to_anchor=(1.02, 0.5), fontsize=8, frameon=False)
 
1443
 
1444
 
1445
  custom_css = """
1446
+ :root {
1447
+ --rv-bg: #090b0f;
1448
+ --rv-panel: rgba(18, 22, 31, 0.92);
1449
+ --rv-panel-2: rgba(24, 29, 40, 0.86);
1450
+ --rv-line: rgba(148, 163, 184, 0.24);
1451
+ --rv-text: #edf2f7;
1452
+ --rv-muted: #9aa7b5;
1453
+ --rv-cyan: #22d3ee;
1454
+ --rv-green: #34d399;
1455
+ --rv-amber: #f59e0b;
1456
+ --rv-coral: #fb7185;
1457
+ }
1458
+
1459
  .gradio-container {
1460
+ font-family: 'Inter', 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
1461
+ background:
1462
+ radial-gradient(circle at 18% 8%, rgba(34, 211, 238, 0.18), transparent 24%),
1463
+ radial-gradient(circle at 88% 18%, rgba(251, 113, 133, 0.16), transparent 26%),
1464
+ linear-gradient(145deg, #080a0e 0%, #101318 48%, #15110d 100%) !important;
1465
+ color: var(--rv-text) !important;
1466
+ }
1467
+
1468
+ .gradio-container .main {
1469
+ max-width: 1500px;
1470
+ }
1471
+
1472
+ .rv-hero {
1473
+ padding: 22px 26px;
1474
+ border: 1px solid var(--rv-line);
1475
+ background: linear-gradient(135deg, rgba(15, 23, 42, 0.88), rgba(18, 18, 22, 0.82));
1476
+ border-radius: 8px;
1477
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
1478
+ display: flex;
1479
+ justify-content: space-between;
1480
+ gap: 18px;
1481
+ align-items: flex-end;
1482
+ }
1483
+
1484
+ .rv-kicker {
1485
+ color: var(--rv-cyan);
1486
+ font-size: 12px;
1487
+ font-weight: 760;
1488
+ letter-spacing: 0.12em;
1489
+ margin-bottom: 8px;
1490
+ }
1491
+
1492
+ .rv-title {
1493
+ font-size: 34px;
1494
+ line-height: 1.12;
1495
+ font-weight: 780;
1496
+ letter-spacing: 0;
1497
+ margin-bottom: 10px;
1498
+ }
1499
+
1500
+ .rv-subtitle {
1501
+ color: var(--rv-muted);
1502
+ font-size: 15px;
1503
+ }
1504
+
1505
+ .rv-hero-metrics {
1506
+ display: grid;
1507
+ grid-template-columns: repeat(3, minmax(90px, 1fr));
1508
+ gap: 10px;
1509
+ min-width: 330px;
1510
+ }
1511
+
1512
+ .rv-hero-metrics div {
1513
+ border: 1px solid rgba(148, 163, 184, 0.22);
1514
+ background: rgba(2, 6, 23, 0.38);
1515
+ border-radius: 8px;
1516
+ padding: 10px 12px;
1517
+ }
1518
+
1519
+ .rv-hero-metrics strong {
1520
+ display: block;
1521
+ color: #f8fafc;
1522
+ font-size: 14px;
1523
+ }
1524
+
1525
+ .rv-hero-metrics span {
1526
+ color: var(--rv-muted);
1527
+ font-size: 12px;
1528
+ }
1529
+
1530
+ .rv-language {
1531
+ max-width: 280px;
1532
+ margin: 12px 0 4px;
1533
+ }
1534
+
1535
+ .rv-status {
1536
+ display: grid;
1537
+ grid-template-columns: repeat(3, minmax(0, 1fr));
1538
+ gap: 12px;
1539
+ margin: 14px 0 8px;
1540
  }
1541
+
1542
+ .rv-step {
1543
+ border: 1px solid var(--rv-line);
1544
+ border-radius: 8px;
1545
+ padding: 12px 14px;
1546
+ background: var(--rv-panel);
1547
+ }
1548
+
1549
+ .rv-step strong {
1550
+ display: block;
1551
+ color: var(--rv-text);
1552
+ font-size: 14px;
1553
+ margin-bottom: 5px;
1554
+ }
1555
+
1556
+ .rv-step span {
1557
+ color: var(--rv-muted);
1558
+ font-size: 12px;
1559
+ }
1560
+
1561
+ .rv-step.active {
1562
+ border-color: rgba(34, 211, 238, 0.78);
1563
+ box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.22), 0 0 24px rgba(34, 211, 238, 0.08);
1564
+ }
1565
+
1566
+ .rv-step.done {
1567
+ border-color: rgba(52, 211, 153, 0.62);
1568
+ }
1569
+
1570
+ .rv-callout {
1571
+ border: 1px solid rgba(245, 158, 11, 0.35);
1572
+ background: rgba(245, 158, 11, 0.08);
1573
+ color: #fde68a;
1574
+ padding: 12px 14px;
1575
+ border-radius: 8px;
1576
+ margin: 10px 0 14px;
1577
+ font-size: 14px;
1578
+ }
1579
+
1580
+ .rv-panel {
1581
+ border: 1px solid var(--rv-line);
1582
+ background: var(--rv-panel);
1583
+ border-radius: 8px;
1584
+ padding: 14px;
1585
+ }
1586
+
1587
+ .rv-section-title {
1588
+ color: var(--rv-text);
1589
+ font-size: 18px;
1590
+ font-weight: 720;
1591
+ margin: 2px 0 10px;
1592
+ }
1593
+
1594
+ .rv-note {
1595
+ color: var(--rv-muted);
1596
+ font-size: 13px;
1597
+ margin: -4px 0 12px;
1598
+ }
1599
+
1600
+ .report-container textarea {
1601
+ max-height: 430px;
1602
  overflow-y: auto;
1603
+ background: rgba(7, 10, 15, 0.92) !important;
1604
+ border: 1px solid rgba(148, 163, 184, 0.22) !important;
1605
+ color: #dbeafe !important;
 
 
1606
  }
1607
+
1608
+ .gradio-video, .gradio-image {
1609
+ border-radius: 8px;
1610
  overflow: hidden;
1611
+ border: 1px solid var(--rv-line);
1612
+ background: #05070a;
1613
+ }
1614
+
1615
+ button.primary {
1616
+ border-radius: 8px !important;
1617
+ box-shadow: 0 10px 30px rgba(34, 211, 238, 0.14);
1618
+ }
1619
+
1620
+ .tabs > .tab-nav {
1621
+ border-bottom: 1px solid var(--rv-line);
1622
+ }
1623
+
1624
+ @media (max-width: 760px) {
1625
+ .rv-hero {
1626
+ display: block;
1627
+ }
1628
+ .rv-hero-metrics {
1629
+ grid-template-columns: 1fr;
1630
+ min-width: 0;
1631
+ margin-top: 16px;
1632
+ }
1633
+ .rv-status {
1634
+ grid-template-columns: 1fr;
1635
+ }
1636
+ .rv-title {
1637
+ font-size: 26px;
1638
+ }
1639
  }
1640
  """
1641
 
1642
 
1643
+ UI_TEXT = {
1644
+ "zh": {
1645
+ "subtitle": "划船动作识别、周期切分、模型对比与技术诊断控制台",
1646
+ "intro": "从左侧上传视频开始。需要截取片段时先创建裁剪片段;否则可以直接处理完整视频。",
1647
+ "clip_ready": "裁剪片段已准备好。下一步:点击“生成火柴人并检测周期”。",
1648
+ "cycles_ready": "周期已就绪。下一步:选择片段,然后点击“验证动作并生成对比”。",
1649
+ "cycles_empty": "没有检测到稳定周期。下一步:延长片段或降低帧步长后重新生成火柴人。",
1650
+ "validated": "验证完成。下一步:拖动帧滑块查看误差峰值,或切到诊断报告复盘问题。",
1651
+ "step1": ("上传与处理", "生成火柴人和周期片段"),
1652
+ "step2": ("周期对比", "选择片段并运行验证"),
1653
+ "step3": ("报告复盘", "查看诊断和误差分布"),
1654
+ "lang_label": "界面语言",
1655
+ "process_title": "第一步:上传视频并生成火柴人动画",
1656
+ "upload_label": "上传视频",
1657
+ "clip_note": "可先截取 5-15 秒动作片段,再进入模型处理。",
1658
+ "start_label": "开始时间(秒)",
1659
+ "end_label": "结束时间(0=视频末尾)",
1660
+ "clip_button": "创建裁剪片段",
1661
+ "clip_preview": "裁剪预览",
1662
+ "clip_summary": "裁剪摘要",
1663
+ "param_title": "处理参数",
1664
+ "conf_label": "检测置信度",
1665
+ "point_conf_label": "关键点绘制置信度",
1666
+ "full_label": "处理完整视频",
1667
+ "max_frames_label": "最大处理帧数",
1668
+ "stride_label": "帧步长",
1669
+ "smooth_label": "平滑窗口",
1670
+ "line_label": "火柴人线宽",
1671
+ "process_button": "生成火柴人并检测周期",
1672
+ "stop_button": "停止处理",
1673
+ "result_title": "处理结果",
1674
+ "stickman_video": "火柴人动画",
1675
+ "stickman_file": "下载火柴人视频",
1676
+ "summary": "处理摘要",
1677
+ "compare_title": "第二步:选择周期并进行动作对比",
1678
+ "cycle_note": "生成火柴人后,这里会出现可分析的 Drive / Recovery 片段。",
1679
+ "cycle_dropdown": "选择分析周期",
1680
+ "validate_button": "验证动作并生成对比",
1681
+ "cycle_info": "周期详情",
1682
+ "overlap_title": "实际动作 vs 模型重建",
1683
+ "comparison": "逐帧对比:实际动作 vs 模型重建",
1684
+ "comparison_file": "下载对比视频",
1685
+ "score_title": "评分与误差",
1686
+ "score": "评分",
1687
+ "frame_slider": "选择归一化帧",
1688
+ "mse_plot": "Total MSE and Joint MSE",
1689
+ "joint_table": "当前帧各关节 MSE",
1690
+ "report_title": "第三步:查看验证报告",
1691
+ "report": "详细报告",
1692
+ "error_table": "错误检测列表",
1693
+ "cycle_none": "未检测到可选周期。请尝试处理更长片段、降低帧步长,或确认人体关键点已被识别。",
1694
+ "cycle_info_value": "周期: {label}\n阶段: {phase}\n帧数范围: {start} - {end}",
1695
+ "stats_empty": "暂无诊断数据",
1696
+ },
1697
+ "en": {
1698
+ "subtitle": "Rowing pose tracking, cycle segmentation, model comparison, and technique diagnostics",
1699
+ "intro": "Start by uploading a rowing video. Create a clip first if you only want to analyze a short segment.",
1700
+ "clip_ready": "Clip is ready. Next: click Generate Stickman and Detect Cycles.",
1701
+ "cycles_ready": "Cycles are ready. Next: choose a segment and run validation.",
1702
+ "cycles_empty": "No stable cycle was detected. Next: use a longer clip or lower frame stride, then process again.",
1703
+ "validated": "Validation complete. Next: scrub the frame slider or open the report tab for details.",
1704
+ "step1": ("Upload & Process", "Generate stickman and cycles"),
1705
+ "step2": ("Cycle Compare", "Select a segment and validate"),
1706
+ "step3": ("Report Review", "Inspect diagnostics and MSE"),
1707
+ "lang_label": "Language",
1708
+ "process_title": "Step 1: Upload Video and Generate Stickman",
1709
+ "upload_label": "Upload video",
1710
+ "clip_note": "Optionally trim a 5-15 second segment before processing.",
1711
+ "start_label": "Start time (sec)",
1712
+ "end_label": "End time (0 = video end)",
1713
+ "clip_button": "Create Clip",
1714
+ "clip_preview": "Clip preview",
1715
+ "clip_summary": "Clip summary",
1716
+ "param_title": "Processing Parameters",
1717
+ "conf_label": "Detection confidence",
1718
+ "point_conf_label": "Keypoint drawing confidence",
1719
+ "full_label": "Process full video",
1720
+ "max_frames_label": "Max frames",
1721
+ "stride_label": "Frame stride",
1722
+ "smooth_label": "Smoothing window",
1723
+ "line_label": "Stickman line width",
1724
+ "process_button": "Generate Stickman and Detect Cycles",
1725
+ "stop_button": "Stop",
1726
+ "result_title": "Processing Result",
1727
+ "stickman_video": "Stickman video",
1728
+ "stickman_file": "Download stickman video",
1729
+ "summary": "Processing summary",
1730
+ "compare_title": "Step 2: Select Cycle and Compare Motion",
1731
+ "cycle_note": "Drive / Recovery segments appear here after processing.",
1732
+ "cycle_dropdown": "Select analysis cycle",
1733
+ "validate_button": "Validate Motion and Generate Comparison",
1734
+ "cycle_info": "Cycle details",
1735
+ "overlap_title": "Actual Pose vs Model Reconstruction",
1736
+ "comparison": "Frame comparison: actual pose vs model reconstruction",
1737
+ "comparison_file": "Download comparison video",
1738
+ "score_title": "Score and Error",
1739
+ "score": "Score",
1740
+ "frame_slider": "Select normalized frame",
1741
+ "mse_plot": "Total MSE and Joint MSE",
1742
+ "joint_table": "Current-frame joint MSE",
1743
+ "report_title": "Step 3: Review Diagnostic Report",
1744
+ "report": "Detailed report",
1745
+ "error_table": "Detected error list",
1746
+ "cycle_none": "No selectable cycle. Try a longer clip, lower frame stride, or clearer side-view video.",
1747
+ "cycle_info_value": "Cycle: {label}\nPhase: {phase}\nFrame range: {start} - {end}",
1748
+ "stats_empty": "No diagnostics yet",
1749
+ },
1750
+ }
1751
+
1752
+
1753
+ def ui_text(lang: str, key: str):
1754
+ return UI_TEXT.get(lang, UI_TEXT["zh"])[key]
1755
+
1756
+
1757
+ def hero_html(lang: str) -> str:
1758
+ return f"""
1759
+ <div class="rv-hero">
1760
+ <div>
1761
+ <div class="rv-kicker">AI ROWING COACH</div>
1762
+ <div class="rv-title">Rowing Validator v3</div>
1763
+ <div class="rv-subtitle">{ui_text(lang, "subtitle")}</div>
1764
+ </div>
1765
+ <div class="rv-hero-metrics">
1766
+ <div><strong>YOLO11x</strong><span>Pose</span></div>
1767
+ <div><strong>LSTM AE</strong><span>Validation</span></div>
1768
+ <div><strong>MSE</strong><span>Diagnostics</span></div>
1769
+ </div>
1770
+ </div>
1771
+ """
1772
+
1773
+
1774
+ def section_html(title: str) -> str:
1775
+ return f'<div class="rv-section-title">{title}</div>'
1776
+
1777
+
1778
+ def note_html(text: str) -> str:
1779
+ return f'<div class="rv-note">{text}</div>'
1780
+
1781
+
1782
+ def workflow_html(active_step: int = 1, message: str | None = None, lang: str = "zh") -> str:
1783
+ steps = [
1784
+ ("1", *ui_text(lang, "step1")),
1785
+ ("2", *ui_text(lang, "step2")),
1786
+ ("3", *ui_text(lang, "step3")),
1787
+ ]
1788
+ cards = []
1789
+ for idx, title, desc in steps:
1790
+ number = int(idx)
1791
+ cls = "rv-step active" if number == active_step else "rv-step done" if number < active_step else "rv-step"
1792
+ cards.append(f'<div class="{cls}"><strong>{idx}. {title}</strong><span>{desc}</span></div>')
1793
+ callout = f'<div class="rv-callout">{message}</div>' if message else ""
1794
+ return f'<div class="rv-status">{"".join(cards)}</div>{callout}'
1795
+
1796
+
1797
+ with gr.Blocks(title="Rowing Validator v3") as demo:
1798
  clip_state = gr.State("")
1799
  cycles_state = gr.State([])
1800
  score_state = gr.State("")
 
1804
  mse_state = gr.State(None)
1805
  overlap_state = gr.State(None)
1806
 
1807
+ hero_output = gr.HTML(hero_html("zh"))
1808
+ language_input = gr.Radio(
1809
+ choices=[("中文", "zh"), ("English", "en")],
1810
+ value="zh",
1811
+ label=ui_text("zh", "lang_label"),
1812
+ elem_classes=["rv-language"],
1813
+ )
1814
+ workflow_status = gr.HTML(
1815
+ workflow_html(
1816
+ 1,
1817
+ ui_text("zh", "intro"),
1818
+ "zh",
1819
+ )
1820
+ )
1821
 
1822
  with gr.Tabs():
1823
+ with gr.TabItem("视频处理 / Process"):
1824
+ process_title_html = gr.HTML(section_html(ui_text("zh", "process_title")))
1825
 
1826
  with gr.Row():
1827
  with gr.Column(scale=1):
1828
  video_input = gr.Video(
1829
+ label=ui_text("zh", "upload_label"),
1830
  format=None,
1831
  )
1832
 
1833
+ clip_note_html = gr.HTML(note_html(ui_text("zh", "clip_note")))
1834
  with gr.Row():
1835
+ start_input = gr.Number(value=0, precision=2, label=ui_text("zh", "start_label"))
1836
+ end_input = gr.Number(value=0, precision=2, label=ui_text("zh", "end_label"))
1837
+ create_clip_button = gr.Button(ui_text("zh", "clip_button"), variant="secondary")
1838
+ clip_preview = gr.Video(label=ui_text("zh", "clip_preview"), format="mp4", include_audio=False)
1839
+ clip_summary = gr.Textbox(label=ui_text("zh", "clip_summary"), lines=3)
1840
 
1841
+ param_title_html = gr.HTML(section_html(ui_text("zh", "param_title")))
1842
+ conf_input = gr.Slider(0.05, 0.90, value=0.30, step=0.05, label=ui_text("zh", "conf_label"))
1843
+ point_conf_input = gr.Slider(0.05, 0.90, value=0.25, step=0.05, label=ui_text("zh", "point_conf_label"))
1844
+ process_full_input = gr.Checkbox(value=True, label=ui_text("zh", "full_label"))
1845
+ max_frames_input = gr.Slider(0, 1200, value=300, step=30, label=ui_text("zh", "max_frames_label"))
1846
+ stride_input = gr.Slider(1, 10, value=1, step=1, label=ui_text("zh", "stride_label"))
1847
+ smoothing_input = gr.Slider(1, 15, value=5, step=1, label=ui_text("zh", "smooth_label"))
1848
+ line_width_input = gr.Slider(1, 8, value=3, step=1, label=ui_text("zh", "line_label"))
1849
  upload_guard_input = gr.Textbox(value="empty", visible=False)
1850
 
1851
  with gr.Row():
1852
+ process_button = gr.Button(ui_text("zh", "process_button"), variant="primary")
1853
+ stop_button = gr.Button(ui_text("zh", "stop_button"), variant="stop")
1854
 
1855
  with gr.Column(scale=1):
1856
+ result_title_html = gr.HTML(section_html(ui_text("zh", "result_title")))
1857
+ video_output = gr.Video(label=ui_text("zh", "stickman_video"), format="mp4", include_audio=False)
1858
+ file_output = gr.File(label=ui_text("zh", "stickman_file"))
1859
+ summary_output = gr.Textbox(label=ui_text("zh", "summary"), lines=5)
1860
 
1861
+ with gr.TabItem("动作对比 / Compare"):
1862
+ compare_title_html = gr.HTML(section_html(ui_text("zh", "compare_title")))
1863
 
1864
  with gr.Row():
1865
  with gr.Column(scale=1):
1866
+ cycle_note_html = gr.HTML(note_html(ui_text("zh", "cycle_note")))
1867
+ cycle_dropdown = gr.Dropdown(label=ui_text("zh", "cycle_dropdown"), choices=[], interactive=False)
1868
+ validate_button = gr.Button(ui_text("zh", "validate_button"), variant="primary")
1869
 
1870
+ cycle_info_output = gr.Textbox(label=ui_text("zh", "cycle_info"), lines=3)
 
1871
 
1872
  with gr.Column(scale=1):
1873
+ overlap_title_html = gr.HTML(section_html(ui_text("zh", "overlap_title")))
1874
+ comparison_output = gr.Image(label=ui_text("zh", "comparison"), type="filepath", height=560)
1875
+ comparison_file = gr.File(label=ui_text("zh", "comparison_file"))
1876
 
1877
+ score_title_html = gr.HTML(section_html(ui_text("zh", "score_title")))
1878
+ score_output = gr.Label(label=ui_text("zh", "score"), value="")
1879
 
1880
+ frame_slider = gr.Slider(0, 99, value=0, step=1, label=ui_text("zh", "frame_slider"), interactive=False)
1881
+ mse_plot_output = gr.Plot(label=ui_text("zh", "mse_plot"))
 
1882
  frame_joint_mse_table = gr.Dataframe(
1883
+ headers=["Joint", "Name", "Current Frame MSE"],
1884
  datatype=["str", "str", "str"],
1885
  row_count=0,
1886
+ label=ui_text("zh", "joint_table"),
1887
  )
1888
 
1889
+ with gr.TabItem("诊断报告 / Report"):
1890
+ report_title_html = gr.HTML(section_html(ui_text("zh", "report_title")))
1891
 
1892
+ report_output = gr.Textbox(label=ui_text("zh", "report"), lines=15, elem_classes=["report-container"])
 
1893
 
 
1894
  error_table = gr.Dataframe(
1895
+ headers=["Phase", "Error Type", "Severity"],
1896
  datatype=["str", "str", "str"],
1897
  row_count=0,
1898
+ label=ui_text("zh", "error_table"),
1899
  )
1900
 
 
1901
  error_stats_output = gr.HTML()
1902
 
1903
+ def update_cycle_widgets(cycles, lang):
1904
  cycle_list = cycles.get("cycles", []) if isinstance(cycles, dict) else cycles
1905
  if not cycle_list:
1906
+ return (
1907
+ gr.update(choices=[], interactive=False, value=None),
1908
+ ui_text(lang, "cycle_none"),
1909
+ workflow_html(1, ui_text(lang, "cycles_empty"), lang),
1910
+ )
1911
  choices = []
1912
  for i, c in enumerate(cycle_list):
1913
  cycle_type = "Drive" if "drive" in c[2] else "Recovery"
1914
  cycle_num = int(c[2].split('_')[0].replace('cycle', '')) if 'cycle' in c[2] else i+1
1915
  choices.append((f"Cycle {cycle_num} - {cycle_type}", i))
1916
+ return (
1917
+ gr.update(choices=choices, interactive=True, value=0),
1918
+ update_cycle_info(cycles, 0, lang),
1919
+ workflow_html(2, ui_text(lang, "cycles_ready"), lang),
1920
+ )
1921
 
1922
+ def update_cycle_info(cycles, cycle_index, lang="zh"):
1923
  cycle_list = cycles.get("cycles", []) if isinstance(cycles, dict) else cycles
1924
  if not cycle_list or cycle_index is None:
1925
  return ""
 
1928
  cycle_info = cycle_list[cycle_index]
1929
  start_frame, end_frame, label = cycle_info
1930
  phase_type = "Drive" if "drive" in label else "Recovery"
1931
+ return ui_text(lang, "cycle_info_value").format(label=label, phase=phase_type, start=start_frame, end=end_frame)
1932
 
1933
  def update_error_table(diagnoses):
1934
  if not diagnoses:
 
1940
 
1941
  def update_error_stats(diagnoses):
1942
  if not diagnoses:
1943
+ return '<div style="text-align:center; padding:20px; color:#64748b;">No diagnostics yet</div>'
1944
 
1945
  severity_counts = {"normal": 0, "low": 0, "medium": 0, "high": 0}
1946
  for d in diagnoses:
 
1956
  <div style="display: flex; gap: 12px; justify-content: center;">
1957
  <div style="background: rgba(107, 203, 119, 0.1); border: 1px solid rgba(107, 203, 119, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1958
  <div style="font-size: 24px; font-weight: bold; color: #6BCB77;">{severity_counts['normal']}</div>
1959
+ <div style="font-size: 12px; color: #94a3b8;">Normal ({normal_pct:.1f}%)</div>
1960
  </div>
1961
  <div style="background: rgba(255, 217, 61, 0.1); border: 1px solid rgba(255, 217, 61, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1962
  <div style="font-size: 24px; font-weight: bold; color: #FFD93D;">{severity_counts['low']}</div>
1963
+ <div style="font-size: 12px; color: #94a3b8;">Low ({low_pct:.1f}%)</div>
1964
  </div>
1965
  <div style="background: rgba(255, 159, 67, 0.1); border: 1px solid rgba(255, 159, 67, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1966
  <div style="font-size: 24px; font-weight: bold; color: #FF9F43;">{severity_counts['medium']}</div>
1967
+ <div style="font-size: 12px; color: #94a3b8;">Medium ({medium_pct:.1f}%)</div>
1968
  </div>
1969
  <div style="background: rgba(255, 107, 107, 0.1); border: 1px solid rgba(255, 107, 107, 0.3); border-radius: 8px; padding: 12px 20px; text-align: center;">
1970
  <div style="font-size: 24px; font-weight: bold; color: #FF6B6B;">{severity_counts['high']}</div>
1971
+ <div style="font-size: 12px; color: #94a3b8;">High ({high_pct:.1f}%)</div>
1972
  </div>
1973
  </div>
1974
  """
1975
 
1976
+ def clip_next_message(lang):
1977
+ return workflow_html(1, ui_text(lang, "clip_ready"), lang)
1978
+
1979
+ def update_language(lang):
1980
+ return (
1981
+ hero_html(lang),
1982
+ gr.update(label=ui_text(lang, "lang_label")),
1983
+ workflow_html(1, ui_text(lang, "intro"), lang),
1984
+ section_html(ui_text(lang, "process_title")),
1985
+ gr.update(label=ui_text(lang, "upload_label")),
1986
+ note_html(ui_text(lang, "clip_note")),
1987
+ gr.update(label=ui_text(lang, "start_label")),
1988
+ gr.update(label=ui_text(lang, "end_label")),
1989
+ gr.update(value=ui_text(lang, "clip_button")),
1990
+ gr.update(label=ui_text(lang, "clip_preview")),
1991
+ gr.update(label=ui_text(lang, "clip_summary")),
1992
+ section_html(ui_text(lang, "param_title")),
1993
+ gr.update(label=ui_text(lang, "conf_label")),
1994
+ gr.update(label=ui_text(lang, "point_conf_label")),
1995
+ gr.update(label=ui_text(lang, "full_label")),
1996
+ gr.update(label=ui_text(lang, "max_frames_label")),
1997
+ gr.update(label=ui_text(lang, "stride_label")),
1998
+ gr.update(label=ui_text(lang, "smooth_label")),
1999
+ gr.update(label=ui_text(lang, "line_label")),
2000
+ gr.update(value=ui_text(lang, "process_button")),
2001
+ gr.update(value=ui_text(lang, "stop_button")),
2002
+ section_html(ui_text(lang, "result_title")),
2003
+ gr.update(label=ui_text(lang, "stickman_video")),
2004
+ gr.update(label=ui_text(lang, "stickman_file")),
2005
+ gr.update(label=ui_text(lang, "summary")),
2006
+ section_html(ui_text(lang, "compare_title")),
2007
+ note_html(ui_text(lang, "cycle_note")),
2008
+ gr.update(label=ui_text(lang, "cycle_dropdown")),
2009
+ gr.update(value=ui_text(lang, "validate_button")),
2010
+ gr.update(label=ui_text(lang, "cycle_info")),
2011
+ section_html(ui_text(lang, "overlap_title")),
2012
+ gr.update(label=ui_text(lang, "comparison")),
2013
+ gr.update(label=ui_text(lang, "comparison_file")),
2014
+ section_html(ui_text(lang, "score_title")),
2015
+ gr.update(label=ui_text(lang, "score")),
2016
+ gr.update(label=ui_text(lang, "frame_slider")),
2017
+ gr.update(label=ui_text(lang, "mse_plot")),
2018
+ gr.update(label=ui_text(lang, "joint_table")),
2019
+ section_html(ui_text(lang, "report_title")),
2020
+ gr.update(label=ui_text(lang, "report")),
2021
+ gr.update(label=ui_text(lang, "error_table")),
2022
+ )
2023
+
2024
+ language_input.change(
2025
+ fn=update_language,
2026
+ inputs=[language_input],
2027
+ outputs=[
2028
+ hero_output,
2029
+ language_input,
2030
+ workflow_status,
2031
+ process_title_html,
2032
+ video_input,
2033
+ clip_note_html,
2034
+ start_input,
2035
+ end_input,
2036
+ create_clip_button,
2037
+ clip_preview,
2038
+ clip_summary,
2039
+ param_title_html,
2040
+ conf_input,
2041
+ point_conf_input,
2042
+ process_full_input,
2043
+ max_frames_input,
2044
+ stride_input,
2045
+ smoothing_input,
2046
+ line_width_input,
2047
+ process_button,
2048
+ stop_button,
2049
+ result_title_html,
2050
+ video_output,
2051
+ file_output,
2052
+ summary_output,
2053
+ compare_title_html,
2054
+ cycle_note_html,
2055
+ cycle_dropdown,
2056
+ validate_button,
2057
+ cycle_info_output,
2058
+ overlap_title_html,
2059
+ comparison_output,
2060
+ comparison_file,
2061
+ score_title_html,
2062
+ score_output,
2063
+ frame_slider,
2064
+ mse_plot_output,
2065
+ frame_joint_mse_table,
2066
+ report_title_html,
2067
+ report_output,
2068
+ error_table,
2069
+ ],
2070
+ show_progress="hidden",
2071
+ )
2072
+
2073
  clip_event = create_clip_button.click(
2074
  fn=create_monitored_clip,
2075
  inputs=[video_input, start_input, end_input, upload_guard_input],
2076
  outputs=[clip_state, clip_preview, clip_summary],
2077
+ ).then(
2078
+ fn=clip_next_message,
2079
+ inputs=[language_input],
2080
+ outputs=[workflow_status],
2081
  )
2082
 
2083
  process_event = process_button.click(
 
2090
  outputs=[video_output, file_output, summary_output, cycles_state],
2091
  ).then(
2092
  fn=update_cycle_widgets,
2093
+ inputs=[cycles_state, language_input],
2094
+ outputs=[cycle_dropdown, cycle_info_output, workflow_status],
2095
  )
2096
 
2097
  cycle_dropdown.change(
2098
  fn=update_cycle_info,
2099
+ inputs=[cycles_state, cycle_dropdown, language_input],
2100
  outputs=[cycle_info_output],
2101
  )
2102
 
2103
+ def validate_and_store(video_path, clip_path, cycles, cycle_index, lang, progress=gr.Progress(track_tqdm=False)):
2104
  (
2105
  comp_video,
2106
  comp_file,
 
2127
  frame_update,
2128
  mse_plot,
2129
  frame_joint_rows,
2130
+ workflow_html(3, ui_text(lang, "validated"), lang),
2131
  )
2132
 
2133
  validate_event = validate_button.click(
2134
  fn=validate_and_store,
2135
+ inputs=[video_input, clip_state, cycles_state, cycle_dropdown, language_input],
2136
  outputs=[
2137
  comparison_output,
2138
  comparison_file,
 
2147
  frame_slider,
2148
  mse_plot_output,
2149
  frame_joint_mse_table,
2150
+ workflow_status,
2151
  ],
2152
  show_progress="full",
2153
  ).then(