Spaces:
Running
Running
fix LM caption: use poll response data directly, empty body from /job?result=1 was the bug
Browse files
app.py
CHANGED
|
@@ -96,11 +96,11 @@ def _get_props():
|
|
| 96 |
|
| 97 |
|
| 98 |
def _poll_job(job_id, timeout=600, progress_cb=None, cancel_check=None):
|
| 99 |
-
"""Poll a job until done/error/timeout/cancelled. Returns (status, elapsed)."""
|
| 100 |
t0 = time.time()
|
| 101 |
while time.time() - t0 < timeout:
|
| 102 |
if cancel_check and cancel_check():
|
| 103 |
-
return "cancelled", time.time() - t0
|
| 104 |
try:
|
| 105 |
r = requests.get(f"{ACE_SERVER}/job", params={"id": job_id}, timeout=5)
|
| 106 |
data = r.json()
|
|
@@ -108,11 +108,11 @@ def _poll_job(job_id, timeout=600, progress_cb=None, cancel_check=None):
|
|
| 108 |
if progress_cb:
|
| 109 |
progress_cb(status, data)
|
| 110 |
if status in ("done", "error"):
|
| 111 |
-
return status, time.time() - t0
|
| 112 |
except Exception:
|
| 113 |
pass
|
| 114 |
time.sleep(1)
|
| 115 |
-
return "timeout", time.time() - t0
|
| 116 |
|
| 117 |
|
| 118 |
def _fetch_result(job_id, timeout=60):
|
|
@@ -146,28 +146,42 @@ def _caption_via_understand(audio_path, timeout=600, cancel_check=None):
|
|
| 146 |
logger.warning("[Caption] %s: /understand submit failed: %s", fname, exc)
|
| 147 |
return None
|
| 148 |
|
| 149 |
-
status, elapsed = _poll_job(job_id, timeout=timeout, cancel_check=cancel_check)
|
| 150 |
if status != "done":
|
| 151 |
logger.warning("[Caption] %s: /understand -> %s (%.0fs)", fname, status, elapsed)
|
| 152 |
return None
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
|
| 173 |
def _run_pipeline(caption, lyrics, bpm, duration, seed, steps, output_format,
|
|
@@ -209,7 +223,7 @@ def _run_pipeline(caption, lyrics, bpm, duration, seed, steps, output_format,
|
|
| 209 |
|
| 210 |
if progress_cb:
|
| 211 |
progress_cb("lm_poll", {"job_id": lm_job_id})
|
| 212 |
-
lm_status, lm_elapsed = _poll_job(lm_job_id, timeout=900)
|
| 213 |
if lm_status != "done":
|
| 214 |
raise RuntimeError(f"LM {lm_status} after {lm_elapsed:.0f}s")
|
| 215 |
|
|
@@ -234,7 +248,7 @@ def _run_pipeline(caption, lyrics, bpm, duration, seed, steps, output_format,
|
|
| 234 |
|
| 235 |
if progress_cb:
|
| 236 |
progress_cb("synth_poll", {"job_id": synth_job_id})
|
| 237 |
-
synth_status, synth_elapsed = _poll_job(synth_job_id, timeout=600)
|
| 238 |
if synth_status != "done":
|
| 239 |
raise RuntimeError(f"Synth {synth_status} after {synth_elapsed:.0f}s")
|
| 240 |
|
|
|
|
| 96 |
|
| 97 |
|
| 98 |
def _poll_job(job_id, timeout=600, progress_cb=None, cancel_check=None):
|
| 99 |
+
"""Poll a job until done/error/timeout/cancelled. Returns (status, elapsed, data)."""
|
| 100 |
t0 = time.time()
|
| 101 |
while time.time() - t0 < timeout:
|
| 102 |
if cancel_check and cancel_check():
|
| 103 |
+
return "cancelled", time.time() - t0, None
|
| 104 |
try:
|
| 105 |
r = requests.get(f"{ACE_SERVER}/job", params={"id": job_id}, timeout=5)
|
| 106 |
data = r.json()
|
|
|
|
| 108 |
if progress_cb:
|
| 109 |
progress_cb(status, data)
|
| 110 |
if status in ("done", "error"):
|
| 111 |
+
return status, time.time() - t0, data
|
| 112 |
except Exception:
|
| 113 |
pass
|
| 114 |
time.sleep(1)
|
| 115 |
+
return "timeout", time.time() - t0, None
|
| 116 |
|
| 117 |
|
| 118 |
def _fetch_result(job_id, timeout=60):
|
|
|
|
| 146 |
logger.warning("[Caption] %s: /understand submit failed: %s", fname, exc)
|
| 147 |
return None
|
| 148 |
|
| 149 |
+
status, elapsed, poll_data = _poll_job(job_id, timeout=timeout, cancel_check=cancel_check)
|
| 150 |
if status != "done":
|
| 151 |
logger.warning("[Caption] %s: /understand -> %s (%.0fs)", fname, status, elapsed)
|
| 152 |
return None
|
| 153 |
|
| 154 |
+
# Result may be in the poll response itself or need separate fetch
|
| 155 |
+
result = None
|
| 156 |
+
|
| 157 |
+
# Check if poll response contains the result directly
|
| 158 |
+
if poll_data and isinstance(poll_data, dict):
|
| 159 |
+
if poll_data.get("caption"):
|
| 160 |
+
result = poll_data
|
| 161 |
+
elif poll_data.get("result") and isinstance(poll_data["result"], dict):
|
| 162 |
+
result = poll_data["result"]
|
| 163 |
+
|
| 164 |
+
# Fallback: try fetching result separately
|
| 165 |
+
if not result:
|
| 166 |
+
try:
|
| 167 |
+
r = _fetch_result(job_id, timeout=120)
|
| 168 |
+
if r.status_code == 200 and r.text.strip():
|
| 169 |
+
data = r.json()
|
| 170 |
+
if isinstance(data, dict):
|
| 171 |
+
if data.get("caption"):
|
| 172 |
+
result = data
|
| 173 |
+
elif data.get("result") and isinstance(data["result"], dict):
|
| 174 |
+
result = data["result"]
|
| 175 |
+
except Exception as exc:
|
| 176 |
+
logger.warning("[Caption] %s: result fetch failed: %s", fname, exc)
|
| 177 |
+
|
| 178 |
+
if result:
|
| 179 |
+
logger.info("[Caption] %s: got caption (%d chars)", fname, len(result.get("caption", "")))
|
| 180 |
+
return result
|
| 181 |
+
|
| 182 |
+
logger.warning("[Caption] %s: no caption in response. poll_keys=%s",
|
| 183 |
+
fname, list(poll_data.keys()) if isinstance(poll_data, dict) else "N/A")
|
| 184 |
+
return None
|
| 185 |
|
| 186 |
|
| 187 |
def _run_pipeline(caption, lyrics, bpm, duration, seed, steps, output_format,
|
|
|
|
| 223 |
|
| 224 |
if progress_cb:
|
| 225 |
progress_cb("lm_poll", {"job_id": lm_job_id})
|
| 226 |
+
lm_status, lm_elapsed, _ = _poll_job(lm_job_id, timeout=900)
|
| 227 |
if lm_status != "done":
|
| 228 |
raise RuntimeError(f"LM {lm_status} after {lm_elapsed:.0f}s")
|
| 229 |
|
|
|
|
| 248 |
|
| 249 |
if progress_cb:
|
| 250 |
progress_cb("synth_poll", {"job_id": synth_job_id})
|
| 251 |
+
synth_status, synth_elapsed, _ = _poll_job(synth_job_id, timeout=600)
|
| 252 |
if synth_status != "done":
|
| 253 |
raise RuntimeError(f"Synth {synth_status} after {synth_elapsed:.0f}s")
|
| 254 |
|