Spaces:
Paused
Paused
Remove sensitive log content; source revision 1e84b02
Browse files
app.py
CHANGED
|
@@ -93,11 +93,11 @@ def _supabase_request(method: str, path: str, payload=None, params=None) -> Opti
|
|
| 93 |
timeout=10,
|
| 94 |
)
|
| 95 |
if resp.status_code >= 400:
|
| 96 |
-
logger.warning(f"Supabase {method} {path} HTTP {resp.status_code}
|
| 97 |
return None
|
| 98 |
return resp.json() if resp.text else {}
|
| 99 |
except Exception as e:
|
| 100 |
-
logger.warning(f"Supabase {method} {path} failed: {e}")
|
| 101 |
return None
|
| 102 |
|
| 103 |
|
|
@@ -239,7 +239,7 @@ async def startup_event():
|
|
| 239 |
await asyncio.to_thread(engine.diarization._load_pipeline)
|
| 240 |
logger.info("Pyannote diarization pipeline pre-loaded successfully.")
|
| 241 |
except Exception as exc:
|
| 242 |
-
logger.warning(f"Pyannote pipeline pre-load failed (will retry on first use): {exc}")
|
| 243 |
asyncio.create_task(_preload_pyannote())
|
| 244 |
else:
|
| 245 |
try:
|
|
@@ -345,7 +345,7 @@ def _purge_old_jobs() -> None:
|
|
| 345 |
params={"submitted_at": when}, headers=_sb_headers(), timeout=15)
|
| 346 |
response.raise_for_status()
|
| 347 |
except Exception as e:
|
| 348 |
-
logger.warning(f"Job purge failed: {e}")
|
| 349 |
threading.Thread(target=run, daemon=True).start()
|
| 350 |
|
| 351 |
|
|
@@ -486,7 +486,7 @@ def _generate_minutes_with_claude(
|
|
| 486 |
"action_items": parsed.get("action_items", []),
|
| 487 |
}
|
| 488 |
except Exception as e:
|
| 489 |
-
logger.warning(f"Minutes generation failed: {e}")
|
| 490 |
return {"summary": "", "topics": [], "decisions": [], "action_items": []}
|
| 491 |
|
| 492 |
|
|
@@ -532,7 +532,7 @@ def _get_speaker_sentiments(segments: list, speaker_names: dict) -> dict:
|
|
| 532 |
response_text = parts[1].lstrip("json").strip() if len(parts) > 1 else response_text
|
| 533 |
return json.loads(response_text)
|
| 534 |
except Exception as e:
|
| 535 |
-
logger.warning(f"Sentiment analysis failed: {e}")
|
| 536 |
return {}
|
| 537 |
|
| 538 |
|
|
@@ -623,15 +623,15 @@ def _enhance_segments_with_claude(segments: list, language: str) -> list:
|
|
| 623 |
# Only drop what looks like Whisper filler. A long, real
|
| 624 |
# sentence is kept even if the model thought it out of place.
|
| 625 |
if len(text.split()) <= 12 or _is_likely_hallucination(text) or _is_repetition_loop(text):
|
| 626 |
-
logger.info(
|
| 627 |
else:
|
| 628 |
-
logger.info(
|
| 629 |
out.append(seg)
|
| 630 |
else:
|
| 631 |
out.append({**seg, "text": corrected})
|
| 632 |
|
| 633 |
except Exception as e:
|
| 634 |
-
logger.warning(f"Claude batch enhancement failed: {e} — keeping originals")
|
| 635 |
out.extend(batch)
|
| 636 |
return out
|
| 637 |
|
|
@@ -706,7 +706,7 @@ def _add_diacritics_with_claude(text: str, language: str) -> str:
|
|
| 706 |
logger.info(f"Added {lang_name} diacritics via Claude")
|
| 707 |
return corrected
|
| 708 |
except Exception as e:
|
| 709 |
-
logger.warning(f"Claude diacritics failed: {e} — keeping original")
|
| 710 |
return text
|
| 711 |
|
| 712 |
|
|
@@ -761,7 +761,7 @@ def _reap_if_orphaned(job_id: str, row: dict) -> dict:
|
|
| 761 |
try:
|
| 762 |
_finish_work(job_id, False)
|
| 763 |
except Exception:
|
| 764 |
-
logger.
|
| 765 |
return dict(row, status="error")
|
| 766 |
|
| 767 |
|
|
@@ -999,7 +999,7 @@ async def _generate_minutes(request: Request, docx: bool = False):
|
|
| 999 |
try:
|
| 1000 |
await asyncio.to_thread(_finish_work, reference, False)
|
| 1001 |
except Exception:
|
| 1002 |
-
logger.
|
| 1003 |
_WORK_SLOTS.release()
|
| 1004 |
|
| 1005 |
|
|
@@ -1043,14 +1043,14 @@ async def translate_transcript_endpoint(request: Request):
|
|
| 1043 |
except HTTPException:
|
| 1044 |
raise
|
| 1045 |
except Exception:
|
| 1046 |
-
logger.
|
| 1047 |
raise HTTPException(status_code=503, detail="Translation unavailable. Please try again.")
|
| 1048 |
finally:
|
| 1049 |
if reserved and not settled:
|
| 1050 |
try:
|
| 1051 |
await asyncio.to_thread(_finish_work, reference, False)
|
| 1052 |
except Exception:
|
| 1053 |
-
logger.
|
| 1054 |
_WORK_SLOTS.release()
|
| 1055 |
|
| 1056 |
|
|
@@ -1116,7 +1116,7 @@ def _verified_uid(request: Request) -> Optional[str]:
|
|
| 1116 |
claims = _gid.verify_firebase_token(token, _gareq.Request(), audience=_FIREBASE_PROJECT)
|
| 1117 |
return (claims or {}).get("user_id") or (claims or {}).get("sub")
|
| 1118 |
except Exception as e:
|
| 1119 |
-
logger.warning(f"Firebase token rejected: {e}")
|
| 1120 |
raise HTTPException(status_code=401, detail="Your session has expired. Please sign in again.")
|
| 1121 |
|
| 1122 |
|
|
@@ -1175,7 +1175,7 @@ def _probe_duration_sec(content: bytes, filename: str) -> Optional[float]:
|
|
| 1175 |
)
|
| 1176 |
return float(out.stdout.strip())
|
| 1177 |
except Exception as e:
|
| 1178 |
-
logger.warning(
|
| 1179 |
return None
|
| 1180 |
|
| 1181 |
|
|
@@ -1438,7 +1438,7 @@ def _supabase_increment_audio_minutes(firebase_uid: str, audio_duration_sec: flo
|
|
| 1438 |
timeout=10,
|
| 1439 |
)
|
| 1440 |
except Exception as exc:
|
| 1441 |
-
logger.warning(f"Could not increment audio_minutes_used: {exc}")
|
| 1442 |
|
| 1443 |
|
| 1444 |
def _paystack_plan_expires(data: dict) -> Optional[str]:
|
|
@@ -1571,7 +1571,7 @@ async def credits_apple(request: Request):
|
|
| 1571 |
try:
|
| 1572 |
tx = verify_jws(str(body.get("signed_transaction") or ""))
|
| 1573 |
except AppleJWSError as e:
|
| 1574 |
-
logger.warning(f"Apple purchase rejected for {uid}: {e}")
|
| 1575 |
raise HTTPException(status_code=400, detail="We couldn't verify this purchase with Apple.")
|
| 1576 |
pack = _apple_pack(tx.get("productId") or "")
|
| 1577 |
if tx.get("bundleId") != APPLE_BUNDLE_ID or not pack or tx.get("type") not in (None, "Consumable"):
|
|
@@ -1620,7 +1620,7 @@ async def apple_notifications(request: Request):
|
|
| 1620 |
try:
|
| 1621 |
note = verify_jws(str(body.get("signedPayload") or ""))
|
| 1622 |
except AppleJWSError as e:
|
| 1623 |
-
logger.warning(f"Apple notification rejected: {e}")
|
| 1624 |
raise HTTPException(status_code=400, detail="invalid signature")
|
| 1625 |
kind = note.get("notificationType")
|
| 1626 |
data = note.get("data") or {}
|
|
@@ -1735,7 +1735,7 @@ def _keepalive_loop() -> None:
|
|
| 1735 |
try:
|
| 1736 |
_requests.get(f"{url}/health", timeout=15)
|
| 1737 |
except Exception as e:
|
| 1738 |
-
logger.warning(f"Keep-alive ping failed: {e}")
|
| 1739 |
|
| 1740 |
|
| 1741 |
threading.Thread(target=_keepalive_loop, name="keepalive", daemon=True).start()
|
|
@@ -1775,7 +1775,7 @@ def _drop_repetition_segments(segments: list) -> list:
|
|
| 1775 |
run_len = run_len + 1 if key == run_text else 1
|
| 1776 |
run_text = key
|
| 1777 |
if run_len > 3 or _is_repetition_loop(text):
|
| 1778 |
-
logger.info(
|
| 1779 |
continue
|
| 1780 |
cleaned.append(seg)
|
| 1781 |
return cleaned
|
|
@@ -1837,7 +1837,7 @@ def _run_transcription_sync(
|
|
| 1837 |
result.text = " ".join((seg.get("text") or "").strip() for seg in result.segments)
|
| 1838 |
loop_only = not result.segments and _is_repetition_loop(result.text or "")
|
| 1839 |
if loop_only or not (result.text or "").strip():
|
| 1840 |
-
logger.warning(
|
| 1841 |
_upsert_job(
|
| 1842 |
jid,
|
| 1843 |
status="error",
|
|
@@ -1935,7 +1935,7 @@ def _run_transcription_sync(
|
|
| 1935 |
_upsert_job(jid, status="cancelled", detail="Cancelled by user")
|
| 1936 |
_CANCELLED.discard(jid)
|
| 1937 |
except Exception as e:
|
| 1938 |
-
logger.error(f"Background transcription job {jid} failed: {e}")
|
| 1939 |
_upsert_job(jid, status="error", detail=str(e))
|
| 1940 |
finally:
|
| 1941 |
_job_finished()
|
|
@@ -1946,7 +1946,7 @@ def _run_transcription_sync(
|
|
| 1946 |
try:
|
| 1947 |
_finish_work(jid, False)
|
| 1948 |
except Exception:
|
| 1949 |
-
logger.
|
| 1950 |
_WORK_SLOTS.release()
|
| 1951 |
|
| 1952 |
|
|
|
|
| 93 |
timeout=10,
|
| 94 |
)
|
| 95 |
if resp.status_code >= 400:
|
| 96 |
+
logger.warning(f"Supabase {method} {path} HTTP {resp.status_code}")
|
| 97 |
return None
|
| 98 |
return resp.json() if resp.text else {}
|
| 99 |
except Exception as e:
|
| 100 |
+
logger.warning(f"Supabase {method} {path} failed: {type(e).__name__}")
|
| 101 |
return None
|
| 102 |
|
| 103 |
|
|
|
|
| 239 |
await asyncio.to_thread(engine.diarization._load_pipeline)
|
| 240 |
logger.info("Pyannote diarization pipeline pre-loaded successfully.")
|
| 241 |
except Exception as exc:
|
| 242 |
+
logger.warning(f"Pyannote pipeline pre-load failed (will retry on first use): {type(exc).__name__}")
|
| 243 |
asyncio.create_task(_preload_pyannote())
|
| 244 |
else:
|
| 245 |
try:
|
|
|
|
| 345 |
params={"submitted_at": when}, headers=_sb_headers(), timeout=15)
|
| 346 |
response.raise_for_status()
|
| 347 |
except Exception as e:
|
| 348 |
+
logger.warning(f"Job purge failed: {type(e).__name__}")
|
| 349 |
threading.Thread(target=run, daemon=True).start()
|
| 350 |
|
| 351 |
|
|
|
|
| 486 |
"action_items": parsed.get("action_items", []),
|
| 487 |
}
|
| 488 |
except Exception as e:
|
| 489 |
+
logger.warning(f"Minutes generation failed: {type(e).__name__}")
|
| 490 |
return {"summary": "", "topics": [], "decisions": [], "action_items": []}
|
| 491 |
|
| 492 |
|
|
|
|
| 532 |
response_text = parts[1].lstrip("json").strip() if len(parts) > 1 else response_text
|
| 533 |
return json.loads(response_text)
|
| 534 |
except Exception as e:
|
| 535 |
+
logger.warning(f"Sentiment analysis failed: {type(e).__name__}")
|
| 536 |
return {}
|
| 537 |
|
| 538 |
|
|
|
|
| 623 |
# Only drop what looks like Whisper filler. A long, real
|
| 624 |
# sentence is kept even if the model thought it out of place.
|
| 625 |
if len(text.split()) <= 12 or _is_likely_hallucination(text) or _is_repetition_loop(text):
|
| 626 |
+
logger.info("Stripped hallucinated segment (Claude)")
|
| 627 |
else:
|
| 628 |
+
logger.info("Kept segment flagged by Claude")
|
| 629 |
out.append(seg)
|
| 630 |
else:
|
| 631 |
out.append({**seg, "text": corrected})
|
| 632 |
|
| 633 |
except Exception as e:
|
| 634 |
+
logger.warning(f"Claude batch enhancement failed: {type(e).__name__} — keeping originals")
|
| 635 |
out.extend(batch)
|
| 636 |
return out
|
| 637 |
|
|
|
|
| 706 |
logger.info(f"Added {lang_name} diacritics via Claude")
|
| 707 |
return corrected
|
| 708 |
except Exception as e:
|
| 709 |
+
logger.warning(f"Claude diacritics failed: {type(e).__name__} — keeping original")
|
| 710 |
return text
|
| 711 |
|
| 712 |
|
|
|
|
| 761 |
try:
|
| 762 |
_finish_work(job_id, False)
|
| 763 |
except Exception:
|
| 764 |
+
logger.error("Orphaned job refund needs reconciliation: %s", job_id)
|
| 765 |
return dict(row, status="error")
|
| 766 |
|
| 767 |
|
|
|
|
| 999 |
try:
|
| 1000 |
await asyncio.to_thread(_finish_work, reference, False)
|
| 1001 |
except Exception:
|
| 1002 |
+
logger.error("Minutes reservation needs reconciliation: %s", reference)
|
| 1003 |
_WORK_SLOTS.release()
|
| 1004 |
|
| 1005 |
|
|
|
|
| 1043 |
except HTTPException:
|
| 1044 |
raise
|
| 1045 |
except Exception:
|
| 1046 |
+
logger.error("Translation failed for reservation %s", reference)
|
| 1047 |
raise HTTPException(status_code=503, detail="Translation unavailable. Please try again.")
|
| 1048 |
finally:
|
| 1049 |
if reserved and not settled:
|
| 1050 |
try:
|
| 1051 |
await asyncio.to_thread(_finish_work, reference, False)
|
| 1052 |
except Exception:
|
| 1053 |
+
logger.error("Translation reservation needs reconciliation: %s", reference)
|
| 1054 |
_WORK_SLOTS.release()
|
| 1055 |
|
| 1056 |
|
|
|
|
| 1116 |
claims = _gid.verify_firebase_token(token, _gareq.Request(), audience=_FIREBASE_PROJECT)
|
| 1117 |
return (claims or {}).get("user_id") or (claims or {}).get("sub")
|
| 1118 |
except Exception as e:
|
| 1119 |
+
logger.warning(f"Firebase token rejected: {type(e).__name__}")
|
| 1120 |
raise HTTPException(status_code=401, detail="Your session has expired. Please sign in again.")
|
| 1121 |
|
| 1122 |
|
|
|
|
| 1175 |
)
|
| 1176 |
return float(out.stdout.strip())
|
| 1177 |
except Exception as e:
|
| 1178 |
+
logger.warning("Could not probe audio duration")
|
| 1179 |
return None
|
| 1180 |
|
| 1181 |
|
|
|
|
| 1438 |
timeout=10,
|
| 1439 |
)
|
| 1440 |
except Exception as exc:
|
| 1441 |
+
logger.warning(f"Could not increment audio_minutes_used: {type(exc).__name__}")
|
| 1442 |
|
| 1443 |
|
| 1444 |
def _paystack_plan_expires(data: dict) -> Optional[str]:
|
|
|
|
| 1571 |
try:
|
| 1572 |
tx = verify_jws(str(body.get("signed_transaction") or ""))
|
| 1573 |
except AppleJWSError as e:
|
| 1574 |
+
logger.warning(f"Apple purchase rejected for {uid}: {type(e).__name__}")
|
| 1575 |
raise HTTPException(status_code=400, detail="We couldn't verify this purchase with Apple.")
|
| 1576 |
pack = _apple_pack(tx.get("productId") or "")
|
| 1577 |
if tx.get("bundleId") != APPLE_BUNDLE_ID or not pack or tx.get("type") not in (None, "Consumable"):
|
|
|
|
| 1620 |
try:
|
| 1621 |
note = verify_jws(str(body.get("signedPayload") or ""))
|
| 1622 |
except AppleJWSError as e:
|
| 1623 |
+
logger.warning(f"Apple notification rejected: {type(e).__name__}")
|
| 1624 |
raise HTTPException(status_code=400, detail="invalid signature")
|
| 1625 |
kind = note.get("notificationType")
|
| 1626 |
data = note.get("data") or {}
|
|
|
|
| 1735 |
try:
|
| 1736 |
_requests.get(f"{url}/health", timeout=15)
|
| 1737 |
except Exception as e:
|
| 1738 |
+
logger.warning(f"Keep-alive ping failed: {type(e).__name__}")
|
| 1739 |
|
| 1740 |
|
| 1741 |
threading.Thread(target=_keepalive_loop, name="keepalive", daemon=True).start()
|
|
|
|
| 1775 |
run_len = run_len + 1 if key == run_text else 1
|
| 1776 |
run_text = key
|
| 1777 |
if run_len > 3 or _is_repetition_loop(text):
|
| 1778 |
+
logger.info("Dropped repeated/looping segment")
|
| 1779 |
continue
|
| 1780 |
cleaned.append(seg)
|
| 1781 |
return cleaned
|
|
|
|
| 1837 |
result.text = " ".join((seg.get("text") or "").strip() for seg in result.segments)
|
| 1838 |
loop_only = not result.segments and _is_repetition_loop(result.text or "")
|
| 1839 |
if loop_only or not (result.text or "").strip():
|
| 1840 |
+
logger.warning("No usable speech after loop cleanup")
|
| 1841 |
_upsert_job(
|
| 1842 |
jid,
|
| 1843 |
status="error",
|
|
|
|
| 1935 |
_upsert_job(jid, status="cancelled", detail="Cancelled by user")
|
| 1936 |
_CANCELLED.discard(jid)
|
| 1937 |
except Exception as e:
|
| 1938 |
+
logger.error(f"Background transcription job {jid} failed: {type(e).__name__}")
|
| 1939 |
_upsert_job(jid, status="error", detail=str(e))
|
| 1940 |
finally:
|
| 1941 |
_job_finished()
|
|
|
|
| 1946 |
try:
|
| 1947 |
_finish_work(jid, False)
|
| 1948 |
except Exception:
|
| 1949 |
+
logger.error("Reservation needs reconciliation: %s", jid)
|
| 1950 |
_WORK_SLOTS.release()
|
| 1951 |
|
| 1952 |
|