feat: complete platform overhaul, bugfixes, and verified production release

This commit is contained in:
Atharv1705
2026-10-28 21:47:48 +05:30
parent 276039a743
commit 3cb6229cd9
62 changed files with 1820 additions and 548 deletions
+16 -4
View File
@@ -2,7 +2,7 @@
Document type classifier for the "other_*" catch-all upload bucket.
When a user uploads via the "Additional Documents" slot, doc_type is set to
`other_<timestamp>_<index>` — a meaningless slug. This module detects the
`other_<timestamp>_<index>` ? a meaningless slug. This module detects the
actual document type from OCR text + filename so the extraction prompt
becomes type-specific rather than generic.
@@ -24,6 +24,12 @@ class DocCategory(str, Enum):
AADHAAR = "Aadhaar Card"
W2 = "W-2 Wage Statement"
FORM_1099 = "1099 Income Form"
FORM_1040 = "Form 1040 (U.S. Individual Income Tax Return)"
FORM_1120 = "Form 1120/1120-S (U.S. Corporation Tax Return)"
FORM_1065 = "Form 1065 (U.S. Partnership Tax Return)"
SCHEDULE_K1 = "Schedule K-1"
FORM_W9 = "Form W-9 (TIN Request)"
EIN_LETTER = "IRS EIN Assignment Letter"
ENGAGEMENT_LETTER = "Engagement Letter"
TAX_ORGANIZER = "Tax Organizer"
INVOICE = "Invoice / Bill"
@@ -33,7 +39,7 @@ class DocCategory(str, Enum):
GENERIC = "Other Document"
# Priority-ordered keyword patterns — first match wins
# Priority-ordered keyword patterns ? first match wins
_PATTERNS: list[tuple[re.Pattern, DocCategory]] = [
# Government IDs
(re.compile(r'\bPERMANENT\s+ACCOUNT\s+NUMBER\b|\bINCOME\s+TAX\s+DEPT\b', re.I), DocCategory.PAN_CARD),
@@ -43,6 +49,12 @@ _PATTERNS: list[tuple[re.Pattern, DocCategory]] = [
# US Tax forms
(re.compile(r'\bW-?2\b.*\bWAGES\b|\bWAGES.*TIPS.*OTHER\b|\bFEDERAL\s+INCOME\s+TAX\s+WITHHELD\b', re.I), DocCategory.W2),
(re.compile(r'\b1099-?[A-Z]{0,4}\b|\bNONEMPLOYEE\s+COMPENSATION\b|\bMISCELLANEOUS\s+INCOME\b', re.I), DocCategory.FORM_1099),
(re.compile(r'\bFORM\s+1040\b|\b1040-?SR\b|\bU\.S\.\s+INDIVIDUAL\s+INCOME\s+TAX\s+RETURN\b', re.I), DocCategory.FORM_1040),
(re.compile(r'\bFORM\s+1120\b|\b1120-?S\b|\bU\.S\.\s+(CORPORATION|INCOME\s+TAX\s+RETURN\s+FOR\s+AN\s+S\s+CORPORATION)\b', re.I), DocCategory.FORM_1120),
(re.compile(r'\bSCHEDULE\s+K-?1\b|\bPARTNER[\'?]S\s+SHARE\s+OF\s+INCOME\b', re.I), DocCategory.SCHEDULE_K1),
(re.compile(r'\bFORM\s+1065\b|\bU\.S\.\s+RETURN\s+OF\s+PARTNERSHIP\s+INCOME\b', re.I), DocCategory.FORM_1065),
(re.compile(r'\bFORM\s+W-?9\b|\bREQUEST\s+FOR\s+TAXPAYER\s+IDENTIFICATION\b', re.I), DocCategory.FORM_W9),
(re.compile(r'\bCP\s*575\b|\bASSIGNED\s+EMPLOYER\s+IDENTIFICATION\s+NUMBER\b|\bFORM\s+SS-?4\b', re.I), DocCategory.EIN_LETTER),
# Accounting documents
(re.compile(r'\bENGAGEMENT\s+LETTER\b|\bTAX\s+RETURN\s+PREPARATION\s+SERVICES\b', re.I), DocCategory.ENGAGEMENT_LETTER),
(re.compile(r'\bTAX\s+ORGANIZER\b|\bLLC\s+TAX\b|\bS[-\s]?CORP\b|\bPARTNERSHIP\s+TAX\b', re.I), DocCategory.TAX_ORGANIZER),
@@ -61,7 +73,7 @@ def classify_other_doc(
Args:
ocr_text: Raw text extracted from the document (any amount).
filename: Original upload filename — used as a secondary hint.
filename: Original upload filename ? used as a secondary hint.
"""
corpus = f"{filename} {ocr_text}"
@@ -70,7 +82,7 @@ def classify_other_doc(
logger.info(f"[DocClassifier] Detected '{category.value}' from other_* upload")
return category
logger.info("[DocClassifier] No match — defaulting to GENERIC")
logger.info("[DocClassifier] No match ? defaulting to GENERIC")
return DocCategory.GENERIC