Spaces:
Running on Zero
Running on Zero
Expose live audio generation API route
Browse files
app.py
CHANGED
|
@@ -772,6 +772,25 @@ def _patched_create_app(blocks, **kwargs):
|
|
| 772 |
@fa_app.get("/respite/specs")
|
| 773 |
def _s(): return JSONResponse({**API_SPECS, "runtime": _get_runtime_specs()})
|
| 774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
@fa_app.get("/respite/search")
|
| 776 |
def _q(q: str="", backend: str="text", max_results: int=10, extract_top: int=0, region: str="wt-wt"):
|
| 777 |
if not q: return JSONResponse({"error":"Missing 'q'"}, status_code=400)
|
|
|
|
| 772 |
@fa_app.get("/respite/specs")
|
| 773 |
def _s(): return JSONResponse({**API_SPECS, "runtime": _get_runtime_specs()})
|
| 774 |
|
| 775 |
+
@fa_app.post("/respite/audio/generate")
|
| 776 |
+
def _audio_api(payload: dict = Body(...)):
|
| 777 |
+
prompt = str(payload.get("prompt", "")).strip()
|
| 778 |
+
if not prompt:
|
| 779 |
+
return JSONResponse({"error": "Missing 'prompt'"}, status_code=400)
|
| 780 |
+
try:
|
| 781 |
+
path = generate_audio(
|
| 782 |
+
prompt,
|
| 783 |
+
max(1, min(120, float(payload.get("duration", 30)))),
|
| 784 |
+
max(1, min(50, int(payload.get("steps", 8)))),
|
| 785 |
+
max(0.0, min(10.0, float(payload.get("cfg_scale", 1.0)))),
|
| 786 |
+
int(payload.get("seed", -1)),
|
| 787 |
+
str(payload.get("model", "small-music")),
|
| 788 |
+
)
|
| 789 |
+
from fastapi.responses import FileResponse
|
| 790 |
+
return FileResponse(path, media_type="audio/wav", filename=os.path.basename(path))
|
| 791 |
+
except Exception as e:
|
| 792 |
+
return JSONResponse({"error": str(e)}, status_code=500)
|
| 793 |
+
|
| 794 |
@fa_app.get("/respite/search")
|
| 795 |
def _q(q: str="", backend: str="text", max_results: int=10, extract_top: int=0, region: str="wt-wt"):
|
| 796 |
if not q: return JSONResponse({"error":"Missing 'q'"}, status_code=400)
|