Add public WorldModelBench review app source
Browse files- web-review/service/Dockerfile +13 -0
- web-review/service/README.md +13 -0
- web-review/service/__pycache__/app.cpython-311.pyc +0 -0
- web-review/service/app.py +157 -0
- web-review/service/requirements.txt +1 -0
- web-review/service/static/data/worldmodelbench-catalog.js +0 -0
- web-review/service/static/review.html +323 -0
web-review/service/Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.12-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
ENV PYTHONUNBUFFERED=1
|
| 5 |
+
ENV PORT=7860
|
| 6 |
+
|
| 7 |
+
COPY requirements.txt .
|
| 8 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 9 |
+
COPY app.py .
|
| 10 |
+
COPY static ./static
|
| 11 |
+
|
| 12 |
+
EXPOSE 7860
|
| 13 |
+
CMD ["python", "app.py"]
|
web-review/service/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: WorldModelBench Review
|
| 3 |
+
emoji: 🧭
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# WorldModelBench Review
|
| 11 |
+
|
| 12 |
+
Public review interface for the complete video catalog. Submitted annotations
|
| 13 |
+
are appended to `Xinyun-Liu/WorldModelBench/web-review/submissions/`.
|
web-review/service/__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (12.2 kB). View file
|
|
|
web-review/service/app.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|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| 6 |
+
import io
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import threading
|
| 10 |
+
import uuid
|
| 11 |
+
from datetime import datetime, timezone
|
| 12 |
+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from urllib.parse import urlparse
|
| 15 |
+
|
| 16 |
+
from huggingface_hub import CommitOperationAdd, HfApi, get_token
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
ROOT = Path(__file__).resolve().parent
|
| 20 |
+
STATIC_ROOT = ROOT / "static"
|
| 21 |
+
CATALOG_PATH = STATIC_ROOT / "data" / "worldmodelbench-catalog.js"
|
| 22 |
+
DATASET_REPO = os.environ.get("WORLDMODELBENCH_REPO", "Xinyun-Liu/WorldModelBench")
|
| 23 |
+
HF_TOKEN = os.environ.get("HF_TOKEN") or get_token() or ""
|
| 24 |
+
MAX_BODY_BYTES = 32_000
|
| 25 |
+
MIN_SUBMISSION_INTERVAL = 0.8
|
| 26 |
+
last_submission_by_ip: dict[str, float] = {}
|
| 27 |
+
rate_lock = threading.Lock()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def read_catalog() -> dict[str, dict[str, str]]:
|
| 31 |
+
raw = CATALOG_PATH.read_text(encoding="utf-8")
|
| 32 |
+
payload = raw.split("=", 1)[1].strip().rstrip(";")
|
| 33 |
+
rows = json.loads(payload)
|
| 34 |
+
return {row["videoPath"]: row for row in rows if isinstance(row, dict) and row.get("videoPath")}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
CATALOG = read_catalog()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def utc_now() -> str:
|
| 41 |
+
return datetime.now(timezone.utc).isoformat(timespec="seconds")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def clean_string(value: object, field: str, maximum: int, required: bool = False) -> str:
|
| 45 |
+
if not isinstance(value, str):
|
| 46 |
+
raise ValueError(f"{field}_must_be_text")
|
| 47 |
+
value = value.strip()
|
| 48 |
+
if required and not value:
|
| 49 |
+
raise ValueError(f"{field}_is_required")
|
| 50 |
+
if len(value) > maximum:
|
| 51 |
+
raise ValueError(f"{field}_is_too_long")
|
| 52 |
+
return value
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def validate_submission(payload: object) -> dict[str, str]:
|
| 56 |
+
if not isinstance(payload, dict):
|
| 57 |
+
raise ValueError("request_must_be_a_json_object")
|
| 58 |
+
annotator = clean_string(payload.get("annotator"), "annotator", 80, required=True)
|
| 59 |
+
video_path = clean_string(payload.get("video_path"), "video_path", 500, required=True)
|
| 60 |
+
row = CATALOG.get(video_path)
|
| 61 |
+
if row is None:
|
| 62 |
+
raise ValueError("video_path_is_not_in_the_catalog")
|
| 63 |
+
decision = clean_string(payload.get("decision", "pending"), "decision", 20, required=True)
|
| 64 |
+
if decision not in {"pending", "keep", "reject"}:
|
| 65 |
+
raise ValueError("invalid_decision")
|
| 66 |
+
return {
|
| 67 |
+
"annotator": annotator,
|
| 68 |
+
"video_path": video_path,
|
| 69 |
+
"sample_id": clean_string(row.get("id", ""), "sample_id", 300, required=True),
|
| 70 |
+
"data_source": clean_string(row.get("sourceDataset", ""), "data_source", 200, required=True),
|
| 71 |
+
"decision": decision,
|
| 72 |
+
"track": clean_string(payload.get("track", ""), "track", 200),
|
| 73 |
+
"scene": clean_string(payload.get("scene", ""), "scene", 300),
|
| 74 |
+
"spatial_ability": clean_string(payload.get("spatial_ability", ""), "spatial_ability", 500),
|
| 75 |
+
"perspective": clean_string(payload.get("perspective", ""), "perspective", 300),
|
| 76 |
+
"text_caption": clean_string(payload.get("text_caption", ""), "text_caption", 4000),
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class ReviewHandler(SimpleHTTPRequestHandler):
|
| 81 |
+
server_version = "WorldModelBenchReview/1.0"
|
| 82 |
+
|
| 83 |
+
def __init__(self, *args, **kwargs):
|
| 84 |
+
super().__init__(*args, directory=str(STATIC_ROOT), **kwargs)
|
| 85 |
+
|
| 86 |
+
def send_json(self, status: int, value: dict[str, object]) -> None:
|
| 87 |
+
body = json.dumps(value, ensure_ascii=False).encode("utf-8")
|
| 88 |
+
self.send_response(status)
|
| 89 |
+
self.send_header("Content-Type", "application/json; charset=utf-8")
|
| 90 |
+
self.send_header("Content-Length", str(len(body)))
|
| 91 |
+
self.send_header("Cache-Control", "no-store")
|
| 92 |
+
self.end_headers()
|
| 93 |
+
self.wfile.write(body)
|
| 94 |
+
|
| 95 |
+
def do_GET(self) -> None:
|
| 96 |
+
path = urlparse(self.path).path
|
| 97 |
+
if path == "/api/health":
|
| 98 |
+
self.send_json(200 if HF_TOKEN else 503, {"ok": bool(HF_TOKEN), "catalog_videos": len(CATALOG), "dataset_repo": DATASET_REPO})
|
| 99 |
+
return
|
| 100 |
+
if path == "/":
|
| 101 |
+
self.path = "/review.html"
|
| 102 |
+
super().do_GET()
|
| 103 |
+
|
| 104 |
+
def do_POST(self) -> None:
|
| 105 |
+
if urlparse(self.path).path != "/api/submissions":
|
| 106 |
+
self.send_json(404, {"error": "not_found"})
|
| 107 |
+
return
|
| 108 |
+
if not HF_TOKEN:
|
| 109 |
+
self.send_json(503, {"error": "submission_service_not_configured"})
|
| 110 |
+
return
|
| 111 |
+
client_ip = self.client_address[0]
|
| 112 |
+
now = datetime.now(timezone.utc).timestamp()
|
| 113 |
+
with rate_lock:
|
| 114 |
+
previous = last_submission_by_ip.get(client_ip, 0.0)
|
| 115 |
+
if now - previous < MIN_SUBMISSION_INTERVAL:
|
| 116 |
+
self.send_json(429, {"error": "please_wait_before_submitting_again"})
|
| 117 |
+
return
|
| 118 |
+
last_submission_by_ip[client_ip] = now
|
| 119 |
+
|
| 120 |
+
try:
|
| 121 |
+
content_length = int(self.headers.get("Content-Length", "0"))
|
| 122 |
+
if content_length <= 0 or content_length > MAX_BODY_BYTES:
|
| 123 |
+
raise ValueError("invalid_request_size")
|
| 124 |
+
payload = json.loads(self.rfile.read(content_length).decode("utf-8"))
|
| 125 |
+
record = validate_submission(payload)
|
| 126 |
+
submission_id = uuid.uuid4().hex
|
| 127 |
+
created_at = utc_now()
|
| 128 |
+
record.update({
|
| 129 |
+
"schema_version": "worldmodelbench-web-review-v1",
|
| 130 |
+
"submission_id": submission_id,
|
| 131 |
+
"submitted_at": created_at,
|
| 132 |
+
"source": "public_review_space",
|
| 133 |
+
})
|
| 134 |
+
path_in_repo = f"web-review/submissions/{created_at[:10]}/{submission_id}.json"
|
| 135 |
+
content = json.dumps(record, ensure_ascii=False, indent=2).encode("utf-8")
|
| 136 |
+
HfApi(token=HF_TOKEN).create_commit(
|
| 137 |
+
repo_id=DATASET_REPO,
|
| 138 |
+
repo_type="dataset",
|
| 139 |
+
operations=[CommitOperationAdd(path_in_repo=path_in_repo, path_or_fileobj=io.BytesIO(content))],
|
| 140 |
+
commit_message=f"Add web review annotation {submission_id[:12]}",
|
| 141 |
+
)
|
| 142 |
+
self.send_json(201, {"ok": True, "submission_id": submission_id, "submitted_at": created_at})
|
| 143 |
+
except ValueError as error:
|
| 144 |
+
self.send_json(400, {"error": str(error)})
|
| 145 |
+
except Exception:
|
| 146 |
+
self.send_json(502, {"error": "huggingface_submission_failed"})
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def main() -> None:
|
| 150 |
+
port = int(os.environ.get("PORT", "7860"))
|
| 151 |
+
server = ThreadingHTTPServer(("0.0.0.0", port), ReviewHandler)
|
| 152 |
+
print(f"WorldModelBench review service listening on {port}", flush=True)
|
| 153 |
+
server.serve_forever()
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
if __name__ == "__main__":
|
| 157 |
+
main()
|
web-review/service/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub>=0.32.0,<1.0
|
web-review/service/static/data/worldmodelbench-catalog.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
web-review/service/static/review.html
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|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
<title>WorldModelBench 数据审核</title>
|
| 7 |
+
<script src="data/worldmodelbench-catalog.js"></script>
|
| 8 |
+
<style>
|
| 9 |
+
:root { color-scheme: light; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #17211d; background: #f4f6f4; }
|
| 10 |
+
* { box-sizing: border-box; }
|
| 11 |
+
body { margin: 0; min-width: 320px; background: #f4f6f4; }
|
| 12 |
+
button, input, select, textarea { font: inherit; }
|
| 13 |
+
button { cursor: pointer; }
|
| 14 |
+
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid #1d7562; outline-offset: 2px; }
|
| 15 |
+
.app-header { border-bottom: 1px solid #ccd6d0; background: #fbfcfb; }
|
| 16 |
+
.header-inner, main { width: min(1480px, calc(100% - 32px)); margin: 0 auto; }
|
| 17 |
+
.header-inner { min-height: 76px; display: grid; grid-template-columns: minmax(230px, 1fr) minmax(190px, 250px) auto; align-items: center; gap: 20px; }
|
| 18 |
+
h1, h2, h3, p { margin: 0; }
|
| 19 |
+
h1 { font-size: 22px; line-height: 1.2; font-weight: 720; letter-spacing: 0; }
|
| 20 |
+
.subtitle { margin-top: 5px; color: #57655f; font-size: 13px; }
|
| 21 |
+
main { padding: 28px 0 52px; }
|
| 22 |
+
.toolbar { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 22px; }
|
| 23 |
+
.toolbar h2 { font-size: 18px; line-height: 1.25; }
|
| 24 |
+
.toolbar p { margin-top: 6px; color: #5e6d66; font-size: 13px; }
|
| 25 |
+
.actions, .filters, .pagination { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
| 26 |
+
.identity { display: grid; gap: 5px; }
|
| 27 |
+
.identity input { min-height: 35px; }
|
| 28 |
+
.service-status { color: #5d6d65; font-size: 11px; }
|
| 29 |
+
.service-status.connected { color: #176b58; }
|
| 30 |
+
.button, .icon-button { border: 1px solid #aebcb4; background: #fff; color: #1c2923; min-height: 38px; border-radius: 5px; padding: 7px 12px; font-weight: 630; font-size: 13px; }
|
| 31 |
+
.button:hover, .icon-button:hover { background: #edf3ef; border-color: #7b978a; }
|
| 32 |
+
.button.primary { background: #176b58; border-color: #176b58; color: #fff; }
|
| 33 |
+
.button.primary:hover { background: #0f5a49; }
|
| 34 |
+
.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 12px; }
|
| 35 |
+
.source-card { width: 100%; min-height: 138px; text-align: left; border: 1px solid #cbd6d0; border-radius: 7px; background: #fff; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; }
|
| 36 |
+
.source-card:hover { border-color: #176b58; box-shadow: 0 4px 14px rgba(20, 53, 42, .09); }
|
| 37 |
+
.source-card h3 { font-size: 16px; line-height: 1.35; letter-spacing: 0; overflow-wrap: anywhere; }
|
| 38 |
+
.source-card span { color: #52625b; font-size: 13px; }
|
| 39 |
+
.review-controls { display: grid; grid-template-columns: minmax(200px, 1fr) 190px auto; gap: 10px; margin-bottom: 18px; align-items: end; }
|
| 40 |
+
label { display: grid; gap: 6px; color: #39483f; font-size: 12px; font-weight: 680; }
|
| 41 |
+
input, select, textarea { width: 100%; border: 1px solid #b9c6be; border-radius: 4px; background: #fff; color: #152019; padding: 8px 9px; font-size: 13px; }
|
| 42 |
+
input, select { min-height: 37px; }
|
| 43 |
+
input[readonly] { background: #edf2ef; color: #43544b; }
|
| 44 |
+
textarea { min-height: 82px; resize: vertical; line-height: 1.4; }
|
| 45 |
+
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
|
| 46 |
+
.review-card { border: 1px solid #c8d3cd; border-radius: 7px; overflow: clip; background: #fff; min-width: 0; }
|
| 47 |
+
video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #101713; object-fit: contain; }
|
| 48 |
+
.card-body { padding: 14px; }
|
| 49 |
+
.sample-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
|
| 50 |
+
.sample-heading h3 { font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
|
| 51 |
+
.draft-state { white-space: nowrap; color: #63736b; font-size: 11px; }
|
| 52 |
+
.draft-state.saved { color: #176b58; }
|
| 53 |
+
.decision { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #b9c6be; border-radius: 4px; overflow: hidden; margin: 0 0 13px; }
|
| 54 |
+
.decision label { display: block; color: #47574e; font-size: 12px; font-weight: 620; padding: 8px 5px; text-align: center; border-right: 1px solid #b9c6be; cursor: pointer; }
|
| 55 |
+
.decision label:last-child { border-right: 0; }
|
| 56 |
+
.decision label:has(input:checked) { background: #dceee6; color: #0d523f; }
|
| 57 |
+
.decision input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; opacity: 0; pointer-events: none; }
|
| 58 |
+
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
|
| 59 |
+
.fields .wide { grid-column: 1 / -1; }
|
| 60 |
+
.metadata { margin-top: 10px; color: #68776f; font-size: 11px; overflow-wrap: anywhere; }
|
| 61 |
+
.submit-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 13px; }
|
| 62 |
+
.submit-row .button { flex: 1; }
|
| 63 |
+
.submit-state { color: #617169; font-size: 11px; white-space: nowrap; }
|
| 64 |
+
.submit-state.success { color: #176b58; }
|
| 65 |
+
.submit-state.error { color: #a2392e; }
|
| 66 |
+
button:disabled { cursor: not-allowed; opacity: .5; }
|
| 67 |
+
.empty { border: 1px dashed #9eafa6; color: #617169; padding: 36px 20px; text-align: center; }
|
| 68 |
+
.pagination { justify-content: center; margin-top: 24px; }
|
| 69 |
+
.page-status { min-width: 96px; text-align: center; color: #56665e; font-size: 13px; }
|
| 70 |
+
.hidden { display: none !important; }
|
| 71 |
+
@media (max-width: 720px) {
|
| 72 |
+
.header-inner, main { width: min(100% - 24px, 1480px); }
|
| 73 |
+
.header-inner { min-height: 88px; display: flex; align-items: stretch; flex-direction: column; justify-content: center; gap: 9px; }
|
| 74 |
+
.toolbar, .review-controls { display: flex; align-items: stretch; flex-direction: column; }
|
| 75 |
+
.actions .button { flex: 1; }
|
| 76 |
+
.source-grid, .video-grid { grid-template-columns: 1fr; }
|
| 77 |
+
}
|
| 78 |
+
</style>
|
| 79 |
+
</head>
|
| 80 |
+
<body>
|
| 81 |
+
<header class="app-header">
|
| 82 |
+
<div class="header-inner">
|
| 83 |
+
<div><h1>WorldModelBench 数据审核</h1><p class="subtitle" id="total-count">正在读取视频目录</p></div>
|
| 84 |
+
<div class="identity"><label>标注者<input id="annotator-input" type="text" autocomplete="name" maxlength="80" placeholder="姓名或审核代号"></label><span class="service-status" id="service-status">正在检查共享提交服务</span></div>
|
| 85 |
+
<div class="actions">
|
| 86 |
+
<button class="button" id="import-button" type="button">导入标注</button>
|
| 87 |
+
<button class="button primary" id="export-button" type="button">导出标注 JSON</button>
|
| 88 |
+
<input class="hidden" id="import-input" type="file" accept="application/json">
|
| 89 |
+
</div>
|
| 90 |
+
</div>
|
| 91 |
+
</header>
|
| 92 |
+
<main>
|
| 93 |
+
<section id="source-view">
|
| 94 |
+
<div class="toolbar"><div><h2>数据来源</h2><p>选择一个来源后再加载视频。</p></div></div>
|
| 95 |
+
<div class="source-grid" id="source-grid"></div>
|
| 96 |
+
</section>
|
| 97 |
+
<section class="hidden" id="review-view">
|
| 98 |
+
<div class="toolbar">
|
| 99 |
+
<div><button class="button" id="back-button" type="button">返回来源</button><h2 id="source-title" style="margin-top:14px"></h2><p id="source-count"></p></div>
|
| 100 |
+
<div class="actions"><button class="button" id="clear-filter-button" type="button">清除筛选</button></div>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="review-controls">
|
| 103 |
+
<label>按文件名或标注搜索<input id="search-input" type="search" autocomplete="off" placeholder="输入 sample id、路径或现有标注"></label>
|
| 104 |
+
<label>审核状态<select id="decision-filter"><option value="all">全部</option><option value="pending">待定</option><option value="keep">保留</option><option value="reject">排除</option></select></label>
|
| 105 |
+
<label>每页<select id="page-size"><option value="8">8</option><option value="12" selected>12</option><option value="20">20</option></select></label>
|
| 106 |
+
</div>
|
| 107 |
+
<div class="video-grid" id="video-grid"></div>
|
| 108 |
+
<div class="pagination" id="pagination"></div>
|
| 109 |
+
</section>
|
| 110 |
+
</main>
|
| 111 |
+
<script>
|
| 112 |
+
(() => {
|
| 113 |
+
const catalog = Array.isArray(window.WORLDMODELBENCH_CATALOG) ? window.WORLDMODELBENCH_CATALOG : [];
|
| 114 |
+
const storageKey = "worldmodelbench-review-v1";
|
| 115 |
+
const annotatorKey = "worldmodelbench-review-annotator-v1";
|
| 116 |
+
const fields = ["decision", "track", "scene", "spatialAbility", "perspective", "textCaption"];
|
| 117 |
+
const state = { source: null, query: "", decision: "all", page: 1, pageSize: 12, drafts: loadDrafts() };
|
| 118 |
+
const sourceView = document.querySelector("#source-view");
|
| 119 |
+
const reviewView = document.querySelector("#review-view");
|
| 120 |
+
const sourceGrid = document.querySelector("#source-grid");
|
| 121 |
+
const videoGrid = document.querySelector("#video-grid");
|
| 122 |
+
const totalCount = document.querySelector("#total-count");
|
| 123 |
+
const sourceTitle = document.querySelector("#source-title");
|
| 124 |
+
const sourceCount = document.querySelector("#source-count");
|
| 125 |
+
const pagination = document.querySelector("#pagination");
|
| 126 |
+
const annotatorInput = document.querySelector("#annotator-input");
|
| 127 |
+
const serviceStatus = document.querySelector("#service-status");
|
| 128 |
+
|
| 129 |
+
function loadDrafts() {
|
| 130 |
+
try { return JSON.parse(localStorage.getItem(storageKey)) || {}; } catch { return {}; }
|
| 131 |
+
}
|
| 132 |
+
function saveDrafts() { localStorage.setItem(storageKey, JSON.stringify(state.drafts)); }
|
| 133 |
+
function draftFor(item) { return state.drafts[item.videoPath] || { decision: "pending" }; }
|
| 134 |
+
function suggestion(item, key) { return item[key] || ""; }
|
| 135 |
+
function el(tag, options = {}, children = []) {
|
| 136 |
+
const node = document.createElement(tag);
|
| 137 |
+
Object.entries(options).forEach(([key, value]) => {
|
| 138 |
+
if (key === "className") node.className = value;
|
| 139 |
+
else if (key === "text") node.textContent = value;
|
| 140 |
+
else if (key === "htmlFor") node.htmlFor = value;
|
| 141 |
+
else if (key.startsWith("on")) node.addEventListener(key.slice(2).toLowerCase(), value);
|
| 142 |
+
else if (value !== undefined && value !== null) node.setAttribute(key, value);
|
| 143 |
+
});
|
| 144 |
+
children.forEach(child => node.append(child));
|
| 145 |
+
return node;
|
| 146 |
+
}
|
| 147 |
+
function sources() {
|
| 148 |
+
const counts = new Map();
|
| 149 |
+
catalog.forEach(item => counts.set(item.sourceDataset, (counts.get(item.sourceDataset) || 0) + 1));
|
| 150 |
+
return [...counts.entries()].sort((a, b) => a[0].localeCompare(b[0], "zh-CN"));
|
| 151 |
+
}
|
| 152 |
+
function renderSources() {
|
| 153 |
+
sourceGrid.replaceChildren();
|
| 154 |
+
sources().forEach(([source, count]) => {
|
| 155 |
+
const card = el("button", { className: "source-card", type: "button", onClick: () => selectSource(source) }, [
|
| 156 |
+
el("h3", { text: source }), el("span", { text: `${count} 个视频` })
|
| 157 |
+
]);
|
| 158 |
+
sourceGrid.append(card);
|
| 159 |
+
});
|
| 160 |
+
totalCount.textContent = `目录中共有 ${catalog.length} 个完整原视频,按来源分组审核`;
|
| 161 |
+
}
|
| 162 |
+
function selectSource(source) {
|
| 163 |
+
state.source = source; state.query = ""; state.decision = "all"; state.page = 1;
|
| 164 |
+
document.querySelector("#search-input").value = "";
|
| 165 |
+
document.querySelector("#decision-filter").value = "all";
|
| 166 |
+
sourceView.classList.add("hidden"); reviewView.classList.remove("hidden");
|
| 167 |
+
sourceTitle.textContent = source;
|
| 168 |
+
renderReview();
|
| 169 |
+
window.scrollTo({ top: 0, behavior: "instant" });
|
| 170 |
+
}
|
| 171 |
+
function visibleItems() {
|
| 172 |
+
const query = state.query.trim().toLocaleLowerCase();
|
| 173 |
+
return catalog.filter(item => {
|
| 174 |
+
if (item.sourceDataset !== state.source) return false;
|
| 175 |
+
const draft = draftFor(item);
|
| 176 |
+
if (state.decision !== "all" && (draft.decision || "pending") !== state.decision) return false;
|
| 177 |
+
if (!query) return true;
|
| 178 |
+
return [item.id, item.videoPath, item.suggestedTrack, item.scene, item.spatialAbility, item.perspective, item.caption]
|
| 179 |
+
.join(" ").toLocaleLowerCase().includes(query);
|
| 180 |
+
});
|
| 181 |
+
}
|
| 182 |
+
function labelFor(key) { return ({ track: "Track", scene: "Scene", spatialAbility: "Spatial Ability", perspective: "Perspective", textCaption: "Text Caption" })[key]; }
|
| 183 |
+
function inputField(item, key, wide = false) {
|
| 184 |
+
const draft = draftFor(item);
|
| 185 |
+
const input = key === "textCaption" ? el("textarea") : el("input", { type: "text" });
|
| 186 |
+
input.value = draft[key] || "";
|
| 187 |
+
input.placeholder = suggestion(item, key === "textCaption" ? "caption" : key);
|
| 188 |
+
input.setAttribute("data-field", key);
|
| 189 |
+
input.addEventListener("input", () => saveField(item, key, input.value, input.closest(".review-card")));
|
| 190 |
+
return el("label", { className: wide ? "wide" : "" }, [el("span", { text: labelFor(key) }), input]);
|
| 191 |
+
}
|
| 192 |
+
function saveField(item, key, value, card) {
|
| 193 |
+
const previous = draftFor(item);
|
| 194 |
+
state.drafts[item.videoPath] = { ...previous, [key]: value, updatedAt: new Date().toISOString() };
|
| 195 |
+
saveDrafts();
|
| 196 |
+
const indicator = card.querySelector(".draft-state");
|
| 197 |
+
indicator.textContent = "已保存"; indicator.classList.add("saved");
|
| 198 |
+
}
|
| 199 |
+
function setSubmissionState(card, text, kind = "") {
|
| 200 |
+
const status = card.querySelector(".submit-state");
|
| 201 |
+
status.textContent = text;
|
| 202 |
+
status.className = `submit-state ${kind}`;
|
| 203 |
+
}
|
| 204 |
+
async function submitCard(item, card, button) {
|
| 205 |
+
const annotator = annotatorInput.value.trim();
|
| 206 |
+
if (!annotator) {
|
| 207 |
+
annotatorInput.focus();
|
| 208 |
+
setSubmissionState(card, "请先填写标注者", "error");
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
const draft = draftFor(item);
|
| 212 |
+
button.disabled = true;
|
| 213 |
+
setSubmissionState(card, "正在提交");
|
| 214 |
+
try {
|
| 215 |
+
const response = await fetch("/api/submissions", {
|
| 216 |
+
method: "POST",
|
| 217 |
+
headers: { "Content-Type": "application/json" },
|
| 218 |
+
body: JSON.stringify({ annotator, video_path: item.videoPath, decision: draft.decision || "pending", track: draft.track || "", scene: draft.scene || "", spatial_ability: draft.spatialAbility || "", perspective: draft.perspective || "", text_caption: draft.textCaption || "" })
|
| 219 |
+
});
|
| 220 |
+
if (response.status === 404) {
|
| 221 |
+
state.drafts[item.videoPath] = { ...draft, localSavedAt: new Date().toISOString(), updatedAt: new Date().toISOString() };
|
| 222 |
+
saveDrafts();
|
| 223 |
+
setSubmissionState(card, "已保存到本机", "success");
|
| 224 |
+
return;
|
| 225 |
+
}
|
| 226 |
+
const result = await response.json().catch(() => ({}));
|
| 227 |
+
if (!response.ok) throw new Error(result.error || "提交失败");
|
| 228 |
+
state.drafts[item.videoPath] = { ...draft, submittedAt: result.submitted_at, submissionId: result.submission_id, updatedAt: new Date().toISOString() };
|
| 229 |
+
saveDrafts();
|
| 230 |
+
setSubmissionState(card, "已提交", "success");
|
| 231 |
+
} catch (error) {
|
| 232 |
+
setSubmissionState(card, error.message || "服务未连接,草稿已保留", "error");
|
| 233 |
+
} finally {
|
| 234 |
+
button.disabled = false;
|
| 235 |
+
}
|
| 236 |
+
}
|
| 237 |
+
function decisionControl(item, card) {
|
| 238 |
+
const container = el("fieldset", { className: "decision", "aria-label": "审核决定" });
|
| 239 |
+
[ ["pending", "待定"], ["keep", "保留"], ["reject", "排除"] ].forEach(([value, name]) => {
|
| 240 |
+
const id = `decision-${safeId(item.videoPath)}-${value}`;
|
| 241 |
+
const input = el("input", { id, name: `decision-${safeId(item.videoPath)}`, type: "radio", value });
|
| 242 |
+
input.checked = (draftFor(item).decision || "pending") === value;
|
| 243 |
+
input.addEventListener("change", () => saveField(item, "decision", value, card));
|
| 244 |
+
container.append(el("label", { htmlFor: id, text: name }, [input]));
|
| 245 |
+
});
|
| 246 |
+
return container;
|
| 247 |
+
}
|
| 248 |
+
function safeId(value) { let hash = 0; for (let i = 0; i < value.length; i++) hash = ((hash << 5) - hash) + value.charCodeAt(i) | 0; return Math.abs(hash); }
|
| 249 |
+
function cardFor(item) {
|
| 250 |
+
const card = el("article", { className: "review-card" });
|
| 251 |
+
const video = el("video", { controls: "", preload: "none", playsinline: "", poster: item.initialFrameUrl || null, src: item.videoUrl });
|
| 252 |
+
const body = el("div", { className: "card-body" });
|
| 253 |
+
const heading = el("div", { className: "sample-heading" }, [el("h3", { text: item.id }), el("span", { className: "draft-state", text: state.drafts[item.videoPath] ? "已保存" : "未标注" })]);
|
| 254 |
+
body.append(heading, decisionControl(item, card));
|
| 255 |
+
const fieldGrid = el("div", { className: "fields" });
|
| 256 |
+
["track", "scene", "spatialAbility", "perspective"].forEach(key => fieldGrid.append(inputField(item, key)));
|
| 257 |
+
const datasource = el("input", { type: "text", value: item.sourceDataset, readonly: "" });
|
| 258 |
+
fieldGrid.append(el("label", { className: "wide" }, [el("span", { text: "Data Source" }), datasource]));
|
| 259 |
+
fieldGrid.append(inputField(item, "textCaption", true));
|
| 260 |
+
const submitButton = el("button", { className: "button primary", type: "button", text: "提交此条", onClick: event => submitCard(item, card, event.currentTarget) });
|
| 261 |
+
const submitted = draftFor(item).submittedAt ? "已提交" : draftFor(item).localSavedAt ? "已保存到本机" : "本地草稿";
|
| 262 |
+
body.append(fieldGrid, el("div", { className: "submit-row" }, [submitButton, el("span", { className: `submit-state ${draftFor(item).submittedAt ? "success" : ""}`, text: submitted })]), el("p", { className: "metadata", text: item.videoPath }));
|
| 263 |
+
card.append(video, body);
|
| 264 |
+
return card;
|
| 265 |
+
}
|
| 266 |
+
function renderReview() {
|
| 267 |
+
const items = visibleItems();
|
| 268 |
+
const pages = Math.max(1, Math.ceil(items.length / state.pageSize));
|
| 269 |
+
state.page = Math.min(state.page, pages);
|
| 270 |
+
const start = (state.page - 1) * state.pageSize;
|
| 271 |
+
sourceCount.textContent = `显示 ${items.length} 个匹配视频,第 ${state.page} / ${pages} 页`;
|
| 272 |
+
videoGrid.replaceChildren();
|
| 273 |
+
if (items.length === 0) videoGrid.append(el("p", { className: "empty", text: "没有符合当前筛选条件的视频。" }));
|
| 274 |
+
else items.slice(start, start + state.pageSize).forEach(item => videoGrid.append(cardFor(item)));
|
| 275 |
+
pagination.replaceChildren();
|
| 276 |
+
const previous = el("button", { className: "icon-button", type: "button", text: "上一页", "aria-label": "上一页", onClick: () => { if (state.page > 1) { state.page--; renderReview(); window.scrollTo({ top: 0, behavior: "instant" }); } } });
|
| 277 |
+
previous.disabled = state.page === 1;
|
| 278 |
+
const next = el("button", { className: "icon-button", type: "button", text: "下一页", "aria-label": "下一页", onClick: () => { if (state.page < pages) { state.page++; renderReview(); window.scrollTo({ top: 0, behavior: "instant" }); } } });
|
| 279 |
+
next.disabled = state.page === pages;
|
| 280 |
+
pagination.append(previous, el("span", { className: "page-status", text: `${state.page} / ${pages}` }), next);
|
| 281 |
+
}
|
| 282 |
+
function exportDrafts() {
|
| 283 |
+
const rows = catalog.map(item => {
|
| 284 |
+
const draft = draftFor(item);
|
| 285 |
+
return { sample_id: item.id, video_path: item.videoPath, video_url: item.videoUrl, data_source: item.sourceDataset, annotator: annotatorInput.value.trim() || "", decision: draft.decision || "pending", track: draft.track || "", scene: draft.scene || "", spatial_ability: draft.spatialAbility || "", perspective: draft.perspective || "", text_caption: draft.textCaption || "", submitted_at: draft.submittedAt || null, local_saved_at: draft.localSavedAt || null, updated_at: draft.updatedAt || null };
|
| 286 |
+
}).filter(row => row.decision !== "pending" || row.track || row.scene || row.spatial_ability || row.perspective || row.text_caption);
|
| 287 |
+
const blob = new Blob([JSON.stringify({ schema_version: "worldmodelbench-web-review-v1", exported_at: new Date().toISOString(), annotations: rows }, null, 2)], { type: "application/json" });
|
| 288 |
+
const link = document.createElement("a"); link.href = URL.createObjectURL(blob); link.download = `worldmodelbench-review-${new Date().toISOString().slice(0, 10)}.json`; link.click(); URL.revokeObjectURL(link.href);
|
| 289 |
+
}
|
| 290 |
+
function importDrafts(file) {
|
| 291 |
+
const reader = new FileReader();
|
| 292 |
+
reader.onload = () => {
|
| 293 |
+
try {
|
| 294 |
+
const payload = JSON.parse(String(reader.result));
|
| 295 |
+
const rows = Array.isArray(payload) ? payload : payload.annotations;
|
| 296 |
+
if (!Array.isArray(rows)) throw new Error("invalid_annotation_file");
|
| 297 |
+
const byPath = new Map(catalog.map(item => [item.videoPath, item]));
|
| 298 |
+
rows.forEach(row => {
|
| 299 |
+
const item = byPath.get(row.video_path);
|
| 300 |
+
if (!item) return;
|
| 301 |
+
state.drafts[item.videoPath] = { decision: row.decision || "pending", track: row.track || "", scene: row.scene || "", spatialAbility: row.spatial_ability || "", perspective: row.perspective || "", textCaption: row.text_caption || "", updatedAt: row.updated_at || new Date().toISOString() };
|
| 302 |
+
});
|
| 303 |
+
saveDrafts(); if (state.source) renderReview();
|
| 304 |
+
} catch { alert("无法读取该标注 JSON。请使用本页面导出的文件。"); }
|
| 305 |
+
};
|
| 306 |
+
reader.readAsText(file, "utf-8");
|
| 307 |
+
}
|
| 308 |
+
document.querySelector("#back-button").addEventListener("click", () => { reviewView.classList.add("hidden"); sourceView.classList.remove("hidden"); state.source = null; });
|
| 309 |
+
document.querySelector("#search-input").addEventListener("input", event => { state.query = event.target.value; state.page = 1; renderReview(); });
|
| 310 |
+
document.querySelector("#decision-filter").addEventListener("change", event => { state.decision = event.target.value; state.page = 1; renderReview(); });
|
| 311 |
+
document.querySelector("#page-size").addEventListener("change", event => { state.pageSize = Number(event.target.value); state.page = 1; renderReview(); });
|
| 312 |
+
document.querySelector("#clear-filter-button").addEventListener("click", () => { state.query = ""; state.decision = "all"; state.page = 1; document.querySelector("#search-input").value = ""; document.querySelector("#decision-filter").value = "all"; renderReview(); });
|
| 313 |
+
document.querySelector("#export-button").addEventListener("click", exportDrafts);
|
| 314 |
+
document.querySelector("#import-button").addEventListener("click", () => document.querySelector("#import-input").click());
|
| 315 |
+
document.querySelector("#import-input").addEventListener("change", event => { if (event.target.files[0]) importDrafts(event.target.files[0]); event.target.value = ""; });
|
| 316 |
+
annotatorInput.value = localStorage.getItem(annotatorKey) || "";
|
| 317 |
+
annotatorInput.addEventListener("input", () => localStorage.setItem(annotatorKey, annotatorInput.value));
|
| 318 |
+
fetch("/api/health", { cache: "no-store" }).then(response => response.ok ? response.json() : Promise.reject()).then(() => { serviceStatus.textContent = "共享提交已连接"; serviceStatus.classList.add("connected"); }).catch(() => { serviceStatus.textContent = "本地草稿模式"; });
|
| 319 |
+
renderSources();
|
| 320 |
+
})();
|
| 321 |
+
</script>
|
| 322 |
+
</body>
|
| 323 |
+
</html>
|