From d798bfbe023f380590f4e7c9f3a0510a10e4afb0 Mon Sep 17 00:00:00 2001 From: Dushyant Acharya Date: Tue, 31 Mar 2026 23:51:36 +0530 Subject: [PATCH 1/2] fix: import Union in main.py and correct pytest directory in Makefile --- Makefile | 2 +- src/main.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 53eb56a..a0d5555 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ pull-model: docker compose exec ollama ollama pull mistral test: - docker compose exec app python3 -m pytest src/test/ + docker compose exec app python3 -m pytest tests/ clean: docker compose down -v diff --git a/src/main.py b/src/main.py index 5bb632b..a17ecb1 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import os +from typing import Union # from backend import Fill from commonforms import prepare_form from pypdf import PdfReader From 6fd3496758575afec3d3f1759998d3efd985672d Mon Sep 17 00:00:00 2001 From: Dushyant Acharya Date: Wed, 1 Apr 2026 00:28:48 +0530 Subject: [PATCH 2/2] feat(pdf): Map Boolean Checkbox and Radio States & Fix main.py NameError Implemented PDF /Btn dictionary parsing in filler.py to extract and dynamically map truthy LLM outputs to their specific 'ON' Appearance Mode instead of blindly appending strings. Also resolved broken backend pipeline in main.py by initializing the base Controller instead of the removed Fill class. --- src/filler.py | 28 ++++++++++++++++++++++++++-- src/main.py | 7 ++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/filler.py b/src/filler.py index e31e535..4073799 100644 --- a/src/filler.py +++ b/src/filler.py @@ -39,8 +39,32 @@ def fill_form(self, pdf_form: str, llm: LLM): for annot in sorted_annots: if annot.Subtype == "/Widget" and annot.T: if i < len(answers_list): - annot.V = f"{answers_list[i]}" - annot.AP = None + answer = answers_list[i] + + # Check if the field type is a Button (Checkbox/Radio) + field_type = annot.FT if annot.FT else (annot.Parent.FT if annot.Parent else None) + if str(field_type) == "/Btn": + is_truthy = str(answer).lower() in ["yes", "true", "1", "x", "on"] + + # Find the 'ON' state from the appearance dictionary + on_state = "/Yes" # Default assumption + if annot.AP and annot.AP.N: + keys = [k for k in annot.AP.N.keys() if k != "/Off"] + if keys: + on_state = keys[0] + + if is_truthy: + from pdfrw import PdfName + annot.V = PdfName(on_state.strip("/")) + annot.AS = PdfName(on_state.strip("/")) + else: + from pdfrw import PdfName + annot.V = PdfName("Off") + annot.AS = PdfName("Off") + else: + annot.V = f"{answer}" + annot.AP = None + i += 1 else: # Stop if we run out of answers diff --git a/src/main.py b/src/main.py index a17ecb1..8ed7e9e 100644 --- a/src/main.py +++ b/src/main.py @@ -31,10 +31,11 @@ def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Unio print("[3] Starting extraction and PDF filling process...") try: - output_name = Fill.fill_form( + controller = Controller() + output_name = controller.fill_form( user_input=user_input, - definitions=definitions, - pdf_form=pdf_form_path + fields=definitions, + pdf_form_path=pdf_form_path ) print("\n----------------------------------")