Wenjiawang0312 commited on
Commit
f3c78a2
·
1 Parent(s): 4060232
Files changed (1) hide show
  1. app.py +96 -48
app.py CHANGED
@@ -180,36 +180,51 @@ def create_video_survey_app():
180
  gr.Markdown(f"## 场景 {scene_idx + 1} / Scene {scene_idx + 1}: `{scene_name}`")
181
 
182
  # 4个视频横向排列
183
- with gr.Row():
184
  scene_ratings = []
185
  for i in range(4):
186
  method_name = f"Method {chr(65+i)}"
187
 
188
- with gr.Column():
189
  gr.Markdown(f"### 🎥 {method_name}")
190
 
191
  # 视频
192
  if method_name in videos:
193
- video = gr.Video(value=videos[method_name], label="", height=300)
194
  else:
195
- video = gr.Video(value=None, label="", height=300, visible=False)
196
 
197
  # 三个评分滑块(垂直排列)
198
- dynamic = gr.Slider(
199
- minimum=1, maximum=5, step=1, value=3,
200
- label="动态质量 / Dynamic",
201
- info="1=差, 5=优秀"
202
- )
203
- static = gr.Slider(
204
- minimum=1, maximum=5, step=1, value=3,
205
- label="静态一致性 / Static",
206
- info="1=差, 5=优秀"
207
- )
208
- overall = gr.Slider(
209
- minimum=1, maximum=5, step=1, value=3,
210
- label="整体质量 / Overall",
211
- info="1=差, 5=优秀"
212
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  scene_ratings.append({
215
  "method": method_name,
@@ -224,9 +239,29 @@ def create_video_survey_app():
224
  "ratings": scene_ratings
225
  })
226
 
227
- # 提交按钮
228
  gr.Markdown("---")
229
- submit_btn = gr.Button("📤 提交所有评分 / Submit All Ratings", variant="primary", size="lg")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  status_output = gr.Markdown("")
231
 
232
  # 提交函数
@@ -251,9 +286,10 @@ def create_video_survey_app():
251
  # 保存评分
252
  save_ratings(scene_name, ratings, method_mapping)
253
 
254
- return "✅ **所有评分已成功保存!感谢参与!** / All ratings saved successfully! Thank you for participating!"
 
255
  except Exception as e:
256
- return f"❌ **保存失败** / Save failed: {str(e)}"
257
 
258
  # 收集所有评分输入
259
  all_rating_inputs = []
@@ -269,7 +305,7 @@ def create_video_survey_app():
269
  submit_btn.click(
270
  submit_all_ratings,
271
  inputs=all_rating_inputs,
272
- outputs=status_output
273
  )
274
 
275
  return demo
@@ -430,26 +466,10 @@ if __name__ == "__main__":
430
  return stats_text, csv_summary_path, csv_detail_path
431
 
432
  with gr.Tabs():
433
- with gr.Tab("📋 原始数据"):
434
- with gr.Row():
435
- refresh_btn = gr.Button("🔄 刷新数据", variant="primary")
436
-
437
- results_display = gr.Textbox(
438
- label="评分记录",
439
- lines=25,
440
- max_lines=50,
441
- interactive=False
442
- )
443
-
444
- download_file = gr.File(label="📥 下载 JSON 文件", interactive=False)
445
-
446
- refresh_btn.click(
447
- load_results,
448
- outputs=[results_display, download_file]
449
- )
450
-
451
  with gr.Tab("📊 统计分析"):
452
- stats_refresh_btn = gr.Button("🔄 刷新统计", variant="primary")
 
 
453
 
454
  stats_display = gr.Textbox(
455
  label="统计结果",
@@ -461,39 +481,67 @@ if __name__ == "__main__":
461
  with gr.Row():
462
  csv_summary_file = gr.File(label="📥 下载汇总统计 CSV", interactive=False)
463
  csv_detail_file = gr.File(label="📥 下载详细数据 CSV", interactive=False)
 
464
 
465
  gr.Markdown("""
466
  **说明**:
467
  - **汇总统计 CSV**:每个方法的平均分和样本数
468
  - **详细数据 CSV**:所有原始评分记录,可用于进一步分析
 
 
469
  """)
470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
  stats_refresh_btn.click(
472
- get_statistics,
473
- outputs=[stats_display, csv_summary_file, csv_detail_file]
 
 
 
 
 
474
  )
475
 
476
  # 登录验证
477
  def check_password(password):
478
  if password == ADMIN_PASSWORD:
 
 
479
  return (
480
  gr.Column(visible=False), # 隐藏登录框
481
  gr.Column(visible=True), # 显示管理内容
482
  "✅ 登录成功!",
483
- *get_statistics() # 自动加载统计数据
 
 
 
484
  )
485
  else:
486
  return (
487
  gr.Column(visible=True), # 保持登录框显示
488
  gr.Column(visible=False), # 隐藏管理内容
489
  "❌ 密码错误,请重试",
490
- "", None, None
491
  )
492
 
493
  login_btn.click(
494
  check_password,
495
  inputs=[password_input],
496
- outputs=[login_box, admin_content, login_status, stats_display, csv_summary_file, csv_detail_file]
497
  )
498
 
499
  # 使用 TabbedInterface 组合两个界面
 
180
  gr.Markdown(f"## 场景 {scene_idx + 1} / Scene {scene_idx + 1}: `{scene_name}`")
181
 
182
  # 4个视频横向排列
183
+ with gr.Row(equal_height=True):
184
  scene_ratings = []
185
  for i in range(4):
186
  method_name = f"Method {chr(65+i)}"
187
 
188
+ with gr.Column(scale=1, min_width=200):
189
  gr.Markdown(f"### 🎥 {method_name}")
190
 
191
  # 视频
192
  if method_name in videos:
193
+ video = gr.Video(value=videos[method_name], label="", height=250, width=200)
194
  else:
195
+ video = gr.Video(value=None, label="", height=250, width=200, visible=False)
196
 
197
  # 三个评分滑块(垂直排列)
198
+ # 只在第一个场景显示详细说明
199
+ if scene_idx == 0:
200
+ dynamic = gr.Slider(
201
+ minimum=1, maximum=5, step=1, value=3,
202
+ label="动态质量 / Dynamic",
203
+ info="1=差, 5=优秀"
204
+ )
205
+ static = gr.Slider(
206
+ minimum=1, maximum=5, step=1, value=3,
207
+ label="静态一致性 / Static",
208
+ info="1=差, 5=优秀"
209
+ )
210
+ overall = gr.Slider(
211
+ minimum=1, maximum=5, step=1, value=3,
212
+ label="整体质量 / Overall",
213
+ info="1=差, 5=优秀"
214
+ )
215
+ else:
216
+ dynamic = gr.Slider(
217
+ minimum=1, maximum=5, step=1, value=3,
218
+ label="动态 / Dynamic"
219
+ )
220
+ static = gr.Slider(
221
+ minimum=1, maximum=5, step=1, value=3,
222
+ label="静态 / Static"
223
+ )
224
+ overall = gr.Slider(
225
+ minimum=1, maximum=5, step=1, value=3,
226
+ label="整体 / Overall"
227
+ )
228
 
229
  scene_ratings.append({
230
  "method": method_name,
 
239
  "ratings": scene_ratings
240
  })
241
 
242
+ # 提交按钮和状态
243
  gr.Markdown("---")
244
+
245
+ with gr.Column(visible=True) as survey_content:
246
+ submit_btn = gr.Button("📤 提交所有评分 / Submit All Ratings", variant="primary", size="lg")
247
+
248
+ with gr.Column(visible=False) as thank_you_content:
249
+ gr.Markdown("""
250
+ # ✅ 提交成功!/ Submission Successful!
251
+
252
+ ## 🎉 感谢您的参与!/ Thank you for participating!
253
+
254
+ 您的评分已成功保存。您的反馈对我们非常重要!
255
+
256
+ Your ratings have been saved successfully. Your feedback is very important to us!
257
+
258
+ ---
259
+
260
+ 您现在可以关闭此页面。
261
+
262
+ You may now close this page.
263
+ """)
264
+
265
  status_output = gr.Markdown("")
266
 
267
  # 提交函数
 
286
  # 保存评分
287
  save_ratings(scene_name, ratings, method_mapping)
288
 
289
+ # 显示感谢页面
290
+ return gr.Column(visible=False), gr.Column(visible=True), ""
291
  except Exception as e:
292
+ return gr.Column(visible=True), gr.Column(visible=False), f"❌ **保存失败** / Save failed: {str(e)}"
293
 
294
  # 收集所有评分输入
295
  all_rating_inputs = []
 
305
  submit_btn.click(
306
  submit_all_ratings,
307
  inputs=all_rating_inputs,
308
+ outputs=[survey_content, thank_you_content, status_output]
309
  )
310
 
311
  return demo
 
466
  return stats_text, csv_summary_path, csv_detail_path
467
 
468
  with gr.Tabs():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
  with gr.Tab("📊 统计分析"):
470
+ with gr.Row():
471
+ stats_refresh_btn = gr.Button("🔄 刷新统计", variant="primary")
472
+ clear_data_btn = gr.Button("🗑️ 清空所有数据", variant="stop")
473
 
474
  stats_display = gr.Textbox(
475
  label="统计结果",
 
481
  with gr.Row():
482
  csv_summary_file = gr.File(label="📥 下载汇总统计 CSV", interactive=False)
483
  csv_detail_file = gr.File(label="📥 下载详细数据 CSV", interactive=False)
484
+ json_file = gr.File(label="📥 下载原始 JSON", interactive=False)
485
 
486
  gr.Markdown("""
487
  **说明**:
488
  - **汇总统计 CSV**:每个方法的平均分和样本数
489
  - **详细数据 CSV**:所有原始评分记录,可用于进一步分析
490
+ - **原始 JSON**:完整的原始数据
491
+ - **清空数据**:删除所有评分记录(谨慎操作!)
492
  """)
493
 
494
+ # 清空数据函数
495
+ def clear_all_data():
496
+ try:
497
+ if os.path.exists("ratings_data.json"):
498
+ os.remove("ratings_data.json")
499
+ return "✅ 所有数据已清空", None, None, None
500
+ except Exception as e:
501
+ return f"❌ 清空失败: {str(e)}", None, None, None
502
+
503
+ # 获取统计和文件
504
+ def get_stats_and_files():
505
+ stats, csv_summary, csv_detail = get_statistics()
506
+ json_path = "ratings_data.json" if os.path.exists("ratings_data.json") else None
507
+ return stats, csv_summary, csv_detail, json_path
508
+
509
  stats_refresh_btn.click(
510
+ get_stats_and_files,
511
+ outputs=[stats_display, csv_summary_file, csv_detail_file, json_file]
512
+ )
513
+
514
+ clear_data_btn.click(
515
+ clear_all_data,
516
+ outputs=[stats_display, csv_summary_file, csv_detail_file, json_file]
517
  )
518
 
519
  # 登录验证
520
  def check_password(password):
521
  if password == ADMIN_PASSWORD:
522
+ stats, csv_summary, csv_detail = get_statistics()
523
+ json_path = "ratings_data.json" if os.path.exists("ratings_data.json") else None
524
  return (
525
  gr.Column(visible=False), # 隐藏登录框
526
  gr.Column(visible=True), # 显示管理内容
527
  "✅ 登录成功!",
528
+ stats,
529
+ csv_summary,
530
+ csv_detail,
531
+ json_path
532
  )
533
  else:
534
  return (
535
  gr.Column(visible=True), # 保持登录框显示
536
  gr.Column(visible=False), # 隐藏管理内容
537
  "❌ 密码错误,请重试",
538
+ "", None, None, None
539
  )
540
 
541
  login_btn.click(
542
  check_password,
543
  inputs=[password_input],
544
+ outputs=[login_box, admin_content, login_status, stats_display, csv_summary_file, csv_detail_file, json_file]
545
  )
546
 
547
  # 使用 TabbedInterface 组合两个界面