Update app.py
Browse files
app.py
CHANGED
|
@@ -493,6 +493,10 @@ if LEADS_DATASET and HF_TOKEN:
|
|
| 493 |
log.warning(f"[users] user log is off: {type(e).__name__}: {e}")
|
| 494 |
|
| 495 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
def track(event, profile, **extra):
|
| 497 |
if _leads is None or profile is None:
|
| 498 |
return
|
|
@@ -509,8 +513,11 @@ def track(event, profile, **extra):
|
|
| 509 |
"avatar": profile.picture,
|
| 510 |
"orgs": [o.get("preferred_username") or o.get("name") for o in orgs if isinstance(o, dict)],
|
| 511 |
"admin": is_admin(profile.username),
|
| 512 |
-
**extra,
|
| 513 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
with _leads.lock:
|
| 515 |
with open(_leads_file, "a") as f:
|
| 516 |
f.write(json.dumps(row, default=str) + "\n")
|
|
@@ -730,7 +737,7 @@ def settings_chips(drama):
|
|
| 730 |
|
| 731 |
# ---------- main handler ----------
|
| 732 |
|
| 733 |
-
def run(video, mood, excited, angry, updates, profile: gr.OAuthProfile | None):
|
| 734 |
def stop(message):
|
| 735 |
raise gr.Error(message, print_exception=False)
|
| 736 |
|
|
@@ -747,7 +754,7 @@ def run(video, mood, excited, angry, updates, profile: gr.OAuthProfile | None):
|
|
| 747 |
ctx = Run(profile.username)
|
| 748 |
ctx.log(f"new run: user={ctx.user} admin={is_admin(ctx.user)} drama={drama} flow={FLOW}")
|
| 749 |
counted = False
|
| 750 |
-
clip = {"drama": drama, "marketing_opt_in": bool(updates)}
|
| 751 |
try:
|
| 752 |
take_quota(ctx.user)
|
| 753 |
counted = True
|
|
@@ -790,7 +797,8 @@ def run(video, mood, excited, angry, updates, profile: gr.OAuthProfile | None):
|
|
| 790 |
ctx.stage = "watermark"
|
| 791 |
result = watermark(raw, workdir, ctx)
|
| 792 |
report(ctx, "SUCCESS")
|
| 793 |
-
track("run", profile, outcome="success", run_id=ctx.id,
|
|
|
|
| 794 |
yield result, status_html("done", f"Done in {ctx.elapsed()}", 5,
|
| 795 |
settings_chips(drama))
|
| 796 |
|
|
@@ -802,7 +810,8 @@ def run(video, mood, excited, angry, updates, profile: gr.OAuthProfile | None):
|
|
| 802 |
track("limit_hit", profile, run_id=ctx.id, **clip)
|
| 803 |
else:
|
| 804 |
report(ctx, "FAILED", e.category, e.detail)
|
| 805 |
-
track("run", profile, outcome="failed", error=e.category,
|
|
|
|
| 806 |
yield None, status_html("error", e.user_message, note=f"Reference: {ctx.id}")
|
| 807 |
stop(f"{e.user_message} (ref: {ctx.id})")
|
| 808 |
except gr.Error:
|
|
@@ -812,7 +821,8 @@ def run(video, mood, excited, angry, updates, profile: gr.OAuthProfile | None):
|
|
| 812 |
refund_quota(ctx.user)
|
| 813 |
ctx.log(f"UNEXPECTED {type(e).__name__}: {e}\n{traceback.format_exc()}", logging.ERROR)
|
| 814 |
report(ctx, "FAILED", "UNEXPECTED", f"{type(e).__name__}: {e}")
|
| 815 |
-
track("run", profile, outcome="failed", error="UNEXPECTED", run_id=ctx.id,
|
|
|
|
| 816 |
yield None, status_html("error", "Something unexpected went wrong.", note=f"Reference: {ctx.id}")
|
| 817 |
stop(f"Something unexpected went wrong. (ref: {ctx.id})")
|
| 818 |
|
|
@@ -1295,7 +1305,7 @@ with gr.Blocks(title=PAGE_TITLE) as demo:
|
|
| 1295 |
demo.load(on_visit, inputs=None, outputs=None, api_visibility="private", show_progress="hidden")
|
| 1296 |
go.click(
|
| 1297 |
run,
|
| 1298 |
-
inputs=[video_in, mood, excited, angry, updates],
|
| 1299 |
outputs=[video_out, status_out],
|
| 1300 |
concurrency_limit=2,
|
| 1301 |
api_visibility="private",
|
|
|
|
| 493 |
log.warning(f"[users] user log is off: {type(e).__name__}: {e}")
|
| 494 |
|
| 495 |
|
| 496 |
+
TRACK_COLUMNS = ["outcome", "error", "error_message", "preset", "happy", "sad", "excited", "angry",
|
| 497 |
+
"clip_seconds", "processing_seconds", "marketing_opt_in", "run_id", "job_id"]
|
| 498 |
+
|
| 499 |
+
|
| 500 |
def track(event, profile, **extra):
|
| 501 |
if _leads is None or profile is None:
|
| 502 |
return
|
|
|
|
| 513 |
"avatar": profile.picture,
|
| 514 |
"orgs": [o.get("preferred_username") or o.get("name") for o in orgs if isinstance(o, dict)],
|
| 515 |
"admin": is_admin(profile.username),
|
|
|
|
| 516 |
}
|
| 517 |
+
drama = extra.pop("drama", None) or {}
|
| 518 |
+
row.update({k: None for k in TRACK_COLUMNS}) # same columns on every row, for the viewer/SQL
|
| 519 |
+
row.update({k: float(drama.get(k, 0)) for k in ("happy", "sad", "excited", "angry")} if drama else {})
|
| 520 |
+
row.update(extra)
|
| 521 |
with _leads.lock:
|
| 522 |
with open(_leads_file, "a") as f:
|
| 523 |
f.write(json.dumps(row, default=str) + "\n")
|
|
|
|
| 737 |
|
| 738 |
# ---------- main handler ----------
|
| 739 |
|
| 740 |
+
def run(video, mood, excited, angry, updates, preset_name, profile: gr.OAuthProfile | None):
|
| 741 |
def stop(message):
|
| 742 |
raise gr.Error(message, print_exception=False)
|
| 743 |
|
|
|
|
| 754 |
ctx = Run(profile.username)
|
| 755 |
ctx.log(f"new run: user={ctx.user} admin={is_admin(ctx.user)} drama={drama} flow={FLOW}")
|
| 756 |
counted = False
|
| 757 |
+
clip = {"preset": preset_name or "Custom", "drama": drama, "marketing_opt_in": bool(updates)}
|
| 758 |
try:
|
| 759 |
take_quota(ctx.user)
|
| 760 |
counted = True
|
|
|
|
| 797 |
ctx.stage = "watermark"
|
| 798 |
result = watermark(raw, workdir, ctx)
|
| 799 |
report(ctx, "SUCCESS")
|
| 800 |
+
track("run", profile, outcome="success", run_id=ctx.id, job_id=ctx.facts.get("job"),
|
| 801 |
+
processing_seconds=round(time.time() - ctx.started), **clip)
|
| 802 |
yield result, status_html("done", f"Done in {ctx.elapsed()}", 5,
|
| 803 |
settings_chips(drama))
|
| 804 |
|
|
|
|
| 810 |
track("limit_hit", profile, run_id=ctx.id, **clip)
|
| 811 |
else:
|
| 812 |
report(ctx, "FAILED", e.category, e.detail)
|
| 813 |
+
track("run", profile, outcome="failed", error=e.category, error_message=e.user_message,
|
| 814 |
+
run_id=ctx.id, job_id=ctx.facts.get("job"), **clip)
|
| 815 |
yield None, status_html("error", e.user_message, note=f"Reference: {ctx.id}")
|
| 816 |
stop(f"{e.user_message} (ref: {ctx.id})")
|
| 817 |
except gr.Error:
|
|
|
|
| 821 |
refund_quota(ctx.user)
|
| 822 |
ctx.log(f"UNEXPECTED {type(e).__name__}: {e}\n{traceback.format_exc()}", logging.ERROR)
|
| 823 |
report(ctx, "FAILED", "UNEXPECTED", f"{type(e).__name__}: {e}")
|
| 824 |
+
track("run", profile, outcome="failed", error="UNEXPECTED", run_id=ctx.id,
|
| 825 |
+
job_id=ctx.facts.get("job"), **clip)
|
| 826 |
yield None, status_html("error", "Something unexpected went wrong.", note=f"Reference: {ctx.id}")
|
| 827 |
stop(f"Something unexpected went wrong. (ref: {ctx.id})")
|
| 828 |
|
|
|
|
| 1305 |
demo.load(on_visit, inputs=None, outputs=None, api_visibility="private", show_progress="hidden")
|
| 1306 |
go.click(
|
| 1307 |
run,
|
| 1308 |
+
inputs=[video_in, mood, excited, angry, updates, preset],
|
| 1309 |
outputs=[video_out, status_out],
|
| 1310 |
concurrency_limit=2,
|
| 1311 |
api_visibility="private",
|