Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -153,1264 +153,33 @@ SAVE_LOCK = threading.Lock()
|
|
| 153 |
|
| 154 |
CUSTOM_CSS = """
|
| 155 |
.gradio-container {
|
| 156 |
-
max-width:
|
| 157 |
-
margin-left: auto !important;
|
| 158 |
-
margin-right: auto !important;
|
| 159 |
-
background:
|
| 160 |
-
radial-gradient(circle at 8% 12%, rgba(102, 124, 255, 0.16) 0%, rgba(102, 124, 255, 0) 28%),
|
| 161 |
-
radial-gradient(circle at 92% 18%, rgba(255, 107, 157, 0.11) 0%, rgba(255, 107, 157, 0) 30%),
|
| 162 |
-
linear-gradient(180deg, #0b1220 0%, #0d1526 52%, #0c1323 100%);
|
| 163 |
-
}
|
| 164 |
-
.title-text h1 {
|
| 165 |
-
text-align: center;
|
| 166 |
-
background: linear-gradient(135deg, #7c5cff 0%, #ff6b9d 100%);
|
| 167 |
-
-webkit-background-clip: text;
|
| 168 |
-
-webkit-text-fill-color: transparent;
|
| 169 |
-
font-size: 2rem;
|
| 170 |
-
font-weight: 760;
|
| 171 |
-
letter-spacing: 0.2px;
|
| 172 |
-
margin: 0 0 8px 0;
|
| 173 |
-
}
|
| 174 |
-
.title-sub {
|
| 175 |
-
text-align: center;
|
| 176 |
-
color: #c4d0f1;
|
| 177 |
-
margin-bottom: 14px;
|
| 178 |
-
}
|
| 179 |
-
#hero {
|
| 180 |
-
border: 1px solid #33456f;
|
| 181 |
-
border-radius: 16px;
|
| 182 |
-
padding: 20px 22px;
|
| 183 |
-
background: linear-gradient(130deg, #121f3f 0%, #1d2f5e 58%, #2b2a63 100%);
|
| 184 |
-
box-shadow: 0 14px 34px rgba(8, 10, 30, 0.42);
|
| 185 |
-
margin-bottom: 14px;
|
| 186 |
-
}
|
| 187 |
-
.hero-badge {
|
| 188 |
-
display: inline-block;
|
| 189 |
-
margin-top: 10px;
|
| 190 |
-
padding: 5px 12px;
|
| 191 |
-
border-radius: 999px;
|
| 192 |
-
border: 1px solid rgba(205, 220, 255, 0.42);
|
| 193 |
-
background: rgba(11, 22, 46, 0.52);
|
| 194 |
-
color: #d9e7ff;
|
| 195 |
-
font-size: 12px;
|
| 196 |
-
font-weight: 600;
|
| 197 |
-
}
|
| 198 |
-
.metric-grid {
|
| 199 |
-
display: grid;
|
| 200 |
-
grid-template-columns: repeat(3, minmax(110px, 1fr));
|
| 201 |
-
gap: 12px;
|
| 202 |
-
margin: 10px 0 16px 0;
|
| 203 |
-
}
|
| 204 |
-
.metric-card {
|
| 205 |
-
border: 1px solid #2f4166;
|
| 206 |
-
border-radius: 12px;
|
| 207 |
-
padding: 12px 14px;
|
| 208 |
-
background: linear-gradient(180deg, #111d33 0%, #111a2d 100%);
|
| 209 |
-
}
|
| 210 |
-
.metric-label {
|
| 211 |
-
color: #9fb0da;
|
| 212 |
-
font-size: 12px;
|
| 213 |
-
margin-bottom: 4px;
|
| 214 |
-
}
|
| 215 |
-
.metric-value {
|
| 216 |
-
color: #e8efff;
|
| 217 |
-
font-size: 16px;
|
| 218 |
-
font-weight: 700;
|
| 219 |
-
}
|
| 220 |
-
.panel {
|
| 221 |
-
border: 1px solid #2b3e64 !important;
|
| 222 |
-
border-radius: 14px !important;
|
| 223 |
-
padding: 14px !important;
|
| 224 |
-
background: linear-gradient(180deg, #111b31 0%, #10192d 100%) !important;
|
| 225 |
-
box-shadow: 0 8px 22px rgba(5, 10, 24, 0.28);
|
| 226 |
-
}
|
| 227 |
-
.section-title {
|
| 228 |
-
margin: 0 0 10px 0;
|
| 229 |
-
font-size: 1.04rem;
|
| 230 |
-
font-weight: 650;
|
| 231 |
-
color: #e2eaff;
|
| 232 |
-
}
|
| 233 |
-
.hint {
|
| 234 |
-
color: #9badd6;
|
| 235 |
-
font-size: 0.9rem;
|
| 236 |
-
}
|
| 237 |
-
.toolbar-btn {
|
| 238 |
-
min-height: 42px !important;
|
| 239 |
-
border-radius: 10px !important;
|
| 240 |
-
}
|
| 241 |
-
.gr-button-primary {
|
| 242 |
-
background: linear-gradient(180deg, #5f85ff 0%, #4a70f0 100%) !important;
|
| 243 |
-
border: 1px solid #90a8ff !important;
|
| 244 |
-
box-shadow: 0 8px 22px rgba(61, 103, 234, 0.35) !important;
|
| 245 |
-
}
|
| 246 |
-
.status-box {
|
| 247 |
-
border: 1px dashed #4a6398;
|
| 248 |
-
border-radius: 10px;
|
| 249 |
-
padding: 9px 11px;
|
| 250 |
-
background: #0c1529;
|
| 251 |
-
}
|
| 252 |
-
.soft-input textarea,
|
| 253 |
-
.soft-input input,
|
| 254 |
-
.soft-input .wrap {
|
| 255 |
-
border-radius: 10px !important;
|
| 256 |
-
}
|
| 257 |
-
.gr-accordion {
|
| 258 |
-
border-radius: 12px !important;
|
| 259 |
-
border-color: #2e426a !important;
|
| 260 |
-
}
|
| 261 |
-
"""
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
def _safe_read_text(path: Path) -> str:
|
| 265 |
-
if not path.exists():
|
| 266 |
-
return ""
|
| 267 |
-
return path.read_text(encoding="utf-8-sig").strip()
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
def load_dataset_index() -> List[Dict[str, Any]]:
|
| 271 |
-
"""扫描输入目录,构建可评测样本列表(每个方法-故事仅保留1个视频)。"""
|
| 272 |
-
stories = {p.stem: _safe_read_text(p) for p in sorted(STORY_DIR.glob("*.txt"))}
|
| 273 |
-
samples: List[Dict[str, Any]] = []
|
| 274 |
-
|
| 275 |
-
if not VIDEO_DIR.exists():
|
| 276 |
-
return samples
|
| 277 |
-
|
| 278 |
-
for method_dir in sorted([d for d in VIDEO_DIR.iterdir() if d.is_dir()]):
|
| 279 |
-
method = method_dir.name
|
| 280 |
-
for story_dir in sorted([d for d in method_dir.iterdir() if d.is_dir()]):
|
| 281 |
-
story_name = story_dir.name
|
| 282 |
-
# 每个方法-故事只评一次:如果有多个视频,默认取排序后第一个
|
| 283 |
-
video_candidates = sorted(story_dir.glob("*.mp4"))
|
| 284 |
-
if not video_candidates:
|
| 285 |
-
continue
|
| 286 |
-
video_path = video_candidates[0]
|
| 287 |
-
sample_id = f"{method}__{story_name}__{video_path.stem}"
|
| 288 |
-
samples.append(
|
| 289 |
-
{
|
| 290 |
-
"sample_id": sample_id,
|
| 291 |
-
"method": method,
|
| 292 |
-
"story_name": story_name,
|
| 293 |
-
"video_name": video_path.name,
|
| 294 |
-
"video_path": str(video_path.resolve()),
|
| 295 |
-
"story_text": stories.get(story_name, ""),
|
| 296 |
-
}
|
| 297 |
-
)
|
| 298 |
-
return samples
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
def load_evaluated_method_story_pairs() -> set:
|
| 302 |
-
"""从结果目录读取已评估的 (method, story_name) 组合。"""
|
| 303 |
-
evaluated = set()
|
| 304 |
-
raw_root = OUTPUT_DIR / "raw_results"
|
| 305 |
-
if not raw_root.exists():
|
| 306 |
-
return evaluated
|
| 307 |
-
|
| 308 |
-
for fp in raw_root.rglob("*.json"):
|
| 309 |
-
try:
|
| 310 |
-
with open(fp, "r", encoding="utf-8-sig") as f:
|
| 311 |
-
data = json.load(f)
|
| 312 |
-
except Exception:
|
| 313 |
-
continue
|
| 314 |
-
sample = data.get("sample", {})
|
| 315 |
-
method = sample.get("method")
|
| 316 |
-
story_name = sample.get("story_name")
|
| 317 |
-
if method and story_name:
|
| 318 |
-
evaluated.add((method, story_name))
|
| 319 |
-
return evaluated
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
def build_pending_samples() -> List[Dict[str, Any]]:
|
| 323 |
-
"""构建待评估样本池,并分配匿名ID。"""
|
| 324 |
-
all_samples = load_dataset_index()
|
| 325 |
-
evaluated_pairs = load_evaluated_method_story_pairs()
|
| 326 |
-
pending = [
|
| 327 |
-
s for s in all_samples
|
| 328 |
-
if (s["method"], s["story_name"]) not in evaluated_pairs
|
| 329 |
-
]
|
| 330 |
-
for i, sample in enumerate(pending, start=1):
|
| 331 |
-
sample["anon_id"] = f"id_{i:03d}"
|
| 332 |
-
return pending
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
def build_data_diagnostics(samples: List[Dict[str, Any]]) -> str:
|
| 336 |
-
return (
|
| 337 |
-
f"**SPACE_MODE**: `{SPACE_MODE}` \n"
|
| 338 |
-
f"**DATA_REPO_ID**: `{DATA_REPO_ID}` \n"
|
| 339 |
-
f"**RESULTS_REPO_ID**: `{RESULTS_REPO_ID}` \n"
|
| 340 |
-
f"**ROOT_DIR**: `{ROOT_DIR}` \n"
|
| 341 |
-
f"**INPUT_DIR exists**: `{INPUT_DIR.exists()}` \n"
|
| 342 |
-
f"**STORY_DIR exists**: `{STORY_DIR.exists()}` \n"
|
| 343 |
-
f"**VIDEO_DIR exists**: `{VIDEO_DIR.exists()}` \n"
|
| 344 |
-
f"**Pending samples**: `{len(samples)}`"
|
| 345 |
-
)
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
def compute_derived(scores: Dict[str, float]) -> Dict[str, float]:
|
| 349 |
-
"""计算 CL / CRh / AVG。"""
|
| 350 |
-
cl = (
|
| 351 |
-
(scores["SF"] + scores["NC"] + scores["VQ"] + scores["CC"] + scores["PLC"]) / 5.0
|
| 352 |
-
+ 0.5 * ((scores["CT"] + scores["AVR"]) / 2.0)
|
| 353 |
-
)
|
| 354 |
-
crh = (
|
| 355 |
-
(scores["V_AQ"] + scores["NP"] + scores["VAC"] + scores["CD"] + scores["OQ"]) / 5.0
|
| 356 |
-
+ 0.5 * ((scores["CT"] + scores["AVR"]) / 2.0)
|
| 357 |
-
)
|
| 358 |
-
avg = sum(scores[k] for k in BASE_METRIC_KEYS) / len(BASE_METRIC_KEYS)
|
| 359 |
-
return {"CL": cl, "CRh": crh, "AVG": avg}
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
def save_single_result(sample: Dict[str, Any], evaluator_id: str, scores: Dict[str, int], reasons: Dict[str, str], summary: str) -> Path:
|
| 363 |
-
"""保存单个问卷结果。"""
|
| 364 |
-
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 365 |
-
result_dir = OUTPUT_DIR / "raw_results" / sample["method"] / sample["story_name"]
|
| 366 |
-
result_dir.mkdir(parents=True, exist_ok=True)
|
| 367 |
-
out_path = result_dir / f"{sample['video_name'].replace('.mp4', '')}_{evaluator_id}_{ts}.json"
|
| 368 |
-
|
| 369 |
-
score_float = {k: float(v) for k, v in scores.items()}
|
| 370 |
-
derived = compute_derived(score_float)
|
| 371 |
-
|
| 372 |
-
payload = {
|
| 373 |
-
"timestamp": datetime.now().isoformat(),
|
| 374 |
-
"evaluator_id": evaluator_id,
|
| 375 |
-
"sample": sample,
|
| 376 |
-
"scores": scores,
|
| 377 |
-
"reasons": reasons,
|
| 378 |
-
"summary": summary,
|
| 379 |
-
"derived": derived,
|
| 380 |
-
}
|
| 381 |
-
with open(out_path, "w", encoding="utf-8") as f:
|
| 382 |
-
json.dump(payload, f, ensure_ascii=False, indent=2)
|
| 383 |
-
return out_path
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
def recompute_method_aggregates() -> Path:
|
| 387 |
-
"""
|
| 388 |
-
统计每个方法各维度均分,并输出 method_aggregates.json。
|
| 389 |
-
同时给出 CL/CRh/AVG 的方法均值。
|
| 390 |
-
"""
|
| 391 |
-
raw_root = OUTPUT_DIR / "raw_results"
|
| 392 |
-
method_scores: Dict[str, Dict[str, List[float]]] = defaultdict(lambda: defaultdict(list))
|
| 393 |
-
method_count: Dict[str, int] = defaultdict(int)
|
| 394 |
-
|
| 395 |
-
if raw_root.exists():
|
| 396 |
-
for fp in raw_root.rglob("*.json"):
|
| 397 |
-
with open(fp, "r", encoding="utf-8-sig") as f:
|
| 398 |
-
data = json.load(f)
|
| 399 |
-
method = data.get("sample", {}).get("method", "UNKNOWN")
|
| 400 |
-
scores = data.get("scores", {})
|
| 401 |
-
if not all(k in scores for k in BASE_METRIC_KEYS):
|
| 402 |
-
continue
|
| 403 |
-
method_count[method] += 1
|
| 404 |
-
for k in BASE_METRIC_KEYS:
|
| 405 |
-
method_scores[method][k].append(float(scores[k]))
|
| 406 |
-
|
| 407 |
-
# 衍生指标也参与方法均值统计
|
| 408 |
-
derived = compute_derived({k: float(scores[k]) for k in BASE_METRIC_KEYS})
|
| 409 |
-
for d_key, d_val in derived.items():
|
| 410 |
-
method_scores[method][d_key].append(float(d_val))
|
| 411 |
-
|
| 412 |
-
agg = {
|
| 413 |
-
"updated_at": datetime.now().isoformat(),
|
| 414 |
-
"metric_keys": BASE_METRIC_KEYS,
|
| 415 |
-
"derived_keys": ["CL", "CRh", "AVG"],
|
| 416 |
-
"methods": {},
|
| 417 |
-
}
|
| 418 |
-
for method in sorted(method_scores.keys()):
|
| 419 |
-
metric_avg = {}
|
| 420 |
-
for key, vals in method_scores[method].items():
|
| 421 |
-
metric_avg[key] = round(sum(vals) / len(vals), 4) if vals else None
|
| 422 |
-
agg["methods"][method] = {
|
| 423 |
-
"num_submissions": method_count[method],
|
| 424 |
-
"avg_scores": metric_avg,
|
| 425 |
-
}
|
| 426 |
-
|
| 427 |
-
out_path = OUTPUT_DIR / "method_aggregates.json"
|
| 428 |
-
with open(out_path, "w", encoding="utf-8") as f:
|
| 429 |
-
json.dump(agg, f, ensure_ascii=False, indent=2)
|
| 430 |
-
return out_path
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
def build_sample_brief(sample: Dict[str, Any], index: int, total: int) -> str:
|
| 434 |
-
story = sample.get("story_text") or "(未找到对应 story 文本,请检查 clip_movie_story 下是否有同名 txt)"
|
| 435 |
-
return (
|
| 436 |
-
f"### 当前匿名样本 {index + 1}/{total}\n"
|
| 437 |
-
f"- **Sample ID**: `{sample['anon_id']}`\n\n"
|
| 438 |
-
f"### Story Description\n{story}"
|
| 439 |
-
)
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
def create_app():
|
| 443 |
-
samples = build_pending_samples()
|
| 444 |
-
sample_map = {s["anon_id"]: s for s in samples}
|
| 445 |
-
|
| 446 |
-
with gr.Blocks(
|
| 447 |
-
title="VideoEval Movie-Level Evaluation",
|
| 448 |
-
css=CUSTOM_CSS,
|
| 449 |
-
theme=gr.themes.Soft(primary_hue="purple", secondary_hue="pink", neutral_hue="slate"),
|
| 450 |
-
) as app:
|
| 451 |
-
gr.Markdown("# VideoEval · Movie-Level Evaluation", elem_classes=["title-text"])
|
| 452 |
-
gr.Markdown("统一电影级评测问卷,支持方法级均分统计(含 CL / CRh / AVG)", elem_classes=["title-sub"])
|
| 453 |
-
|
| 454 |
-
gr.HTML(
|
| 455 |
-
f"""
|
| 456 |
-
<div id="hero">
|
| 457 |
-
<div class="hero-badge">HF Space Ready · Gradio Blocks · Clean Review Flow</div>
|
| 458 |
-
<div class="metric-grid">
|
| 459 |
-
<div class="metric-card">
|
| 460 |
-
<div class="metric-label">Pending Samples</div>
|
| 461 |
-
<div class="metric-value">{len(samples)}</div>
|
| 462 |
-
</div>
|
| 463 |
-
<div class="metric-card">
|
| 464 |
-
<div class="metric-label">Evaluation Scope</div>
|
| 465 |
-
<div class="metric-value">Movie-Level</div>
|
| 466 |
-
</div>
|
| 467 |
-
<div class="metric-card">
|
| 468 |
-
<div class="metric-label">Scoring Standard</div>
|
| 469 |
-
<div class="metric-value">12 Metrics · 1~5</div>
|
| 470 |
-
</div>
|
| 471 |
-
</div>
|
| 472 |
-
</div>
|
| 473 |
-
"""
|
| 474 |
-
)
|
| 475 |
-
gr.Markdown(
|
| 476 |
-
f"<span class='hint'>输入目录:`{INPUT_DIR}` | 输出目录:`{OUTPUT_DIR}`</span>",
|
| 477 |
-
)
|
| 478 |
-
with gr.Accordion("系统诊断信息(展开查看)", open=False):
|
| 479 |
-
gr.Markdown(build_data_diagnostics(samples))
|
| 480 |
-
|
| 481 |
-
current_idx = gr.State(0)
|
| 482 |
-
evaluator_state = gr.State("anonymous")
|
| 483 |
-
|
| 484 |
-
with gr.Row():
|
| 485 |
-
with gr.Column(scale=4, elem_classes=["panel"]):
|
| 486 |
-
gr.Markdown("<div class='section-title'>1) 评测员与样本</div>")
|
| 487 |
-
with gr.Row():
|
| 488 |
-
evaluator_input = gr.Textbox(label="Evaluator ID", value="anonymous", elem_classes=["soft-input"])
|
| 489 |
-
sample_dropdown = gr.Dropdown(
|
| 490 |
-
label="选择评测样本(匿名)",
|
| 491 |
-
choices=[s["anon_id"] for s in samples],
|
| 492 |
-
value=samples[0]["anon_id"] if samples else None,
|
| 493 |
-
interactive=True,
|
| 494 |
-
elem_classes=["soft-input"],
|
| 495 |
-
)
|
| 496 |
-
with gr.Row():
|
| 497 |
-
prev_btn = gr.Button("← Previous", elem_classes=["toolbar-btn"])
|
| 498 |
-
next_btn = gr.Button("Next →", elem_classes=["toolbar-btn"])
|
| 499 |
-
submit_btn = gr.Button("提交当前评分并统计", variant="primary", elem_classes=["toolbar-btn"])
|
| 500 |
-
status = gr.Markdown("<div class='status-box'>等待提交</div>")
|
| 501 |
-
with gr.Column(scale=8, elem_classes=["panel"]):
|
| 502 |
-
gr.Markdown("<div class='section-title'>2) 视频与剧情</div>")
|
| 503 |
-
movie_video = gr.Video(label="Movie Video", value=samples[0]["video_path"] if samples else None, height=460)
|
| 504 |
-
sample_info = gr.Markdown("无可用样本" if not samples else build_sample_brief(samples[0], 0, len(samples)))
|
| 505 |
-
|
| 506 |
-
gr.Markdown("## 3) Movie-Level 指标评分(1-5)")
|
| 507 |
-
gr.Markdown("<span class='hint'>先给分,再填写可选理由。未打分无法提交。</span>")
|
| 508 |
-
|
| 509 |
-
score_widgets: Dict[str, gr.Radio] = {}
|
| 510 |
-
reason_widgets: Dict[str, gr.Textbox] = {}
|
| 511 |
-
metric_groups = {
|
| 512 |
-
"I. 叙事与剧本 (NS)": ["SF", "NC"],
|
| 513 |
-
"II. 视听与技术 (AT)": ["VQ", "CC", "PLC", "V_AQ"],
|
| 514 |
-
"III. 美学与表现力 (AE)": ["CT", "AVR"],
|
| 515 |
-
"IV. 节奏与流动性 (RF)": ["NP", "VAC"],
|
| 516 |
-
"V. 情感与参与度 (EE)": ["CD"],
|
| 517 |
-
"VI. 整体体验 (OE)": ["OQ"],
|
| 518 |
-
}
|
| 519 |
-
criteria_map = {k: (name, desc) for k, name, desc in MOVIE_CRITERIA}
|
| 520 |
-
|
| 521 |
-
for section_title, keys in metric_groups.items():
|
| 522 |
-
with gr.Accordion(section_title, open=True):
|
| 523 |
-
for key in keys:
|
| 524 |
-
name, desc = criteria_map[key]
|
| 525 |
-
with gr.Group(elem_classes=["panel"]):
|
| 526 |
-
gr.Markdown(f"**{key} · {name}**")
|
| 527 |
-
gr.Markdown(f"<span class='hint'>{desc}</span>")
|
| 528 |
-
with gr.Row():
|
| 529 |
-
score_widgets[key] = gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{key} Score", scale=1, elem_classes=["soft-input"])
|
| 530 |
-
reason_widgets[key] = gr.Textbox(label=f"{key} Reason(可选)", lines=2, placeholder="补充评分依据", scale=2, elem_classes=["soft-input"])
|
| 531 |
-
|
| 532 |
-
final_summary = gr.Textbox(label="Final Summary(可选)", lines=4, placeholder="总结该视频的主要优缺点", elem_classes=["soft-input"])
|
| 533 |
-
|
| 534 |
-
def _sync_sample_from_dropdown(anon_id: str) -> Tuple[str, str, int]:
|
| 535 |
-
if not anon_id or anon_id not in sample_map:
|
| 536 |
-
return None, "未找到样本", 0
|
| 537 |
-
idx = next(i for i, s in enumerate(samples) if s["anon_id"] == anon_id)
|
| 538 |
-
sample = samples[idx]
|
| 539 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), idx
|
| 540 |
-
|
| 541 |
-
def _go_prev(idx: int) -> Tuple[str, str, str, int]:
|
| 542 |
-
if not samples:
|
| 543 |
-
return None, "无可用样本", None, 0
|
| 544 |
-
idx = max(0, idx - 1)
|
| 545 |
-
sample = samples[idx]
|
| 546 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), sample["anon_id"], idx
|
| 547 |
-
|
| 548 |
-
def _go_next(idx: int) -> Tuple[str, str, str, int]:
|
| 549 |
-
if not samples:
|
| 550 |
-
return None, "无可用样本", None, 0
|
| 551 |
-
idx = min(len(samples) - 1, idx + 1)
|
| 552 |
-
sample = samples[idx]
|
| 553 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), sample["anon_id"], idx
|
| 554 |
-
|
| 555 |
-
def _submit(evaluator_id: str, anon_id: str, summary: str, *score_reason_vals):
|
| 556 |
-
if not samples:
|
| 557 |
-
return "❌ 没有可提交样本。"
|
| 558 |
-
if not anon_id or anon_id not in sample_map:
|
| 559 |
-
return "❌ 请先选择样本。"
|
| 560 |
-
sample = sample_map[anon_id]
|
| 561 |
-
evaluator_id = (evaluator_id or "anonymous").strip() or "anonymous"
|
| 562 |
-
|
| 563 |
-
# 防重复:方法-故事只允许评估一次
|
| 564 |
-
evaluated_pairs = load_evaluated_method_story_pairs()
|
| 565 |
-
if (sample["method"], sample["story_name"]) in evaluated_pairs:
|
| 566 |
-
return "⚠️ 该方法-故事已经被评估过一次,请选择其他匿名样本。"
|
| 567 |
-
|
| 568 |
-
scores: Dict[str, int] = {}
|
| 569 |
-
reasons: Dict[str, str] = {}
|
| 570 |
-
for i, key in enumerate(BASE_METRIC_KEYS):
|
| 571 |
-
score = score_reason_vals[i * 2]
|
| 572 |
-
reason = score_reason_vals[i * 2 + 1]
|
| 573 |
-
if score is None:
|
| 574 |
-
return f"❌ 请为 `{key}` 打分。"
|
| 575 |
-
scores[key] = int(score)
|
| 576 |
-
reasons[key] = (reason or "").strip()
|
| 577 |
-
|
| 578 |
-
with SAVE_LOCK:
|
| 579 |
-
single_path = save_single_result(sample, evaluator_id, scores, reasons, summary or "")
|
| 580 |
-
agg_path = recompute_method_aggregates()
|
| 581 |
-
|
| 582 |
-
return f"✅ 已保存: `{single_path}`\n\n✅ 已更新方法统计: `{agg_path}`"
|
| 583 |
-
|
| 584 |
-
sample_dropdown.change(
|
| 585 |
-
_sync_sample_from_dropdown,
|
| 586 |
-
inputs=[sample_dropdown],
|
| 587 |
-
outputs=[movie_video, sample_info, current_idx],
|
| 588 |
-
)
|
| 589 |
-
prev_btn.click(_go_prev, inputs=[current_idx], outputs=[movie_video, sample_info, sample_dropdown, current_idx])
|
| 590 |
-
next_btn.click(_go_next, inputs=[current_idx], outputs=[movie_video, sample_info, sample_dropdown, current_idx])
|
| 591 |
-
|
| 592 |
-
submit_inputs = [evaluator_input, sample_dropdown, final_summary]
|
| 593 |
-
for key in BASE_METRIC_KEYS:
|
| 594 |
-
submit_inputs.append(score_widgets[key])
|
| 595 |
-
submit_inputs.append(reason_widgets[key])
|
| 596 |
-
submit_btn.click(_submit, inputs=submit_inputs, outputs=[status])
|
| 597 |
-
|
| 598 |
-
app.load(lambda x: x, inputs=[evaluator_input], outputs=[evaluator_state])
|
| 599 |
-
|
| 600 |
-
return app
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
demo = create_app()
|
| 604 |
-
|
| 605 |
-
if __name__ == "__main__":
|
| 606 |
-
allowed_paths = [str(INPUT_DIR.resolve())] if INPUT_DIR.exists() else None
|
| 607 |
-
demo.launch(
|
| 608 |
-
server_name="0.0.0.0",
|
| 609 |
-
server_port=7860,
|
| 610 |
-
share=False,
|
| 611 |
-
show_error=True,
|
| 612 |
-
allowed_paths=allowed_paths,
|
| 613 |
-
)
|
| 614 |
-
"""
|
| 615 |
-
VideoEval Movie-Level 问卷应用(Hugging Face Spaces)
|
| 616 |
-
仅保留 Movie-Level 评测,并支持方法级别统计输出。
|
| 617 |
-
"""
|
| 618 |
-
|
| 619 |
-
import json
|
| 620 |
-
import os
|
| 621 |
-
import threading
|
| 622 |
-
from collections import defaultdict
|
| 623 |
-
from datetime import datetime
|
| 624 |
-
from pathlib import Path
|
| 625 |
-
from typing import Any, Dict, List, Optional, Tuple
|
| 626 |
-
|
| 627 |
-
import gradio as gr
|
| 628 |
-
from huggingface_hub import CommitScheduler, snapshot_download
|
| 629 |
-
|
| 630 |
-
# 路径配置(按用户要求)
|
| 631 |
-
# Spaces 推荐优先读取当前 Space 仓库内文件(app.py 同级)
|
| 632 |
-
APP_DIR = Path(__file__).resolve().parent
|
| 633 |
-
LOCAL_INPUT_DIR = APP_DIR / "user_study_input"
|
| 634 |
-
LOCAL_OUTPUT_DIR = APP_DIR / "user_study_results"
|
| 635 |
-
DATA_INPUT_DIR = Path("/data/user_study_input")
|
| 636 |
-
DATA_OUTPUT_DIR = Path("/data/user_study_results")
|
| 637 |
-
DATA_REPO_ID = os.environ.get("DATA_REPO_ID", "MemDirector/user_study_input")
|
| 638 |
-
RESULTS_REPO_ID = os.environ.get("RESULTS_REPO_ID", "MemDirector/user_study_results")
|
| 639 |
-
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 640 |
-
SPACE_MODE = os.environ.get("SPACE_MODE", "repo_first") # repo_first / data_first / hub_only
|
| 641 |
-
|
| 642 |
-
ROOT_DIR = APP_DIR
|
| 643 |
-
INPUT_DIR = LOCAL_INPUT_DIR
|
| 644 |
-
OUTPUT_DIR = LOCAL_OUTPUT_DIR
|
| 645 |
-
STORY_DIR = INPUT_DIR / "clip_movie_story"
|
| 646 |
-
VIDEO_DIR = INPUT_DIR / "video"
|
| 647 |
-
|
| 648 |
-
Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)
|
| 649 |
-
scheduler: Optional[CommitScheduler] = None
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
def _set_paths(input_dir: Path, output_dir: Path) -> None:
|
| 653 |
-
global INPUT_DIR, OUTPUT_DIR, STORY_DIR, VIDEO_DIR, ROOT_DIR
|
| 654 |
-
INPUT_DIR = input_dir
|
| 655 |
-
OUTPUT_DIR = output_dir
|
| 656 |
-
STORY_DIR = INPUT_DIR / "clip_movie_story"
|
| 657 |
-
VIDEO_DIR = INPUT_DIR / "video"
|
| 658 |
-
ROOT_DIR = INPUT_DIR.parent
|
| 659 |
-
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
def _try_use_local_repo_layout() -> bool:
|
| 663 |
-
# Space 仓库内自带 user_study_input 时,直接读取(最符合“已放上去直接跑”)
|
| 664 |
-
if LOCAL_INPUT_DIR.exists():
|
| 665 |
-
_set_paths(LOCAL_INPUT_DIR, LOCAL_OUTPUT_DIR)
|
| 666 |
-
return True
|
| 667 |
-
return False
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
def _try_use_data_volume_layout() -> bool:
|
| 671 |
-
# 如果使用 /data 持久卷,则可放在 /data/user_study_input
|
| 672 |
-
if DATA_INPUT_DIR.exists():
|
| 673 |
-
_set_paths(DATA_INPUT_DIR, DATA_OUTPUT_DIR)
|
| 674 |
-
return True
|
| 675 |
-
return False
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
def _try_download_from_hub() -> bool:
|
| 679 |
-
# 最后兜底:从 dataset repo 下载
|
| 680 |
-
if not DATA_REPO_ID:
|
| 681 |
-
return False
|
| 682 |
-
hub_root = APP_DIR / ".hf_space_cache"
|
| 683 |
-
try:
|
| 684 |
-
snapshot_download(
|
| 685 |
-
repo_id=DATA_REPO_ID,
|
| 686 |
-
repo_type="dataset",
|
| 687 |
-
local_dir=str(hub_root),
|
| 688 |
-
token=HF_TOKEN,
|
| 689 |
-
allow_patterns=[
|
| 690 |
-
"clip_movie_story/**",
|
| 691 |
-
"video/**",
|
| 692 |
-
"user_study_input/**",
|
| 693 |
-
"user_study_results/**",
|
| 694 |
-
],
|
| 695 |
-
)
|
| 696 |
-
except Exception as e:
|
| 697 |
-
print(f"[INIT] snapshot_download failed: {e}")
|
| 698 |
-
return False
|
| 699 |
-
|
| 700 |
-
# 兼容两种 dataset 结构:
|
| 701 |
-
# A) 仓库根目录直接是 clip_movie_story/ 与 video/
|
| 702 |
-
# B) 仓库里有 user_study_input/ 子目录
|
| 703 |
-
if (hub_root / "clip_movie_story").exists() and (hub_root / "video").exists():
|
| 704 |
-
hub_input = hub_root
|
| 705 |
-
elif (hub_root / "user_study_input").exists():
|
| 706 |
-
hub_input = hub_root / "user_study_input"
|
| 707 |
-
else:
|
| 708 |
-
return False
|
| 709 |
-
|
| 710 |
-
hub_output = hub_root / "user_study_results"
|
| 711 |
-
_set_paths(hub_input, hub_output)
|
| 712 |
-
return True
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
def init_space_storage() -> None:
|
| 716 |
-
"""
|
| 717 |
-
Hugging Face Spaces 规范:
|
| 718 |
-
- 从 dataset repo 拉取 user_study_input 与 user_study_results 到本地 ROOT_DIR
|
| 719 |
-
- 使用 CommitScheduler 持续回写 user_study_results
|
| 720 |
-
"""
|
| 721 |
-
global scheduler
|
| 722 |
-
|
| 723 |
-
if SPACE_MODE == "hub_only":
|
| 724 |
-
ok = _try_download_from_hub()
|
| 725 |
-
elif SPACE_MODE == "data_first":
|
| 726 |
-
ok = _try_use_data_volume_layout() or _try_use_local_repo_layout() or _try_download_from_hub()
|
| 727 |
-
else:
|
| 728 |
-
ok = _try_use_local_repo_layout() or _try_use_data_volume_layout() or _try_download_from_hub()
|
| 729 |
-
print(f"[INIT] storage init mode={SPACE_MODE}, success={ok}, input={INPUT_DIR}, output={OUTPUT_DIR}")
|
| 730 |
-
|
| 731 |
-
if RESULTS_REPO_ID:
|
| 732 |
-
try:
|
| 733 |
-
scheduler = CommitScheduler(
|
| 734 |
-
repo_id=RESULTS_REPO_ID,
|
| 735 |
-
repo_type="dataset",
|
| 736 |
-
folder_path=str(OUTPUT_DIR),
|
| 737 |
-
path_in_repo="user_study_results",
|
| 738 |
-
every=3,
|
| 739 |
-
token=HF_TOKEN,
|
| 740 |
-
)
|
| 741 |
-
print(f"[INIT] CommitScheduler enabled: {RESULTS_REPO_ID}")
|
| 742 |
-
except Exception as e:
|
| 743 |
-
print(f"[INIT] CommitScheduler init failed: {e}")
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
init_space_storage()
|
| 747 |
-
|
| 748 |
-
# Movie-Level 指标定义
|
| 749 |
-
MOVIE_CRITERIA: List[Tuple[str, str, str]] = [
|
| 750 |
-
("SF", "Script Faithfulness (剧本忠实度)", "生成的视觉内容与原始剧本描述的吻合程度。"),
|
| 751 |
-
("NC", "Narrative Coherence (叙事连贯性)", "镜头间情节发展的逻辑性,确保故事表达清晰、不破碎。"),
|
| 752 |
-
("VQ", "Visual Quality (视觉质量)", "画面的清晰度、噪点控制、光影效果等基础图像质量。"),
|
| 753 |
-
("CC", "Character Consistency (角色一致性)", "同一角色在不同镜头、不同角度下的外貌、服装及特征的稳定性。"),
|
| 754 |
-
("PLC", "Physical Law Compliance (物理规律符合度)", "运动、重力、碰撞等是否符合现实物理逻辑,是否存在严重 AI 幻觉。"),
|
| 755 |
-
("V_AQ", "Voice/Audio Quality (语音/音频质量)", "配音、背景音乐和音效的清晰度、自然度及技术品质。"),
|
| 756 |
-
("CT", "Cinematic Techniques (电影技巧)", "镜头运动、景深控制及构图的专业性。"),
|
| 757 |
-
("AVR", "Audio-Visual Richness (视听丰富度)", "画面细节精细度以及音频层次(音效、氛围音)的丰富程度。"),
|
| 758 |
-
("NP", "Narrative Pacing (叙事节奏)", "镜头剪辑长短切换是否契合故事情节张力需求。"),
|
| 759 |
-
("VAC", "Video-Audio Coordination (视听协调性)", "画面动作与音效、音乐卡点的同步率。"),
|
| 760 |
-
("CD", "Compelling Degree (引人入胜程度)", "吸引注意力并引发情感共鸣或沉浸感的能力。"),
|
| 761 |
-
("OQ", "Overall Quality (整体质量)", "对生成视频作为“电影作品”的综合观感评分。"),
|
| 762 |
-
]
|
| 763 |
-
|
| 764 |
-
BASE_METRIC_KEYS = [k for k, _, _ in MOVIE_CRITERIA]
|
| 765 |
-
SAVE_LOCK = threading.Lock()
|
| 766 |
-
|
| 767 |
-
CUSTOM_CSS = """
|
| 768 |
-
.gradio-container {
|
| 769 |
-
max-width: 1300px !important;
|
| 770 |
-
}
|
| 771 |
-
#hero {
|
| 772 |
-
border: 1px solid #2b2f3a;
|
| 773 |
-
border-radius: 16px;
|
| 774 |
-
padding: 20px 22px;
|
| 775 |
-
background: linear-gradient(135deg, #121826 0%, #1d2540 55%, #2a1f45 100%);
|
| 776 |
-
margin-bottom: 14px;
|
| 777 |
-
}
|
| 778 |
-
#hero h1 {
|
| 779 |
-
margin: 0 0 8px 0;
|
| 780 |
-
font-size: 1.9rem;
|
| 781 |
-
}
|
| 782 |
-
#hero p {
|
| 783 |
-
margin: 0;
|
| 784 |
-
color: #d0d8f0;
|
| 785 |
-
}
|
| 786 |
-
.panel {
|
| 787 |
-
border: 1px solid #2e3445 !important;
|
| 788 |
-
border-radius: 14px !important;
|
| 789 |
-
padding: 14px !important;
|
| 790 |
-
background: #111522 !important;
|
| 791 |
-
}
|
| 792 |
-
.hint {
|
| 793 |
-
color: #9aa7c9;
|
| 794 |
-
font-size: 0.9rem;
|
| 795 |
-
}
|
| 796 |
-
"""
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
def _safe_read_text(path: Path) -> str:
|
| 800 |
-
if not path.exists():
|
| 801 |
-
return ""
|
| 802 |
-
return path.read_text(encoding="utf-8-sig").strip()
|
| 803 |
-
|
| 804 |
-
|
| 805 |
-
def load_dataset_index() -> List[Dict[str, Any]]:
|
| 806 |
-
"""扫描输入目录,构建可评测样本列表(每个方法-故事仅保留1个视频)。"""
|
| 807 |
-
stories = {p.stem: _safe_read_text(p) for p in sorted(STORY_DIR.glob("*.txt"))}
|
| 808 |
-
samples: List[Dict[str, Any]] = []
|
| 809 |
-
|
| 810 |
-
if not VIDEO_DIR.exists():
|
| 811 |
-
return samples
|
| 812 |
-
|
| 813 |
-
for method_dir in sorted([d for d in VIDEO_DIR.iterdir() if d.is_dir()]):
|
| 814 |
-
method = method_dir.name
|
| 815 |
-
for story_dir in sorted([d for d in method_dir.iterdir() if d.is_dir()]):
|
| 816 |
-
story_name = story_dir.name
|
| 817 |
-
# 每个方法-故事只评一次:如果有多个视频,默认取排序后第一个
|
| 818 |
-
video_candidates = sorted(story_dir.glob("*.mp4"))
|
| 819 |
-
if not video_candidates:
|
| 820 |
-
continue
|
| 821 |
-
video_path = video_candidates[0]
|
| 822 |
-
sample_id = f"{method}__{story_name}__{video_path.stem}"
|
| 823 |
-
samples.append(
|
| 824 |
-
{
|
| 825 |
-
"sample_id": sample_id,
|
| 826 |
-
"method": method,
|
| 827 |
-
"story_name": story_name,
|
| 828 |
-
"video_name": video_path.name,
|
| 829 |
-
"video_path": str(video_path.resolve()),
|
| 830 |
-
"story_text": stories.get(story_name, ""),
|
| 831 |
-
}
|
| 832 |
-
)
|
| 833 |
-
return samples
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
def load_evaluated_method_story_pairs() -> set:
|
| 837 |
-
"""从结果目录读取已评估的 (method, story_name) 组合。"""
|
| 838 |
-
evaluated = set()
|
| 839 |
-
raw_root = OUTPUT_DIR / "raw_results"
|
| 840 |
-
if not raw_root.exists():
|
| 841 |
-
return evaluated
|
| 842 |
-
|
| 843 |
-
for fp in raw_root.rglob("*.json"):
|
| 844 |
-
try:
|
| 845 |
-
with open(fp, "r", encoding="utf-8-sig") as f:
|
| 846 |
-
data = json.load(f)
|
| 847 |
-
except Exception:
|
| 848 |
-
continue
|
| 849 |
-
sample = data.get("sample", {})
|
| 850 |
-
method = sample.get("method")
|
| 851 |
-
story_name = sample.get("story_name")
|
| 852 |
-
if method and story_name:
|
| 853 |
-
evaluated.add((method, story_name))
|
| 854 |
-
return evaluated
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
def build_pending_samples() -> List[Dict[str, Any]]:
|
| 858 |
-
"""构建待评估样本池,并分配匿名ID。"""
|
| 859 |
-
all_samples = load_dataset_index()
|
| 860 |
-
evaluated_pairs = load_evaluated_method_story_pairs()
|
| 861 |
-
pending = [
|
| 862 |
-
s for s in all_samples
|
| 863 |
-
if (s["method"], s["story_name"]) not in evaluated_pairs
|
| 864 |
-
]
|
| 865 |
-
for i, sample in enumerate(pending, start=1):
|
| 866 |
-
sample["anon_id"] = f"id_{i:03d}"
|
| 867 |
-
return pending
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
def build_data_diagnostics(samples: List[Dict[str, Any]]) -> str:
|
| 871 |
-
return (
|
| 872 |
-
f"**SPACE_MODE**: `{SPACE_MODE}` \n"
|
| 873 |
-
f"**DATA_REPO_ID**: `{DATA_REPO_ID}` \n"
|
| 874 |
-
f"**RESULTS_REPO_ID**: `{RESULTS_REPO_ID}` \n"
|
| 875 |
-
f"**ROOT_DIR**: `{ROOT_DIR}` \n"
|
| 876 |
-
f"**INPUT_DIR exists**: `{INPUT_DIR.exists()}` \n"
|
| 877 |
-
f"**STORY_DIR exists**: `{STORY_DIR.exists()}` \n"
|
| 878 |
-
f"**VIDEO_DIR exists**: `{VIDEO_DIR.exists()}` \n"
|
| 879 |
-
f"**Pending samples**: `{len(samples)}`"
|
| 880 |
-
)
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
def compute_derived(scores: Dict[str, float]) -> Dict[str, float]:
|
| 884 |
-
"""计算 CL / CRh / AVG。"""
|
| 885 |
-
cl = (
|
| 886 |
-
(scores["SF"] + scores["NC"] + scores["VQ"] + scores["CC"] + scores["PLC"]) / 5.0
|
| 887 |
-
+ 0.5 * ((scores["CT"] + scores["AVR"]) / 2.0)
|
| 888 |
-
)
|
| 889 |
-
crh = (
|
| 890 |
-
(scores["V_AQ"] + scores["NP"] + scores["VAC"] + scores["CD"] + scores["OQ"]) / 5.0
|
| 891 |
-
+ 0.5 * ((scores["CT"] + scores["AVR"]) / 2.0)
|
| 892 |
-
)
|
| 893 |
-
avg = sum(scores[k] for k in BASE_METRIC_KEYS) / len(BASE_METRIC_KEYS)
|
| 894 |
-
return {"CL": cl, "CRh": crh, "AVG": avg}
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
def save_single_result(sample: Dict[str, Any], evaluator_id: str, scores: Dict[str, int], reasons: Dict[str, str], summary: str) -> Path:
|
| 898 |
-
"""保存单个问卷结果。"""
|
| 899 |
-
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 900 |
-
result_dir = OUTPUT_DIR / "raw_results" / sample["method"] / sample["story_name"]
|
| 901 |
-
result_dir.mkdir(parents=True, exist_ok=True)
|
| 902 |
-
out_path = result_dir / f"{sample['video_name'].replace('.mp4', '')}_{evaluator_id}_{ts}.json"
|
| 903 |
-
|
| 904 |
-
score_float = {k: float(v) for k, v in scores.items()}
|
| 905 |
-
derived = compute_derived(score_float)
|
| 906 |
-
|
| 907 |
-
payload = {
|
| 908 |
-
"timestamp": datetime.now().isoformat(),
|
| 909 |
-
"evaluator_id": evaluator_id,
|
| 910 |
-
"sample": sample,
|
| 911 |
-
"scores": scores,
|
| 912 |
-
"reasons": reasons,
|
| 913 |
-
"summary": summary,
|
| 914 |
-
"derived": derived,
|
| 915 |
-
}
|
| 916 |
-
with open(out_path, "w", encoding="utf-8") as f:
|
| 917 |
-
json.dump(payload, f, ensure_ascii=False, indent=2)
|
| 918 |
-
return out_path
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
def recompute_method_aggregates() -> Path:
|
| 922 |
-
"""
|
| 923 |
-
统计每个方法各维度均分,并输出 method_aggregates.json。
|
| 924 |
-
同时给出 CL/CRh/AVG 的方法均值。
|
| 925 |
-
"""
|
| 926 |
-
raw_root = OUTPUT_DIR / "raw_results"
|
| 927 |
-
method_scores: Dict[str, Dict[str, List[float]]] = defaultdict(lambda: defaultdict(list))
|
| 928 |
-
method_count: Dict[str, int] = defaultdict(int)
|
| 929 |
-
|
| 930 |
-
if raw_root.exists():
|
| 931 |
-
for fp in raw_root.rglob("*.json"):
|
| 932 |
-
with open(fp, "r", encoding="utf-8-sig") as f:
|
| 933 |
-
data = json.load(f)
|
| 934 |
-
method = data.get("sample", {}).get("method", "UNKNOWN")
|
| 935 |
-
scores = data.get("scores", {})
|
| 936 |
-
if not all(k in scores for k in BASE_METRIC_KEYS):
|
| 937 |
-
continue
|
| 938 |
-
method_count[method] += 1
|
| 939 |
-
for k in BASE_METRIC_KEYS:
|
| 940 |
-
method_scores[method][k].append(float(scores[k]))
|
| 941 |
-
|
| 942 |
-
# 衍生指标也参与方法均值统计
|
| 943 |
-
derived = compute_derived({k: float(scores[k]) for k in BASE_METRIC_KEYS})
|
| 944 |
-
for d_key, d_val in derived.items():
|
| 945 |
-
method_scores[method][d_key].append(float(d_val))
|
| 946 |
-
|
| 947 |
-
agg = {
|
| 948 |
-
"updated_at": datetime.now().isoformat(),
|
| 949 |
-
"metric_keys": BASE_METRIC_KEYS,
|
| 950 |
-
"derived_keys": ["CL", "CRh", "AVG"],
|
| 951 |
-
"methods": {},
|
| 952 |
-
}
|
| 953 |
-
for method in sorted(method_scores.keys()):
|
| 954 |
-
metric_avg = {}
|
| 955 |
-
for key, vals in method_scores[method].items():
|
| 956 |
-
metric_avg[key] = round(sum(vals) / len(vals), 4) if vals else None
|
| 957 |
-
agg["methods"][method] = {
|
| 958 |
-
"num_submissions": method_count[method],
|
| 959 |
-
"avg_scores": metric_avg,
|
| 960 |
-
}
|
| 961 |
-
|
| 962 |
-
out_path = OUTPUT_DIR / "method_aggregates.json"
|
| 963 |
-
with open(out_path, "w", encoding="utf-8") as f:
|
| 964 |
-
json.dump(agg, f, ensure_ascii=False, indent=2)
|
| 965 |
-
return out_path
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
def build_sample_brief(sample: Dict[str, Any], index: int, total: int) -> str:
|
| 969 |
-
story = sample.get("story_text") or "(未找到对应 story 文本,请检查 clip_movie_story 下是否有同名 txt)"
|
| 970 |
-
return (
|
| 971 |
-
f"### 当前匿名样本 {index + 1}/{total}\n"
|
| 972 |
-
f"- **Sample ID**: `{sample['anon_id']}`\n\n"
|
| 973 |
-
f"### Story Description\n{story}"
|
| 974 |
-
)
|
| 975 |
-
|
| 976 |
-
|
| 977 |
-
def create_app():
|
| 978 |
-
samples = build_pending_samples()
|
| 979 |
-
sample_map = {s["anon_id"]: s for s in samples}
|
| 980 |
-
|
| 981 |
-
with gr.Blocks(
|
| 982 |
-
title="VideoEval Movie-Level Evaluation",
|
| 983 |
-
css=CUSTOM_CSS,
|
| 984 |
-
theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue", neutral_hue="slate"),
|
| 985 |
-
) as app:
|
| 986 |
-
gr.HTML(
|
| 987 |
-
"""
|
| 988 |
-
<div id="hero">
|
| 989 |
-
<h1>VideoEval · Movie-Level Evaluation</h1>
|
| 990 |
-
<p>统一电影级评测问卷,支持方法级均分统计(含 CL / CRh / AVG)</p>
|
| 991 |
-
</div>
|
| 992 |
-
"""
|
| 993 |
-
)
|
| 994 |
-
gr.Markdown(
|
| 995 |
-
f"<span class='hint'>输入目录:`{INPUT_DIR}` | 输出目录:`{OUTPUT_DIR}`</span>",
|
| 996 |
-
)
|
| 997 |
-
gr.Markdown(build_data_diagnostics(samples))
|
| 998 |
-
|
| 999 |
-
current_idx = gr.State(0)
|
| 1000 |
-
evaluator_state = gr.State("anonymous")
|
| 1001 |
-
|
| 1002 |
-
with gr.Row():
|
| 1003 |
-
with gr.Column(scale=5, elem_classes=["panel"]):
|
| 1004 |
-
gr.Markdown("### 1) 评测员与样本")
|
| 1005 |
-
with gr.Row():
|
| 1006 |
-
evaluator_input = gr.Textbox(label="Evaluator ID", value="anonymous")
|
| 1007 |
-
sample_dropdown = gr.Dropdown(
|
| 1008 |
-
label="选择评测样本(匿名)",
|
| 1009 |
-
choices=[s["anon_id"] for s in samples],
|
| 1010 |
-
value=samples[0]["anon_id"] if samples else None,
|
| 1011 |
-
interactive=True,
|
| 1012 |
-
)
|
| 1013 |
-
with gr.Row():
|
| 1014 |
-
prev_btn = gr.Button("← Previous")
|
| 1015 |
-
next_btn = gr.Button("Next →")
|
| 1016 |
-
submit_btn = gr.Button("提交当前评分并统计", variant="primary")
|
| 1017 |
-
status = gr.Markdown("")
|
| 1018 |
-
with gr.Column(scale=7, elem_classes=["panel"]):
|
| 1019 |
-
gr.Markdown("### 2) 视频与剧情")
|
| 1020 |
-
movie_video = gr.Video(label="Movie Video", value=samples[0]["video_path"] if samples else None, height=460)
|
| 1021 |
-
sample_info = gr.Markdown("无可用样本" if not samples else build_sample_brief(samples[0], 0, len(samples)))
|
| 1022 |
-
|
| 1023 |
-
gr.Markdown("## 3) Movie-Level 指标评分(1-5)")
|
| 1024 |
-
gr.Markdown("<span class='hint'>先给分,再填写可选理由。未打分无法提交。</span>")
|
| 1025 |
-
|
| 1026 |
-
score_widgets: Dict[str, gr.Radio] = {}
|
| 1027 |
-
reason_widgets: Dict[str, gr.Textbox] = {}
|
| 1028 |
-
metric_groups = {
|
| 1029 |
-
"I. 叙事与剧本 (NS)": ["SF", "NC"],
|
| 1030 |
-
"II. 视听与技术 (AT)": ["VQ", "CC", "PLC", "V_AQ"],
|
| 1031 |
-
"III. 美学与表现力 (AE)": ["CT", "AVR"],
|
| 1032 |
-
"IV. 节奏与流动性 (RF)": ["NP", "VAC"],
|
| 1033 |
-
"V. 情感与参与度 (EE)": ["CD"],
|
| 1034 |
-
"VI. 整体体验 (OE)": ["OQ"],
|
| 1035 |
-
}
|
| 1036 |
-
criteria_map = {k: (name, desc) for k, name, desc in MOVIE_CRITERIA}
|
| 1037 |
-
|
| 1038 |
-
for section_title, keys in metric_groups.items():
|
| 1039 |
-
with gr.Accordion(section_title, open=True):
|
| 1040 |
-
for key in keys:
|
| 1041 |
-
name, desc = criteria_map[key]
|
| 1042 |
-
with gr.Group(elem_classes=["panel"]):
|
| 1043 |
-
gr.Markdown(f"**{key} · {name}**")
|
| 1044 |
-
gr.Markdown(f"<span class='hint'>{desc}</span>")
|
| 1045 |
-
with gr.Row():
|
| 1046 |
-
score_widgets[key] = gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{key} Score", scale=1)
|
| 1047 |
-
reason_widgets[key] = gr.Textbox(label=f"{key} Reason(可选)", lines=2, placeholder="补充评分依据", scale=2)
|
| 1048 |
-
|
| 1049 |
-
final_summary = gr.Textbox(label="Final Summary(可选)", lines=4, placeholder="总结该视频的主要优缺点")
|
| 1050 |
-
|
| 1051 |
-
def _sync_sample_from_dropdown(anon_id: str) -> Tuple[str, str, int]:
|
| 1052 |
-
if not anon_id or anon_id not in sample_map:
|
| 1053 |
-
return None, "未找到样本", 0
|
| 1054 |
-
idx = next(i for i, s in enumerate(samples) if s["anon_id"] == anon_id)
|
| 1055 |
-
sample = samples[idx]
|
| 1056 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), idx
|
| 1057 |
-
|
| 1058 |
-
def _go_prev(idx: int) -> Tuple[str, str, str, int]:
|
| 1059 |
-
if not samples:
|
| 1060 |
-
return None, "无可用样本", None, 0
|
| 1061 |
-
idx = max(0, idx - 1)
|
| 1062 |
-
sample = samples[idx]
|
| 1063 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), sample["anon_id"], idx
|
| 1064 |
-
|
| 1065 |
-
def _go_next(idx: int) -> Tuple[str, str, str, int]:
|
| 1066 |
-
if not samples:
|
| 1067 |
-
return None, "无可用样本", None, 0
|
| 1068 |
-
idx = min(len(samples) - 1, idx + 1)
|
| 1069 |
-
sample = samples[idx]
|
| 1070 |
-
return sample["video_path"], build_sample_brief(sample, idx, len(samples)), sample["anon_id"], idx
|
| 1071 |
-
|
| 1072 |
-
def _submit(evaluator_id: str, anon_id: str, summary: str, *score_reason_vals):
|
| 1073 |
-
if not samples:
|
| 1074 |
-
return "❌ 没有可提交样本。"
|
| 1075 |
-
if not anon_id or anon_id not in sample_map:
|
| 1076 |
-
return "❌ 请先选择样本。"
|
| 1077 |
-
sample = sample_map[anon_id]
|
| 1078 |
-
evaluator_id = (evaluator_id or "anonymous").strip() or "anonymous"
|
| 1079 |
-
|
| 1080 |
-
# 防重复:方法-故事只允许评估一次
|
| 1081 |
-
evaluated_pairs = load_evaluated_method_story_pairs()
|
| 1082 |
-
if (sample["method"], sample["story_name"]) in evaluated_pairs:
|
| 1083 |
-
return "⚠️ 该方法-故事已经被评估过一次,请选择其他匿名样本。"
|
| 1084 |
-
|
| 1085 |
-
scores: Dict[str, int] = {}
|
| 1086 |
-
reasons: Dict[str, str] = {}
|
| 1087 |
-
for i, key in enumerate(BASE_METRIC_KEYS):
|
| 1088 |
-
score = score_reason_vals[i * 2]
|
| 1089 |
-
reason = score_reason_vals[i * 2 + 1]
|
| 1090 |
-
if score is None:
|
| 1091 |
-
return f"❌ 请为 `{key}` 打分。"
|
| 1092 |
-
scores[key] = int(score)
|
| 1093 |
-
reasons[key] = (reason or "").strip()
|
| 1094 |
-
|
| 1095 |
-
with SAVE_LOCK:
|
| 1096 |
-
single_path = save_single_result(sample, evaluator_id, scores, reasons, summary or "")
|
| 1097 |
-
agg_path = recompute_method_aggregates()
|
| 1098 |
-
|
| 1099 |
-
return f"✅ 已保存: `{single_path}`\n\n✅ 已更新方法统计: `{agg_path}`"
|
| 1100 |
-
|
| 1101 |
-
sample_dropdown.change(
|
| 1102 |
-
_sync_sample_from_dropdown,
|
| 1103 |
-
inputs=[sample_dropdown],
|
| 1104 |
-
outputs=[movie_video, sample_info, current_idx],
|
| 1105 |
-
)
|
| 1106 |
-
prev_btn.click(_go_prev, inputs=[current_idx], outputs=[movie_video, sample_info, sample_dropdown, current_idx])
|
| 1107 |
-
next_btn.click(_go_next, inputs=[current_idx], outputs=[movie_video, sample_info, sample_dropdown, current_idx])
|
| 1108 |
-
|
| 1109 |
-
submit_inputs = [evaluator_input, sample_dropdown, final_summary]
|
| 1110 |
-
for key in BASE_METRIC_KEYS:
|
| 1111 |
-
submit_inputs.append(score_widgets[key])
|
| 1112 |
-
submit_inputs.append(reason_widgets[key])
|
| 1113 |
-
submit_btn.click(_submit, inputs=submit_inputs, outputs=[status])
|
| 1114 |
-
|
| 1115 |
-
app.load(lambda x: x, inputs=[evaluator_input], outputs=[evaluator_state])
|
| 1116 |
-
|
| 1117 |
-
return app
|
| 1118 |
-
|
| 1119 |
-
|
| 1120 |
-
demo = create_app()
|
| 1121 |
-
|
| 1122 |
-
if __name__ == "__main__":
|
| 1123 |
-
allowed_paths = [str(INPUT_DIR.resolve())] if INPUT_DIR.exists() else None
|
| 1124 |
-
demo.launch(
|
| 1125 |
-
server_name="0.0.0.0",
|
| 1126 |
-
server_port=7860,
|
| 1127 |
-
share=False,
|
| 1128 |
-
show_error=True,
|
| 1129 |
-
allowed_paths=allowed_paths,
|
| 1130 |
-
)
|
| 1131 |
-
"""
|
| 1132 |
-
VideoEval Movie-Level 问卷应用(Hugging Face Spaces)
|
| 1133 |
-
仅保留 Movie-Level 评测,并支持方法级别统计输出。
|
| 1134 |
-
"""
|
| 1135 |
-
|
| 1136 |
-
import json
|
| 1137 |
-
import os
|
| 1138 |
-
import threading
|
| 1139 |
-
from collections import defaultdict
|
| 1140 |
-
from datetime import datetime
|
| 1141 |
-
from pathlib import Path
|
| 1142 |
-
from typing import Any, Dict, List, Optional, Tuple
|
| 1143 |
-
|
| 1144 |
-
import gradio as gr
|
| 1145 |
-
from huggingface_hub import CommitScheduler, snapshot_download
|
| 1146 |
-
|
| 1147 |
-
# 路径配置(按用户要求)
|
| 1148 |
-
# Spaces 推荐优先读取当前 Space 仓库内文件(app.py 同级)
|
| 1149 |
-
APP_DIR = Path(__file__).resolve().parent
|
| 1150 |
-
LOCAL_INPUT_DIR = APP_DIR / "user_study_input"
|
| 1151 |
-
LOCAL_OUTPUT_DIR = APP_DIR / "user_study_results"
|
| 1152 |
-
DATA_INPUT_DIR = Path("/data/user_study_input")
|
| 1153 |
-
DATA_OUTPUT_DIR = Path("/data/user_study_results")
|
| 1154 |
-
DATA_REPO_ID = os.environ.get("DATA_REPO_ID", "MemDirector/user_study_input")
|
| 1155 |
-
RESULTS_REPO_ID = os.environ.get("RESULTS_REPO_ID", "MemDirector/user_study_results")
|
| 1156 |
-
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 1157 |
-
SPACE_MODE = os.environ.get("SPACE_MODE", "repo_first") # repo_first / data_first / hub_only
|
| 1158 |
-
|
| 1159 |
-
ROOT_DIR = APP_DIR
|
| 1160 |
-
INPUT_DIR = LOCAL_INPUT_DIR
|
| 1161 |
-
OUTPUT_DIR = LOCAL_OUTPUT_DIR
|
| 1162 |
-
STORY_DIR = INPUT_DIR / "clip_movie_story"
|
| 1163 |
-
VIDEO_DIR = INPUT_DIR / "video"
|
| 1164 |
-
|
| 1165 |
-
Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)
|
| 1166 |
-
scheduler: Optional[CommitScheduler] = None
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
def _set_paths(input_dir: Path, output_dir: Path) -> None:
|
| 1170 |
-
global INPUT_DIR, OUTPUT_DIR, STORY_DIR, VIDEO_DIR, ROOT_DIR
|
| 1171 |
-
INPUT_DIR = input_dir
|
| 1172 |
-
OUTPUT_DIR = output_dir
|
| 1173 |
-
STORY_DIR = INPUT_DIR / "clip_movie_story"
|
| 1174 |
-
VIDEO_DIR = INPUT_DIR / "video"
|
| 1175 |
-
ROOT_DIR = INPUT_DIR.parent
|
| 1176 |
-
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 1177 |
-
|
| 1178 |
-
|
| 1179 |
-
def _try_use_local_repo_layout() -> bool:
|
| 1180 |
-
# Space 仓库内自带 user_study_input 时,直接读取(最符合“已放上去直接跑”)
|
| 1181 |
-
if LOCAL_INPUT_DIR.exists():
|
| 1182 |
-
_set_paths(LOCAL_INPUT_DIR, LOCAL_OUTPUT_DIR)
|
| 1183 |
-
return True
|
| 1184 |
-
return False
|
| 1185 |
-
|
| 1186 |
-
|
| 1187 |
-
def _try_use_data_volume_layout() -> bool:
|
| 1188 |
-
# 如果使用 /data 持久卷,则可放在 /data/user_study_input
|
| 1189 |
-
if DATA_INPUT_DIR.exists():
|
| 1190 |
-
_set_paths(DATA_INPUT_DIR, DATA_OUTPUT_DIR)
|
| 1191 |
-
return True
|
| 1192 |
-
return False
|
| 1193 |
-
|
| 1194 |
-
|
| 1195 |
-
def _try_download_from_hub() -> bool:
|
| 1196 |
-
# 最后兜底:从 dataset repo 下载
|
| 1197 |
-
if not DATA_REPO_ID:
|
| 1198 |
-
return False
|
| 1199 |
-
hub_root = APP_DIR / ".hf_space_cache"
|
| 1200 |
-
try:
|
| 1201 |
-
snapshot_download(
|
| 1202 |
-
repo_id=DATA_REPO_ID,
|
| 1203 |
-
repo_type="dataset",
|
| 1204 |
-
local_dir=str(hub_root),
|
| 1205 |
-
token=HF_TOKEN,
|
| 1206 |
-
allow_patterns=[
|
| 1207 |
-
"clip_movie_story/**",
|
| 1208 |
-
"video/**",
|
| 1209 |
-
"user_study_input/**",
|
| 1210 |
-
"user_study_results/**",
|
| 1211 |
-
],
|
| 1212 |
-
)
|
| 1213 |
-
except Exception as e:
|
| 1214 |
-
print(f"[INIT] snapshot_download failed: {e}")
|
| 1215 |
-
return False
|
| 1216 |
-
|
| 1217 |
-
# 兼容两种 dataset 结构:
|
| 1218 |
-
# A) 仓库根目录直接是 clip_movie_story/ 与 video/
|
| 1219 |
-
# B) 仓库里有 user_study_input/ 子目录
|
| 1220 |
-
if (hub_root / "clip_movie_story").exists() and (hub_root / "video").exists():
|
| 1221 |
-
hub_input = hub_root
|
| 1222 |
-
elif (hub_root / "user_study_input").exists():
|
| 1223 |
-
hub_input = hub_root / "user_study_input"
|
| 1224 |
-
else:
|
| 1225 |
-
return False
|
| 1226 |
-
|
| 1227 |
-
hub_output = hub_root / "user_study_results"
|
| 1228 |
-
_set_paths(hub_input, hub_output)
|
| 1229 |
-
return True
|
| 1230 |
-
|
| 1231 |
-
|
| 1232 |
-
def init_space_storage() -> None:
|
| 1233 |
-
"""
|
| 1234 |
-
Hugging Face Spaces 规范:
|
| 1235 |
-
- 从 dataset repo 拉取 user_study_input 与 user_study_results 到本地 ROOT_DIR
|
| 1236 |
-
- 使用 CommitScheduler 持续回写 user_study_results
|
| 1237 |
-
"""
|
| 1238 |
-
global scheduler
|
| 1239 |
-
|
| 1240 |
-
if SPACE_MODE == "hub_only":
|
| 1241 |
-
ok = _try_download_from_hub()
|
| 1242 |
-
elif SPACE_MODE == "data_first":
|
| 1243 |
-
ok = _try_use_data_volume_layout() or _try_use_local_repo_layout() or _try_download_from_hub()
|
| 1244 |
-
else:
|
| 1245 |
-
ok = _try_use_local_repo_layout() or _try_use_data_volume_layout() or _try_download_from_hub()
|
| 1246 |
-
print(f"[INIT] storage init mode={SPACE_MODE}, success={ok}, input={INPUT_DIR}, output={OUTPUT_DIR}")
|
| 1247 |
-
|
| 1248 |
-
if RESULTS_REPO_ID:
|
| 1249 |
-
try:
|
| 1250 |
-
scheduler = CommitScheduler(
|
| 1251 |
-
repo_id=RESULTS_REPO_ID,
|
| 1252 |
-
repo_type="dataset",
|
| 1253 |
-
folder_path=str(OUTPUT_DIR),
|
| 1254 |
-
path_in_repo="user_study_results",
|
| 1255 |
-
every=3,
|
| 1256 |
-
token=HF_TOKEN,
|
| 1257 |
-
)
|
| 1258 |
-
print(f"[INIT] CommitScheduler enabled: {RESULTS_REPO_ID}")
|
| 1259 |
-
except Exception as e:
|
| 1260 |
-
print(f"[INIT] CommitScheduler init failed: {e}")
|
| 1261 |
-
|
| 1262 |
-
|
| 1263 |
-
init_space_storage()
|
| 1264 |
-
|
| 1265 |
-
# Movie-Level 指标定义
|
| 1266 |
-
MOVIE_CRITERIA: List[Tuple[str, str, str]] = [
|
| 1267 |
-
("SF", "Script Faithfulness (剧本忠实度)", "生成的视觉内容与原始剧本描述的吻合程度。"),
|
| 1268 |
-
("NC", "Narrative Coherence (叙事连贯性)", "镜头间情节发展的逻辑性,确保故事表达清晰、不破碎。"),
|
| 1269 |
-
("VQ", "Visual Quality (视觉质量)", "画面的清晰度、噪点控制、光影效果等基础图像质量。"),
|
| 1270 |
-
("CC", "Character Consistency (角色一致性)", "同一角色在不同镜头、不同角度下的外貌、服装及特征的稳定性。"),
|
| 1271 |
-
("PLC", "Physical Law Compliance (物理规律符合度)", "运动、重力、碰撞等是否符合现实物理逻辑,是否存在严重 AI 幻觉。"),
|
| 1272 |
-
("V_AQ", "Voice/Audio Quality (语音/音频质量)", "配音、背景音乐和音效的清晰度、自然度及技术品质。"),
|
| 1273 |
-
("CT", "Cinematic Techniques (电影技巧)", "镜头运动、景深控制及构图的专业性。"),
|
| 1274 |
-
("AVR", "Audio-Visual Richness (视听丰富度)", "画面细节精细度以及音频层次(音效、氛围音)的丰富程度。"),
|
| 1275 |
-
("NP", "Narrative Pacing (叙事节奏)", "镜头剪辑长短切换是否契合故事情节张力需求。"),
|
| 1276 |
-
("VAC", "Video-Audio Coordination (视听协调性)", "画面动作与音效、音乐卡点的同步率。"),
|
| 1277 |
-
("CD", "Compelling Degree (引人入胜程度)", "吸引注意力并引发情感共鸣或沉浸感的能力。"),
|
| 1278 |
-
("OQ", "Overall Quality (整体质量)", "对生成视频作为“电影作品”的综合观感评分。"),
|
| 1279 |
-
]
|
| 1280 |
-
|
| 1281 |
-
BASE_METRIC_KEYS = [k for k, _, _ in MOVIE_CRITERIA]
|
| 1282 |
-
SAVE_LOCK = threading.Lock()
|
| 1283 |
-
|
| 1284 |
-
CUSTOM_CSS = """
|
| 1285 |
-
.gradio-container {
|
| 1286 |
-
max-width: 1360px !important;
|
| 1287 |
-
background:
|
| 1288 |
-
radial-gradient(circle at 8% 12%, rgba(103, 136, 255, 0.12) 0%, rgba(103, 136, 255, 0) 32%),
|
| 1289 |
-
radial-gradient(circle at 92% 18%, rgba(255, 145, 200, 0.1) 0%, rgba(255, 145, 200, 0) 34%),
|
| 1290 |
-
linear-gradient(180deg, #fcfdff 0%, #f9fbff 52%, #ffffff 100%);
|
| 1291 |
-
padding-bottom: 18px;
|
| 1292 |
-
color: #2e4168;
|
| 1293 |
-
}
|
| 1294 |
-
body,
|
| 1295 |
-
html {
|
| 1296 |
-
background: #f6f9ff !important;
|
| 1297 |
-
color-scheme: light;
|
| 1298 |
-
}
|
| 1299 |
-
.gradio-container .block,
|
| 1300 |
-
.gradio-container .form {
|
| 1301 |
-
background: transparent !important;
|
| 1302 |
-
}
|
| 1303 |
-
.gradio-container .prose,
|
| 1304 |
-
.gradio-container .gr-box,
|
| 1305 |
-
.gradio-container .gr-panel,
|
| 1306 |
-
.gradio-container .gr-group {
|
| 1307 |
-
background: #ffffff !important;
|
| 1308 |
}
|
| 1309 |
#hero {
|
| 1310 |
-
border: 1px solid #
|
| 1311 |
border-radius: 16px;
|
| 1312 |
-
padding:
|
| 1313 |
-
background: linear-gradient(
|
| 1314 |
-
|
| 1315 |
-
margin-bottom: 12px;
|
| 1316 |
}
|
| 1317 |
#hero h1 {
|
| 1318 |
-
margin: 0;
|
| 1319 |
-
font-size: 1.
|
| 1320 |
-
letter-spacing: 0.3px;
|
| 1321 |
-
color: #23325b;
|
| 1322 |
}
|
| 1323 |
#hero p {
|
| 1324 |
-
margin:
|
| 1325 |
-
color: #
|
| 1326 |
-
}
|
| 1327 |
-
#hero .hero-badge {
|
| 1328 |
-
display: inline-flex;
|
| 1329 |
-
gap: 8px;
|
| 1330 |
-
align-items: center;
|
| 1331 |
-
margin-top: 14px;
|
| 1332 |
-
padding: 6px 12px;
|
| 1333 |
-
border-radius: 999px;
|
| 1334 |
-
border: 1px solid #c9d7ff;
|
| 1335 |
-
background: #ffffffcc;
|
| 1336 |
-
color: #49609d;
|
| 1337 |
-
font-size: 12px;
|
| 1338 |
-
}
|
| 1339 |
-
.topbar {
|
| 1340 |
-
margin: 12px 0 16px 0;
|
| 1341 |
-
display: grid;
|
| 1342 |
-
grid-template-columns: repeat(3, minmax(120px, 1fr));
|
| 1343 |
-
gap: 12px;
|
| 1344 |
-
}
|
| 1345 |
-
.metric-card {
|
| 1346 |
-
border: 1px solid #d7e1ff;
|
| 1347 |
-
border-radius: 12px;
|
| 1348 |
-
padding: 12px 14px;
|
| 1349 |
-
background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
|
| 1350 |
-
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
|
| 1351 |
-
}
|
| 1352 |
-
.metric-label {
|
| 1353 |
-
font-size: 12px;
|
| 1354 |
-
color: #667aa8;
|
| 1355 |
-
margin-bottom: 4px;
|
| 1356 |
-
}
|
| 1357 |
-
.metric-value {
|
| 1358 |
-
color: #2d3f68;
|
| 1359 |
-
font-size: 16px;
|
| 1360 |
-
font-weight: 650;
|
| 1361 |
}
|
| 1362 |
.panel {
|
| 1363 |
-
border: 1px solid #
|
| 1364 |
border-radius: 14px !important;
|
| 1365 |
padding: 14px !important;
|
| 1366 |
-
background: #
|
| 1367 |
-
box-shadow: 0 3px 12px rgba(101, 118, 172, 0.08);
|
| 1368 |
-
}
|
| 1369 |
-
.section-title {
|
| 1370 |
-
margin: 0 0 10px 0;
|
| 1371 |
-
font-size: 1.03rem;
|
| 1372 |
-
font-weight: 620;
|
| 1373 |
-
color: #2a3c63;
|
| 1374 |
}
|
| 1375 |
.hint {
|
| 1376 |
-
color: #
|
| 1377 |
font-size: 0.9rem;
|
| 1378 |
}
|
| 1379 |
-
.toolbar-btn {
|
| 1380 |
-
min-height: 42px !important;
|
| 1381 |
-
border-radius: 10px !important;
|
| 1382 |
-
}
|
| 1383 |
-
.gr-button-primary {
|
| 1384 |
-
background: linear-gradient(180deg, #7496ff 0%, #5b82ff 100%) !important;
|
| 1385 |
-
border: 1px solid #8aa7ff !important;
|
| 1386 |
-
box-shadow: 0 6px 18px rgba(93, 125, 223, 0.28) !important;
|
| 1387 |
-
}
|
| 1388 |
-
.status-box {
|
| 1389 |
-
border: 1px dashed #9fb2e3;
|
| 1390 |
-
border-radius: 10px;
|
| 1391 |
-
padding: 9px 11px;
|
| 1392 |
-
background: #f8faff;
|
| 1393 |
-
color: #3f527f;
|
| 1394 |
-
}
|
| 1395 |
-
.soft-input textarea,
|
| 1396 |
-
.soft-input input,
|
| 1397 |
-
.soft-input .wrap {
|
| 1398 |
-
border-radius: 10px !important;
|
| 1399 |
-
background: #ffffff !important;
|
| 1400 |
-
border-color: #d8e2ff !important;
|
| 1401 |
-
color: #2e4168 !important;
|
| 1402 |
-
}
|
| 1403 |
-
.gr-markdown,
|
| 1404 |
-
.gradio-container p,
|
| 1405 |
-
.gradio-container span,
|
| 1406 |
-
.gradio-container label {
|
| 1407 |
-
color: #2e4168;
|
| 1408 |
-
}
|
| 1409 |
-
.gr-accordion {
|
| 1410 |
-
border-radius: 12px !important;
|
| 1411 |
-
border-color: #d5def7 !important;
|
| 1412 |
-
background: #ffffff !important;
|
| 1413 |
-
}
|
| 1414 |
"""
|
| 1415 |
|
| 1416 |
|
|
@@ -1599,59 +368,42 @@ def create_app():
|
|
| 1599 |
with gr.Blocks(
|
| 1600 |
title="VideoEval Movie-Level Evaluation",
|
| 1601 |
css=CUSTOM_CSS,
|
| 1602 |
-
theme=gr.themes.Soft(primary_hue="
|
| 1603 |
) as app:
|
| 1604 |
gr.HTML(
|
| 1605 |
-
|
| 1606 |
<div id="hero">
|
| 1607 |
<h1>VideoEval · Movie-Level Evaluation</h1>
|
| 1608 |
<p>统一电影级评测问卷,支持方法级均分统计(含 CL / CRh / AVG)</p>
|
| 1609 |
-
<div class="hero-badge">HF Space Ready · Gradio Blocks · Clean Review Flow</div>
|
| 1610 |
-
</div>
|
| 1611 |
-
<div class="topbar">
|
| 1612 |
-
<div class="metric-card">
|
| 1613 |
-
<div class="metric-label">Pending Samples</div>
|
| 1614 |
-
<div class="metric-value">{len(samples)}</div>
|
| 1615 |
-
</div>
|
| 1616 |
-
<div class="metric-card">
|
| 1617 |
-
<div class="metric-label">Evaluation Scope</div>
|
| 1618 |
-
<div class="metric-value">Movie-Level</div>
|
| 1619 |
-
</div>
|
| 1620 |
-
<div class="metric-card">
|
| 1621 |
-
<div class="metric-label">Scoring Standard</div>
|
| 1622 |
-
<div class="metric-value">12 Metrics · 1~5</div>
|
| 1623 |
-
</div>
|
| 1624 |
</div>
|
| 1625 |
"""
|
| 1626 |
)
|
| 1627 |
gr.Markdown(
|
| 1628 |
f"<span class='hint'>输入目录:`{INPUT_DIR}` | 输出目录:`{OUTPUT_DIR}`</span>",
|
| 1629 |
)
|
| 1630 |
-
|
| 1631 |
-
gr.Markdown(build_data_diagnostics(samples))
|
| 1632 |
|
| 1633 |
current_idx = gr.State(0)
|
| 1634 |
evaluator_state = gr.State("anonymous")
|
| 1635 |
|
| 1636 |
with gr.Row():
|
| 1637 |
-
with gr.Column(scale=
|
| 1638 |
-
gr.Markdown("
|
| 1639 |
with gr.Row():
|
| 1640 |
-
evaluator_input = gr.Textbox(label="Evaluator ID", value="anonymous"
|
| 1641 |
sample_dropdown = gr.Dropdown(
|
| 1642 |
label="选择评测样本(匿名)",
|
| 1643 |
choices=[s["anon_id"] for s in samples],
|
| 1644 |
value=samples[0]["anon_id"] if samples else None,
|
| 1645 |
interactive=True,
|
| 1646 |
-
elem_classes=["soft-input"],
|
| 1647 |
)
|
| 1648 |
with gr.Row():
|
| 1649 |
-
prev_btn = gr.Button("← Previous"
|
| 1650 |
-
next_btn = gr.Button("Next →"
|
| 1651 |
-
submit_btn = gr.Button("提交当前评分并统计", variant="primary"
|
| 1652 |
-
status = gr.Markdown("
|
| 1653 |
-
with gr.Column(scale=
|
| 1654 |
-
gr.Markdown("
|
| 1655 |
movie_video = gr.Video(label="Movie Video", value=samples[0]["video_path"] if samples else None, height=460)
|
| 1656 |
sample_info = gr.Markdown("无可用样本" if not samples else build_sample_brief(samples[0], 0, len(samples)))
|
| 1657 |
|
|
@@ -1678,10 +430,10 @@ def create_app():
|
|
| 1678 |
gr.Markdown(f"**{key} · {name}**")
|
| 1679 |
gr.Markdown(f"<span class='hint'>{desc}</span>")
|
| 1680 |
with gr.Row():
|
| 1681 |
-
score_widgets[key] = gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{key} Score", scale=1
|
| 1682 |
-
reason_widgets[key] = gr.Textbox(label=f"{key} Reason(可选)", lines=2, placeholder="补充评分依据", scale=2
|
| 1683 |
|
| 1684 |
-
final_summary = gr.Textbox(label="Final Summary(可选)", lines=4, placeholder="总结该视频的主要优缺点"
|
| 1685 |
|
| 1686 |
def _sync_sample_from_dropdown(anon_id: str) -> Tuple[str, str, int]:
|
| 1687 |
if not anon_id or anon_id not in sample_map:
|
|
|
|
| 153 |
|
| 154 |
CUSTOM_CSS = """
|
| 155 |
.gradio-container {
|
| 156 |
+
max-width: 1300px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
}
|
| 158 |
#hero {
|
| 159 |
+
border: 1px solid #2b2f3a;
|
| 160 |
border-radius: 16px;
|
| 161 |
+
padding: 20px 22px;
|
| 162 |
+
background: linear-gradient(135deg, #121826 0%, #1d2540 55%, #2a1f45 100%);
|
| 163 |
+
margin-bottom: 14px;
|
|
|
|
| 164 |
}
|
| 165 |
#hero h1 {
|
| 166 |
+
margin: 0 0 8px 0;
|
| 167 |
+
font-size: 1.9rem;
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
#hero p {
|
| 170 |
+
margin: 0;
|
| 171 |
+
color: #d0d8f0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
.panel {
|
| 174 |
+
border: 1px solid #2e3445 !important;
|
| 175 |
border-radius: 14px !important;
|
| 176 |
padding: 14px !important;
|
| 177 |
+
background: #111522 !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
.hint {
|
| 180 |
+
color: #9aa7c9;
|
| 181 |
font-size: 0.9rem;
|
| 182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
"""
|
| 184 |
|
| 185 |
|
|
|
|
| 368 |
with gr.Blocks(
|
| 369 |
title="VideoEval Movie-Level Evaluation",
|
| 370 |
css=CUSTOM_CSS,
|
| 371 |
+
theme=gr.themes.Soft(primary_hue="violet", secondary_hue="blue", neutral_hue="slate"),
|
| 372 |
) as app:
|
| 373 |
gr.HTML(
|
| 374 |
+
"""
|
| 375 |
<div id="hero">
|
| 376 |
<h1>VideoEval · Movie-Level Evaluation</h1>
|
| 377 |
<p>统一电影级评测问卷,支持方法级均分统计(含 CL / CRh / AVG)</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
</div>
|
| 379 |
"""
|
| 380 |
)
|
| 381 |
gr.Markdown(
|
| 382 |
f"<span class='hint'>输入目录:`{INPUT_DIR}` | 输出目录:`{OUTPUT_DIR}`</span>",
|
| 383 |
)
|
| 384 |
+
gr.Markdown(build_data_diagnostics(samples))
|
|
|
|
| 385 |
|
| 386 |
current_idx = gr.State(0)
|
| 387 |
evaluator_state = gr.State("anonymous")
|
| 388 |
|
| 389 |
with gr.Row():
|
| 390 |
+
with gr.Column(scale=5, elem_classes=["panel"]):
|
| 391 |
+
gr.Markdown("### 1) 评测员与样本")
|
| 392 |
with gr.Row():
|
| 393 |
+
evaluator_input = gr.Textbox(label="Evaluator ID", value="anonymous")
|
| 394 |
sample_dropdown = gr.Dropdown(
|
| 395 |
label="选择评测样本(匿名)",
|
| 396 |
choices=[s["anon_id"] for s in samples],
|
| 397 |
value=samples[0]["anon_id"] if samples else None,
|
| 398 |
interactive=True,
|
|
|
|
| 399 |
)
|
| 400 |
with gr.Row():
|
| 401 |
+
prev_btn = gr.Button("← Previous")
|
| 402 |
+
next_btn = gr.Button("Next →")
|
| 403 |
+
submit_btn = gr.Button("提交当前评分并统计", variant="primary")
|
| 404 |
+
status = gr.Markdown("")
|
| 405 |
+
with gr.Column(scale=7, elem_classes=["panel"]):
|
| 406 |
+
gr.Markdown("### 2) 视频与剧情")
|
| 407 |
movie_video = gr.Video(label="Movie Video", value=samples[0]["video_path"] if samples else None, height=460)
|
| 408 |
sample_info = gr.Markdown("无可用样本" if not samples else build_sample_brief(samples[0], 0, len(samples)))
|
| 409 |
|
|
|
|
| 430 |
gr.Markdown(f"**{key} · {name}**")
|
| 431 |
gr.Markdown(f"<span class='hint'>{desc}</span>")
|
| 432 |
with gr.Row():
|
| 433 |
+
score_widgets[key] = gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{key} Score", scale=1)
|
| 434 |
+
reason_widgets[key] = gr.Textbox(label=f"{key} Reason(可选)", lines=2, placeholder="补充评分依据", scale=2)
|
| 435 |
|
| 436 |
+
final_summary = gr.Textbox(label="Final Summary(可选)", lines=4, placeholder="总结该视频的主要优缺点")
|
| 437 |
|
| 438 |
def _sync_sample_from_dropdown(anon_id: str) -> Tuple[str, str, int]:
|
| 439 |
if not anon_id or anon_id not in sample_map:
|