PLEASE WORK NOW
Browse files
app.py
CHANGED
|
@@ -191,7 +191,34 @@ def job_status(request_id):
|
|
| 191 |
r = requests.get(f"{BASE}{PATHS['get-status']}", headers=HEADERS,
|
| 192 |
params={"request_id": request_id}, timeout=30)
|
| 193 |
body = read_json(r, "get-status")
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
|
| 197 |
def download(request_id, workdir):
|
|
@@ -243,11 +270,11 @@ def run(video, audio, mood, excited, angry, profile: gr.OAuthProfile | None):
|
|
| 243 |
|
| 244 |
started = time.time()
|
| 245 |
while True:
|
| 246 |
-
status = job_status(request_id)
|
| 247 |
if status == "success":
|
| 248 |
break
|
| 249 |
-
if status in ("failed", "invalid_request", "internal_error"):
|
| 250 |
-
raise gr.Error(
|
| 251 |
if time.time() - started > JOB_TIMEOUT:
|
| 252 |
raise gr.Error("This is taking too long. Please try again later.")
|
| 253 |
waited = int(time.time() - started)
|
|
|
|
| 191 |
r = requests.get(f"{BASE}{PATHS['get-status']}", headers=HEADERS,
|
| 192 |
params={"request_id": request_id}, timeout=30)
|
| 193 |
body = read_json(r, "get-status")
|
| 194 |
+
data = body.get("data") or {}
|
| 195 |
+
status = str(data.get("status", "")).lower()
|
| 196 |
+
if status not in ("success", "in_progress", "pending", "created", "processing"):
|
| 197 |
+
print(f"[get-status] {request_id}: {json.dumps(body)[:800]}")
|
| 198 |
+
return status, data
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def failure_reason(request_id, status_data):
|
| 202 |
+
"""Work out why a job failed: look in the status reply, then in /get-request."""
|
| 203 |
+
details = dict(status_data)
|
| 204 |
+
try:
|
| 205 |
+
r = requests.get(f"{BASE}/get-request", headers=HEADERS,
|
| 206 |
+
params={"request_id": request_id}, timeout=30)
|
| 207 |
+
print(f"[get-request] {request_id}: HTTP {r.status_code}: {r.text[:1500]}")
|
| 208 |
+
req = (r.json() or {}).get("data") or {}
|
| 209 |
+
if isinstance(req, dict):
|
| 210 |
+
details.update({k: v for k, v in req.items() if v})
|
| 211 |
+
except Exception as e:
|
| 212 |
+
print(f"[get-request] {request_id} failed: {e}")
|
| 213 |
+
code = details.get("error_code")
|
| 214 |
+
if code in FRIENDLY_ERRORS:
|
| 215 |
+
return FRIENDLY_ERRORS[code]
|
| 216 |
+
msg = (details.get("error_message") or details.get("error")
|
| 217 |
+
or details.get("message") or details.get("reason"))
|
| 218 |
+
if isinstance(msg, dict):
|
| 219 |
+
msg = msg.get("message") or json.dumps(msg)
|
| 220 |
+
base = f"Processing failed: {msg}" if msg else "Processing failed. Try a different clip."
|
| 221 |
+
return f"{base} (job {request_id[:8]})"
|
| 222 |
|
| 223 |
|
| 224 |
def download(request_id, workdir):
|
|
|
|
| 270 |
|
| 271 |
started = time.time()
|
| 272 |
while True:
|
| 273 |
+
status, status_data = job_status(request_id)
|
| 274 |
if status == "success":
|
| 275 |
break
|
| 276 |
+
if status in ("failed", "failure", "error", "invalid_request", "internal_error"):
|
| 277 |
+
raise gr.Error(failure_reason(request_id, status_data))
|
| 278 |
if time.time() - started > JOB_TIMEOUT:
|
| 279 |
raise gr.Error("This is taking too long. Please try again later.")
|
| 280 |
waited = int(time.time() - started)
|