Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -266,35 +266,39 @@ def analyze_pushup_video(video_path: str, save_annotated: bool = True, annotated
|
|
| 266 |
# -----------------------
|
| 267 |
# Gradio wrapper
|
| 268 |
# -----------------------
|
| 269 |
-
def gradio_run(
|
|
|
|
| 270 |
workdir = tempfile.mkdtemp()
|
| 271 |
in_path = os.path.join(workdir, "input.mp4")
|
| 272 |
-
shutil.copy(
|
| 273 |
|
| 274 |
out_path = os.path.join(workdir, "annotated.mp4")
|
| 275 |
result = analyze_pushup_video(in_path, save_annotated=True, annotated_out_path=out_path)
|
| 276 |
|
| 277 |
if not result["ok"]:
|
| 278 |
-
return "
|
| 279 |
|
| 280 |
-
|
| 281 |
if result["rep_events"]:
|
| 282 |
avg_prob = sum(r["prob"] for r in result["rep_events"]) / len(result["rep_events"])
|
| 283 |
-
summary += f"Avg rep probability: {avg_prob:.2f}\n"
|
| 284 |
|
| 285 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
|
| 288 |
demo = gr.Interface(
|
| 289 |
fn=gradio_run,
|
| 290 |
-
inputs=gr.Video(label="Upload pushup video"),
|
| 291 |
-
outputs=
|
| 292 |
-
|
| 293 |
-
gr.Video(label="Annotated output"),
|
| 294 |
-
gr.JSON(label="Per-rep details"),
|
| 295 |
-
],
|
| 296 |
-
api_name="analyze", # add this
|
| 297 |
)
|
| 298 |
|
| 299 |
if __name__ == "__main__":
|
|
|
|
| 300 |
demo.launch()
|
|
|
|
| 266 |
# -----------------------
|
| 267 |
# Gradio wrapper
|
| 268 |
# -----------------------
|
| 269 |
+
def gradio_run(video_file_path):
|
| 270 |
+
# video_file_path is a REAL file path on the HF server (because type="filepath")
|
| 271 |
workdir = tempfile.mkdtemp()
|
| 272 |
in_path = os.path.join(workdir, "input.mp4")
|
| 273 |
+
shutil.copy(video_file_path, in_path)
|
| 274 |
|
| 275 |
out_path = os.path.join(workdir, "annotated.mp4")
|
| 276 |
result = analyze_pushup_video(in_path, save_annotated=True, annotated_out_path=out_path)
|
| 277 |
|
| 278 |
if not result["ok"]:
|
| 279 |
+
return {"ok": False, "error": str(result["error"]), "rep_count": 0, "avg_prob": 0.0, "rep_events": []}
|
| 280 |
|
| 281 |
+
avg_prob = 0.0
|
| 282 |
if result["rep_events"]:
|
| 283 |
avg_prob = sum(r["prob"] for r in result["rep_events"]) / len(result["rep_events"])
|
|
|
|
| 284 |
|
| 285 |
+
# IMPORTANT: return only JSON-ish data (browser can render it easily)
|
| 286 |
+
return {
|
| 287 |
+
"ok": True,
|
| 288 |
+
"error": None,
|
| 289 |
+
"rep_count": int(result["rep_count"]),
|
| 290 |
+
"avg_prob": float(avg_prob),
|
| 291 |
+
"rep_events": result["rep_events"],
|
| 292 |
+
}
|
| 293 |
|
| 294 |
|
| 295 |
demo = gr.Interface(
|
| 296 |
fn=gradio_run,
|
| 297 |
+
inputs=gr.Video(label="Upload pushup video", type="filepath"),
|
| 298 |
+
outputs=gr.JSON(label="Result"),
|
| 299 |
+
api_name="analyze", # gives you a stable endpoint name
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
)
|
| 301 |
|
| 302 |
if __name__ == "__main__":
|
| 303 |
+
demo.queue()
|
| 304 |
demo.launch()
|