Spaces:
Runtime error
Runtime error
Commit ·
468712b
1
Parent(s): d52ed80
Upload TRAIN PDFs to API space
Browse files- backend/worker/worker.py +17 -0
backend/worker/worker.py
CHANGED
|
@@ -138,6 +138,23 @@ def _process_train_label(gmail: GmailClient, s: Settings, root: Path) -> None:
|
|
| 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:
|
|
|
|
| 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 |
+
r = 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 |
+
)
|
| 152 |
+
r.raise_for_status()
|
| 153 |
+
print(f"[worker] uploaded pdf_id={pdf_id} to API")
|
| 154 |
+
except Exception as e:
|
| 155 |
+
print(f"[worker] ERROR uploading PDF to API: {e}")
|
| 156 |
+
|
| 157 |
+
print(f"[worker][TRAIN] open: {trainer_link}")
|
| 158 |
|
| 159 |
# push PDF into API space so UI can fetch it
|
| 160 |
try:
|