-
Notifications
You must be signed in to change notification settings - Fork 152
feat: Checkboxes and Radio Button Mapping for PDFs (GSoC) #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dotify71
wants to merge
7
commits into
fireform-core:main
Choose a base branch
from
Dotify71:fix/startup-and-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−23
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d798bfb
fix: import Union in main.py and correct pytest directory in Makefile
6fd3496
feat(pdf): Map Boolean Checkbox and Radio States & Fix main.py NameError
15122f6
Merge branch 'upstream/main' into fix/startup-and-tests
Dotify71 9feeb78
feat(pdf): enforce strict boolean typing for checkbox/radio fields
Dotify71 6977124
Merge upstream/main and resolve conflicts
Dotify71 a10663d
fix: add strict boolean schema validation and retry loop
Dotify71 c525c9b
Merge branch 'main' into fix/startup-and-tests
Dotify71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| from typing import Union | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Union is not used in new versions of python use the "|" operator instead. |
||
| import os | ||
|
|
||
| os.environ["CUDA_VISIBLE_DEVICES"] = "" | ||
|
|
||
| # Monkey patch rfdetr to force CPU usage on Mac Silicon / Docker | ||
|
|
@@ -12,22 +14,68 @@ | |
| except ImportError: | ||
| pass | ||
|
|
||
| from commonforms import prepare_form | ||
| from commonforms import prepare_form | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI models create unnecessary spaces in the end of the line, get rid of them. |
||
| from pypdf import PdfReader | ||
| from controller import Controller | ||
|
|
||
| def input_fields(num_fields: int): | ||
| fields = [] | ||
| for i in range(num_fields): | ||
| field = input(f"Enter description for field {i + 1}: ") | ||
| fields.append(field) | ||
| return fields | ||
|
|
||
| def run_pdf_fill_process(user_input: str, definitions: list, pdf_form_path: Union[str, os.PathLike]): | ||
| """ | ||
| This function is called by the frontend server. | ||
| It receives the raw data, runs the PDF filling logic, | ||
| and returns the path to the newly created file. | ||
| """ | ||
|
|
||
| print("[1] Received request from frontend.") | ||
| print(f"[2] PDF template path: {pdf_form_path}") | ||
|
|
||
| # Normalize Path/PathLike to a plain string for downstream code | ||
| pdf_form_path = os.fspath(pdf_form_path) | ||
|
|
||
| if not os.path.exists(pdf_form_path): | ||
| print(f"Error: PDF template not found at {pdf_form_path}") | ||
| return None # Or raise an exception | ||
|
|
||
| print("[3] Starting extraction and PDF filling process...") | ||
| try: | ||
| controller = Controller() | ||
| output_name = controller.fill_form( | ||
| user_input=user_input, | ||
| fields=definitions, | ||
| pdf_form_path=pdf_form_path | ||
| ) | ||
|
|
||
| print("\n----------------------------------") | ||
| print(f"✅ Process Complete.") | ||
| print(f"Output saved to: {output_name}") | ||
|
|
||
| return output_name | ||
|
|
||
| except Exception as e: | ||
| print(f"An error occurred during PDF generation: {e}") | ||
| # Re-raise the exception so the frontend can handle it | ||
| raise e | ||
| if __name__ == "__main__": | ||
| file = "./src/inputs/file.pdf" | ||
| user_input = "Hi. The employee's name is John Doe. His job title is managing director. His department supervisor is Jane Doe. His phone number is 123456. His email is jdoe@ucsc.edu. The signature is <Mamañema>, and the date is 01/02/2005" | ||
| fields = [ | ||
| "Employee's name", | ||
| "Employee's job title", | ||
| "Employee's department supervisor", | ||
| "Employee's phone number", | ||
| "Employee's email", | ||
| "Signature", | ||
| "Date", | ||
| ] | ||
| # Fields dict maps each field name to its expected Python type. | ||
| # Use `bool` for checkbox/radio fields so the LLM is instructed to | ||
| # return exactly True or False instead of fuzzy strings like "yes". | ||
| fields = { | ||
| "Employee's name": str, | ||
| "Employee's job title": str, | ||
| "Employee's department supervisor": str, | ||
| "Employee's phone number": str, | ||
| "Employee's email": str, | ||
| "Signature": str, | ||
| "Date": str, | ||
| } | ||
| prepared_pdf = "temp_outfile.pdf" | ||
| prepare_form(file, prepared_pdf) | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be updated with the new removal of handle_plural_values.