Spaces:
Sleeping
Sleeping
deploy rater (Docker/FastAPI): registration + completeness gate + /api/submit → dataset
Browse files
app.py
CHANGED
|
@@ -58,6 +58,22 @@ def _is_admin(name: str) -> bool:
|
|
| 58 |
return (name or "").strip().lower() in ADMIN_NAMES
|
| 59 |
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def _count_scores(cases) -> int:
|
| 62 |
n = 0
|
| 63 |
for c in cases or []:
|
|
@@ -99,6 +115,7 @@ async def submit(req: Request):
|
|
| 99 |
raise HTTPException(400, f"invalid JSON: {e}")
|
| 100 |
|
| 101 |
name, email = _validate_rater(payload)
|
|
|
|
| 102 |
|
| 103 |
rubric = payload.get("rubric") or []
|
| 104 |
cases = payload.get("cases") or []
|
|
@@ -207,6 +224,7 @@ async def save_progress(req: Request):
|
|
| 207 |
raise HTTPException(400, f"invalid JSON: {e}")
|
| 208 |
|
| 209 |
name, email = _validate_rater(payload)
|
|
|
|
| 210 |
cases = payload.get("cases") or []
|
| 211 |
n_scores = _count_scores(cases)
|
| 212 |
is_admin = _is_admin(name)
|
|
|
|
| 58 |
return (name or "").strip().lower() in ADMIN_NAMES
|
| 59 |
|
| 60 |
|
| 61 |
+
def _normalize_legacy_models(payload: dict) -> int:
|
| 62 |
+
"""Rewrite any `model: "huobao"` (and matching `_huobao.mp4` paths) to
|
| 63 |
+
`univa` on the way in. Older clients with stale localStorage keep
|
| 64 |
+
re-introducing the old name on save; this silently fixes it server-side
|
| 65 |
+
so the dataset stays clean. Returns the number of fields rewritten."""
|
| 66 |
+
n = 0
|
| 67 |
+
for c in payload.get("cases") or []:
|
| 68 |
+
for v in c.get("videos") or []:
|
| 69 |
+
if v.get("model") == "huobao":
|
| 70 |
+
v["model"] = "univa"; n += 1
|
| 71 |
+
p = v.get("path") or ""
|
| 72 |
+
if "_huobao.mp4" in p:
|
| 73 |
+
v["path"] = p.replace("_huobao.mp4", "_univa.mp4"); n += 1
|
| 74 |
+
return n
|
| 75 |
+
|
| 76 |
+
|
| 77 |
def _count_scores(cases) -> int:
|
| 78 |
n = 0
|
| 79 |
for c in cases or []:
|
|
|
|
| 115 |
raise HTTPException(400, f"invalid JSON: {e}")
|
| 116 |
|
| 117 |
name, email = _validate_rater(payload)
|
| 118 |
+
_normalize_legacy_models(payload) # rewrite any stale `huobao` → `univa`
|
| 119 |
|
| 120 |
rubric = payload.get("rubric") or []
|
| 121 |
cases = payload.get("cases") or []
|
|
|
|
| 224 |
raise HTTPException(400, f"invalid JSON: {e}")
|
| 225 |
|
| 226 |
name, email = _validate_rater(payload)
|
| 227 |
+
_normalize_legacy_models(payload) # rewrite any stale `huobao` → `univa`
|
| 228 |
cases = payload.get("cases") or []
|
| 229 |
n_scores = _count_scores(cases)
|
| 230 |
is_admin = _is_admin(name)
|