Spaces:
Sleeping
Sleeping
Tu Nombre commited on
Commit ·
6562dbf
1
Parent(s): 0d85861
fix musica IA
Browse files
app.py
CHANGED
|
@@ -534,22 +534,34 @@ async def ep_musica_ia(request: Request):
|
|
| 534 |
for line in stream.iter_lines():
|
| 535 |
if not line: continue
|
| 536 |
decoded = line.decode("utf-8")
|
| 537 |
-
if decoded.startswith("data:"):
|
|
|
|
| 538 |
data = _json.loads(decoded[5:].strip())
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
return JSONResponse({"error": "La Fabrica no devolvio audio"}, status_code=500)
|
| 552 |
except Exception as e:
|
|
|
|
| 553 |
return JSONResponse({"error": str(e)[:200]}, status_code=500)
|
| 554 |
|
| 555 |
@app.get("/audio")
|
|
|
|
| 534 |
for line in stream.iter_lines():
|
| 535 |
if not line: continue
|
| 536 |
decoded = line.decode("utf-8")
|
| 537 |
+
if not decoded.startswith("data:"): continue
|
| 538 |
+
try:
|
| 539 |
data = _json.loads(decoded[5:].strip())
|
| 540 |
+
except Exception:
|
| 541 |
+
continue
|
| 542 |
+
if not (isinstance(data, list) and data): continue
|
| 543 |
+
audio_url = data[0]
|
| 544 |
+
if audio_url is None: continue
|
| 545 |
+
if isinstance(audio_url, dict):
|
| 546 |
+
audio_url = audio_url.get("url") or audio_url.get("path","") or ""
|
| 547 |
+
if not isinstance(audio_url, str) or not audio_url:
|
| 548 |
+
continue
|
| 549 |
+
if not audio_url.startswith("http"):
|
| 550 |
+
if "/gradio_api/file=" in audio_url:
|
| 551 |
+
audio_url = url_fabrica + audio_url
|
| 552 |
+
else:
|
| 553 |
+
audio_url = url_fabrica + "/gradio_api/file=" + audio_url
|
| 554 |
+
audio_resp = _req.get(audio_url, timeout=60)
|
| 555 |
+
audio_resp.raise_for_status()
|
| 556 |
+
with open("musica.mp3","wb") as f:
|
| 557 |
+
f.write(audio_resp.content)
|
| 558 |
+
ESTADO["musica"] = True
|
| 559 |
+
log(f"[Musica] OK -> {audio_url[:90]}")
|
| 560 |
+
return {"ok": True}
|
| 561 |
+
log("[Musica] La Fabrica no devolvio audio")
|
| 562 |
return JSONResponse({"error": "La Fabrica no devolvio audio"}, status_code=500)
|
| 563 |
except Exception as e:
|
| 564 |
+
log(f"[Musica] ERROR: {e}")
|
| 565 |
return JSONResponse({"error": str(e)[:200]}, status_code=500)
|
| 566 |
|
| 567 |
@app.get("/audio")
|