""" PorchaPrahari — West Bengal Land Record Pre-verification (Gradio UI). Pre-checks Bengali property documents (Porcha, Dalil) against Banglarbhumi compliance rules before portal submission. OCR + verification run natively on Gemma 4 12B via transformers (GPU) with no external cloud API. """ import gradio as gr from llm import LLMConfigError, verify, _file_to_images STAGE_PORCHA = "porcha" STAGE_DALIL = "dalil" STAGE_LABELS = { STAGE_PORCHA: "Record of Right (Porcha)", STAGE_DALIL: "Deed of Conveyance (Dalil)" } STAGE_RADIO_CHOICES = [ (STAGE_LABELS[STAGE_PORCHA], STAGE_PORCHA), (STAGE_LABELS[STAGE_DALIL], STAGE_DALIL), ] # Kolkata/Bengal specific document rules mock-database DOC_TYPES = { "RESIDENTIAL": { "code": "RESIDENTIAL", "name": "Bastu (Residential) Property Transfer", "procedure": "Title Verification", "rules": [ {"id": "r1", "check": "Land classification (Shreni) must explicitly mention 'Bastu' (বাস্তু) or 'Homestead'."}, {"id": "r2", "check": "Total land area must be clearly stated in Satak (শতক) or Kathas (কাঠা)."} ] }, "AGRICULTURAL": { "code": "AGRICULTURAL", "name": "Sali (Agricultural) Land Verification", "procedure": "Agricultural Transfer", "rules": [ {"id": "r3", "check": "Land classification must mention 'Sali' (শালি) or 'Agricultural'."}, {"id": "r4", "check": "Must not contain NOC for commercial building construction."} ] } } def required_documents(code, stage): if stage == STAGE_PORCHA: return [ {"id": "d1", "label": "LR Porcha", "verify": "Contains Khaitan No. and LR Dag No.", "note": "Must have govt watermark or signature."}, {"id": "d2", "label": "Owner ID (Aadhaar/EPIC)", "verify": "Name matches the recorded owner on Porcha."} ] else: return [ {"id": "d3", "label": "Registered Dalil", "verify": "Shows buyer, seller, and Mouza details clearly."}, {"id": "d4", "label": "Query Receipt", "verify": "Contains the 14-digit e-Nathikaran query number."} ] # Synthetic SAMPLES for judges to test with 1-click SAMPLES = [ ("🏠 Residential Bastu · Porcha · Bengali", "RESIDENTIAL", STAGE_PORCHA, ["samples/bastu_porcha_pg1.jpg", "samples/owner_aadhaar.jpg"]), ("🌾 Agricultural Sali · Sale Deed · EN+BN", "AGRICULTURAL", STAGE_DALIL, ["samples/sali_dalil_pg1.jpg", "samples/sali_dalil_pg2.jpg"]), ] def package_info_md(code): pkg = DOC_TYPES.get(code) if not pkg: return "" return (f"**{pkg['name']}** \nProcess: {pkg.get('procedure', '—')}") def checklist_md(code, stage): if not code or not stage: return "_Select a transaction type and stage to see required documents._" pkg = DOC_TYPES.get(code) docs = required_documents(code, stage) lines = [f"### Required documents — {STAGE_LABELS[stage]}", f"_{pkg['name']}_", ""] for i, doc in enumerate(docs, 1): line = f"{i}. **{doc['label']}** — {doc['verify']}" lines.append(line) rules = pkg.get("rules", []) if rules: lines.append("\n**Legal Compliance checks:**") for r in rules: lines.append(f"- {r['check']}") return "\n".join(lines) def on_package_change(code, stage): return package_info_md(code), checklist_md(code, stage) def on_stage_change(code, stage): return checklist_md(code, stage) def show_documents(files): images = [] for f in files or []: path = getattr(f, "name", f) try: images.extend(_file_to_images(path)) except Exception: pass return images def run_verification(code, stage, files): if not code or not stage or not files: yield "⚠️ Please select type, stage, and upload documents." return pkg = DOC_TYPES.get(code) docs = required_documents(code, stage) paths = [getattr(f, "name", f) for f in files] yield f"⏳ **Analyzing {len(paths)} document(s)…** Projecting document image patches to Gemma 4 12B for Bengali evaluation." try: result = verify(pkg, STAGE_LABELS[stage], docs, pkg.get("rules", []), paths) except Exception as e: yield f"## ❌ Verification failed\n\nError: `{type(e).__name__}: {e}`" return yield result # --- Styling & UI -------------------------------------------------------------- THEME = gr.themes.Soft(primary_hue=gr.themes.colors.emerald) CSS = """ .gradio-container {max-width: 1500px !important;} #hero { background: linear-gradient(135deg, #059669 0%, #10b981 100%); color: #fff; border-radius: 16px; padding: 28px; } #hero h1 {margin: 0 0 8px 0; font-size: 31px; font-weight: 800;} .pill { display:inline-block; background: rgba(255,255,255,.2); border:1px solid rgba(255,255,255,.4); padding: 5px 13px; border-radius: 999px; font-size: 12.5px; margin: 0 8px 6px 0;} """ HERO = """
An AI pre-check for West Bengal land records. Upload your Bengali Porcha or Dalil. Gemma 4 reads the native Bengali text from the images, verifies mandatory clauses (Dag, Khatian, Mouza), and highlights discrepancies before you submit to Banglarbhumi or execute a real estate deal.