YTShortMakerArchx commited on
Commit
d3cd464
·
verified ·
1 Parent(s): 2c309e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -3
app.py CHANGED
@@ -85,9 +85,9 @@ QWEN_SPACES = [
85
  ]
86
  FFMPEG_SPACES = [
87
  "https://archnemix-ffmpeg-polyglot-ffmpeg-rust.hf.space",
88
- # "https://archnemix-ffmpeg-polyglot-ffmpeg-nodejs.hf.space",
89
- # "https://archnemix-ffmpeg-polyglot-ffmpeg-GO.hf.space",
90
- # "https://archnemix-ffmpeg-polyglot-ffmpeg-python.hf.space",
91
  ]
92
 
93
  non_used_spaces = [
@@ -1481,6 +1481,57 @@ async def get_capacity():
1481
  "total_in_memory": len(pipelines),
1482
  }
1483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1484
  if __name__ == "__main__":
1485
  import uvicorn
1486
  uvicorn.run(app, host="0.0.0.0", port=7860, timeout_keep_alive=180)
 
85
  ]
86
  FFMPEG_SPACES = [
87
  "https://archnemix-ffmpeg-polyglot-ffmpeg-rust.hf.space",
88
+ "https://archnemix-ffmpeg-polyglot-ffmpeg-nodejs.hf.space",
89
+ "https://archnemix-ffmpeg-polyglot-ffmpeg-GO.hf.space",
90
+ "https://archnemix-ffmpeg-polyglot-ffmpeg-python.hf.space",
91
  ]
92
 
93
  non_used_spaces = [
 
1481
  "total_in_memory": len(pipelines),
1482
  }
1483
 
1484
+ @app.post("/pipeline/{pipeline_id}/cancel/{stage}")
1485
+ async def cancel_stage(pipeline_id: str, stage: str):
1486
+ if stage not in (Stage.TTS, Stage.ALIGN, Stage.VIDEO):
1487
+ raise HTTPException(400, {
1488
+ "error": "invalid_stage",
1489
+ "detail": f"Stage must be one of: tts, align, video",
1490
+ })
1491
+
1492
+ p = _pipeline_or_404(pipeline_id)
1493
+ s = p["stages"][stage]
1494
+
1495
+ if s["status"] != StageStatus.RUNNING:
1496
+ raise HTTPException(400, {
1497
+ "error": "stage_not_running",
1498
+ "detail": f"Stage '{stage}' is not currently running (status: {s['status']}). Nothing to cancel.",
1499
+ })
1500
+
1501
+ url = s.get("backend_url")
1502
+ jid = s.get("backend_job_id")
1503
+ btype = s.get("backend_type")
1504
+
1505
+ if url and jid:
1506
+ try:
1507
+ if btype == "ffmpeg":
1508
+ await http().delete(
1509
+ f"{url}/job/{jid}",
1510
+ headers={"X-APP-KEY": APP_KEY},
1511
+ timeout=10.0,
1512
+ )
1513
+ else:
1514
+ await http().post(
1515
+ f"{url}/cancel/{jid}",
1516
+ json={"client_id": _client_id(pipeline_id)},
1517
+ timeout=10.0,
1518
+ )
1519
+ logger.info(f"Pipeline {pipeline_id[:8]}: user cancelled {stage} job {jid} on {url}")
1520
+ except Exception as e:
1521
+ # Backend cancel failed but we still mark it failed locally
1522
+ logger.warning(f"Pipeline {pipeline_id[:8]}: cancel request to backend failed ({e}) — marking failed anyway")
1523
+
1524
+ s["status"] = StageStatus.FAILED
1525
+ s["error"] = "Cancelled by user"
1526
+
1527
+ return {
1528
+ "ok": True,
1529
+ "pipeline_id": pipeline_id,
1530
+ "stage": stage,
1531
+ "job_id": jid,
1532
+ "backend_url": url,
1533
+ }
1534
+
1535
  if __name__ == "__main__":
1536
  import uvicorn
1537
  uvicorn.run(app, host="0.0.0.0", port=7860, timeout_keep_alive=180)