Spaces:
Runtime error
Runtime error
Commit ·
d52ed80
1
Parent(s): 88696c0
Fix TRAIN upload block syntax + upload to API
Browse files- backend/worker/worker.py +14 -13
backend/worker/worker.py
CHANGED
|
@@ -137,20 +137,21 @@ def _process_train_label(gmail: GmailClient, s: Settings, root: Path) -> None:
|
|
| 137 |
print(
|
| 138 |
f"[worker][TRAIN] stored PDF msg={m.msg_id} file={filename} "
|
| 139 |
f"pdf_id={pdf_id} stored={stored_pdf_path}"
|
| 140 |
-
|
| 141 |
-
# push PDF into API space so UI can fetch it
|
| 142 |
-
try:
|
| 143 |
-
if PDF_TRAINER_API_BASE:
|
| 144 |
-
with open(stored_pdf_path, "rb") as f:
|
| 145 |
-
requests.post(
|
| 146 |
-
f"{PDF_TRAINER_API_BASE.rstrip('/')}/api/pdf/{pdf_id}",
|
| 147 |
-
files={"file": (f"{pdf_id}.pdf", f, "application/pdf")},
|
| 148 |
-
data={"pdf_name": filename},
|
| 149 |
-
timeout=30,
|
| 150 |
-
).raise_for_status()
|
| 151 |
-
except Exception as e:
|
| 152 |
-
print(f"[worker] WARN: failed to upload PDF to API: {e}")
|
| 153 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
print(f"[worker][TRAIN] open: {trainer_link}")
|
| 155 |
|
| 156 |
|
|
|
|
| 137 |
print(
|
| 138 |
f"[worker][TRAIN] stored PDF msg={m.msg_id} file={filename} "
|
| 139 |
f"pdf_id={pdf_id} stored={stored_pdf_path}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
)
|
| 141 |
+
|
| 142 |
+
# push PDF into API space so UI can fetch it
|
| 143 |
+
try:
|
| 144 |
+
if PDF_TRAINER_API_BASE:
|
| 145 |
+
with open(stored_pdf_path, "rb") as f:
|
| 146 |
+
requests.post(
|
| 147 |
+
f"{PDF_TRAINER_API_BASE.rstrip('/')}/api/pdf/{pdf_id}",
|
| 148 |
+
files={"file": (f"{pdf_id}.pdf", f, "application/pdf")},
|
| 149 |
+
data={"pdf_name": filename},
|
| 150 |
+
timeout=30,
|
| 151 |
+
).raise_for_status()
|
| 152 |
+
except Exception as e:
|
| 153 |
+
print(f"[worker] WARN: failed to upload PDF to API: {e}")
|
| 154 |
+
|
| 155 |
print(f"[worker][TRAIN] open: {trainer_link}")
|
| 156 |
|
| 157 |
|