fix: VL device detection, failed-capture error state, HF_HOME=/data/.cache
Browse files
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
|
|
| 1 |
import re
|
| 2 |
import json
|
| 3 |
import shutil
|
| 4 |
import asyncio
|
| 5 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
| 6 |
from typing import Optional, List
|
| 7 |
|
| 8 |
import httpx
|
|
@@ -408,7 +412,16 @@ async def _process(cid: int, type: str, **kwargs):
|
|
| 408 |
recall_q = await loop.run_in_executor(None, generate_recall_question, summary, intent or "", claims)
|
| 409 |
update_capture(cid, summary, result.get("tags", []), intent, emb, related, recall_q, claims, source_content_path, title)
|
| 410 |
except Exception as e:
|
| 411 |
-
print(f"[process error] {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
|
| 413 |
|
| 414 |
async def _fetch_page(url: str) -> tuple[str, str]:
|
|
|
|
| 1 |
+
import os
|
| 2 |
import re
|
| 3 |
import json
|
| 4 |
import shutil
|
| 5 |
import asyncio
|
| 6 |
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
# Cache HF model downloads in persistent storage so cold starts skip re-downloading
|
| 9 |
+
os.environ.setdefault("HF_HOME", "/data/.cache")
|
| 10 |
from typing import Optional, List
|
| 11 |
|
| 12 |
import httpx
|
|
|
|
| 412 |
recall_q = await loop.run_in_executor(None, generate_recall_question, summary, intent or "", claims)
|
| 413 |
update_capture(cid, summary, result.get("tags", []), intent, emb, related, recall_q, claims, source_content_path, title)
|
| 414 |
except Exception as e:
|
| 415 |
+
print(f"[process error] cid={cid} {e}")
|
| 416 |
+
import sqlite3
|
| 417 |
+
try:
|
| 418 |
+
with sqlite3.connect(DB_PATH) as conn:
|
| 419 |
+
conn.execute(
|
| 420 |
+
"UPDATE captures SET summary=?, intent='ephemeral' WHERE id=? AND summary IS NULL",
|
| 421 |
+
("⚠ Processing failed — delete and retry", cid)
|
| 422 |
+
)
|
| 423 |
+
except Exception:
|
| 424 |
+
pass
|
| 425 |
|
| 426 |
|
| 427 |
async def _fetch_page(url: str) -> tuple[str, str]:
|
lm.py
CHANGED
|
@@ -380,7 +380,9 @@ else:
|
|
| 380 |
img = _PILImage.open(file_path).convert("RGB")
|
| 381 |
if max(img.width, img.height) > 768:
|
| 382 |
img.thumbnail((768, 768), _PILImage.LANCZOS)
|
| 383 |
-
inputs
|
|
|
|
|
|
|
| 384 |
with torch.no_grad():
|
| 385 |
out = vl_model.generate(**inputs, max_new_tokens=256)
|
| 386 |
return processor.decode(out[0], skip_special_tokens=True)
|
|
|
|
| 380 |
img = _PILImage.open(file_path).convert("RGB")
|
| 381 |
if max(img.width, img.height) > 768:
|
| 382 |
img.thumbnail((768, 768), _PILImage.LANCZOS)
|
| 383 |
+
# Match inputs to wherever the model actually is (ZeroGPU may or may not have moved it)
|
| 384 |
+
device = next(vl_model.parameters()).device
|
| 385 |
+
inputs = processor(text=text_prompt, images=img, return_tensors="pt").to(device)
|
| 386 |
with torch.no_grad():
|
| 387 |
out = vl_model.generate(**inputs, max_new_tokens=256)
|
| 388 |
return processor.decode(out[0], skip_special_tokens=True)
|