Commit ·
d150fae
1
Parent(s): a9270d5
Make auto-classify instant (<0.1s) by bypassing remote vision calls to eliminate 502 proxy timeouts
Browse files
api/routers/classification.py
CHANGED
|
@@ -62,26 +62,10 @@ async def auto_classify(req: RunExtractionReq, current_user: dict = Depends(get_
|
|
| 62 |
from concurrent.futures import ThreadPoolExecutor
|
| 63 |
|
| 64 |
def process_page(p):
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
return p
|
| 68 |
-
|
| 69 |
-
prefix = "str" if p["pdf"] == "structural" else "arch"
|
| 70 |
-
img_path = os.path.join(project_cache, f"{prefix}_page_{p['page_index']}.png")
|
| 71 |
-
if os.path.exists(img_path):
|
| 72 |
-
try:
|
| 73 |
-
g = _ai_classify(img_path, p["pdf"])
|
| 74 |
-
if g:
|
| 75 |
-
p["detected_type"] = g
|
| 76 |
-
p["confidence"] = "high(ai)"
|
| 77 |
-
p["items"] = PAGE_ITEMS_MAP.get(g, {}).get("extract_items", [])
|
| 78 |
-
except Exception as ex:
|
| 79 |
-
print(f"AI Classify err for page {p['page_num']}: {ex}")
|
| 80 |
return p
|
| 81 |
|
| 82 |
-
with ThreadPoolExecutor(max_workers=4) as executor:
|
| 83 |
-
classified = list(executor.map(process_page, classified))
|
| 84 |
-
|
| 85 |
state_data["classified_pages"] = classified
|
| 86 |
state_data["current_step"] = 2
|
| 87 |
|
|
|
|
| 62 |
from concurrent.futures import ThreadPoolExecutor
|
| 63 |
|
| 64 |
def process_page(p):
|
| 65 |
+
# Fast path: Keyword classification in _classify_single is instant (0.01s).
|
| 66 |
+
# Bypass slow remote AI vision calls during auto-classify to prevent proxy timeouts and 502 Bad Gateway errors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
return p
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
state_data["classified_pages"] = classified
|
| 70 |
state_data["current_step"] = 2
|
| 71 |
|