basel00omar commited on
Commit
d0d7322
·
1 Parent(s): 0102eee

Add ARCH debug logging to auto_classify

Browse files
Files changed (1) hide show
  1. api/routers/classification.py +26 -5
api/routers/classification.py CHANGED
@@ -42,8 +42,12 @@ async def auto_classify(req: RunExtractionReq, current_user: dict = Depends(get_
42
  str_texts = []
43
  for b in str_boundaries:
44
  pdf_p = os.path.join(project_cache, b.get("pdf_path", ""))
45
- if os.path.exists(pdf_p):
46
- str_texts.extend(extract_page_text(pdf_p))
 
 
 
 
47
 
48
  # Fallback to DB-stored (truncated) texts if PDFs are missing from disk
49
  if not str_texts:
@@ -53,8 +57,12 @@ async def auto_classify(req: RunExtractionReq, current_user: dict = Depends(get_
53
  arch_texts = []
54
  for b in arch_boundaries:
55
  pdf_p = os.path.join(project_cache, b.get("pdf_path", ""))
56
- if os.path.exists(pdf_p):
57
- arch_texts.extend(extract_page_text(pdf_p))
 
 
 
 
58
 
59
  if not arch_texts:
60
  arch_texts = state_data.get("arch_texts") or []
@@ -90,7 +98,20 @@ async def auto_classify(req: RunExtractionReq, current_user: dict = Depends(get_
90
 
91
  return {
92
  "classified_pages": classified,
93
- "next_step": 3
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  }
95
 
96
  def _background_record_memory(user_id: int, pages: list):
 
42
  str_texts = []
43
  for b in str_boundaries:
44
  pdf_p = os.path.join(project_cache, b.get("pdf_path", ""))
45
+ exists = os.path.exists(pdf_p)
46
+ print(f"[classify/auto] STR PDF path={pdf_p} exists={exists}")
47
+ if exists:
48
+ extracted = extract_page_text(pdf_p)
49
+ print(f"[classify/auto] STR extracted {len(extracted)} pages, first 200 chars: {extracted[0][:200] if extracted else '(none)'}")
50
+ str_texts.extend(extracted)
51
 
52
  # Fallback to DB-stored (truncated) texts if PDFs are missing from disk
53
  if not str_texts:
 
57
  arch_texts = []
58
  for b in arch_boundaries:
59
  pdf_p = os.path.join(project_cache, b.get("pdf_path", ""))
60
+ exists = os.path.exists(pdf_p)
61
+ print(f"[classify/auto] ARCH PDF path={pdf_p} exists={exists}")
62
+ if exists:
63
+ extracted = extract_page_text(pdf_p)
64
+ print(f"[classify/auto] ARCH extracted {len(extracted)} pages, first 200 chars: {extracted[0][:200] if extracted else '(none)'}")
65
+ arch_texts.extend(extracted)
66
 
67
  if not arch_texts:
68
  arch_texts = state_data.get("arch_texts") or []
 
98
 
99
  return {
100
  "classified_pages": classified,
101
+ "next_step": 3,
102
+ "_debug": {
103
+ "cache_dir": project_cache,
104
+ "cache_exists": os.path.isdir(project_cache),
105
+ "cache_files": os.listdir(project_cache) if os.path.isdir(project_cache) else [],
106
+ "str_boundaries": str_boundaries,
107
+ "arch_boundaries": arch_boundaries,
108
+ "str_texts_count": len(str_texts),
109
+ "arch_texts_count": len(arch_texts),
110
+ "str_text_sample": str_texts[0][:300] if str_texts else "(empty)",
111
+ "arch_text_sample": arch_texts[0][:300] if arch_texts else "(empty)",
112
+ "unknown_count": sum(1 for p in classified if p.get("detected_type") == "unknown"),
113
+ "total_classified": len(classified),
114
+ }
115
  }
116
 
117
  def _background_record_memory(user_id: int, pages: list):