Skip to content
Binary file added .DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,34 @@ __Contributors:__
- Vincent Harkins (@vharkins1)
- Marc Vergés (@marcvergees)
- Jan Sans


## Local Development Setup (Beginner Friendly)

1. Clone your fork and enter project folder:

- git clone <your-fork-url>
cd FireForm (Terminal)

2. Create virtual environment:

- python3 -m venv venv
source venv/bin/activate

3. Install dependencies:

4. Initialize database tables:

5. Run backend server:

6. Open Swagger UI in browser: (http://127.0.0.1:8000/docs)

### Common Errors

- `sqlite3.OperationalError: no such table`
→ Run database initialization step.

- `Could not connect to Ollama`
→ Ensure Ollama server is running locally.


3 changes: 2 additions & 1 deletion api/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class FormSubmission(SQLModel, table=True):
template_id: int
input_text: str
output_pdf_path: str
created_at: datetime = Field(default_factory=datetime.utcnow)
requires_review: bool = False
created_at: datetime = Field(default_factory=datetime.utcnow)
32 changes: 22 additions & 10 deletions api/routes/forms.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter, Depends, Request
from sqlmodel import Session

from api.deps import get_db
from api.schemas.forms import FormFill, FormFillResponse
from api.db.repositories import create_form, get_template
from api.db.models import FormSubmission
from api.errors.base import AppError
from src.controller import Controller
from api.middleware.rate_limiter import limiter

router = APIRouter(prefix="/forms", tags=["forms"])


@router.post("/fill", response_model=FormFillResponse)
def fill_form(form: FormFill, db: Session = Depends(get_db)):
fetched_template = get_template(db, form.template_id)
if not fetched_template:
@limiter.limit("20/minute")
def fill_form(request: Request, form: FormFill, db: Session = Depends(get_db)):
# Single query instead of the previous duplicate get_template() calls
template = get_template(db, form.template_id)
if not template:
raise AppError("Template not found", status_code=404)

controller = Controller()
path = controller.fill_form(
user_input=form.input_text,
fields=fetched_template.fields,
pdf_form_path=fetched_template.pdf_path,
)
try:
path = controller.fill_form(
user_input=form.input_text,
fields=template.fields,
pdf_form_path=template.pdf_path,
)
except AppError:
raise # Re-raise known application errors as-is
except Exception as exc:
raise AppError(
f"Form filling failed: {exc}",
status_code=500,
) from exc

submission = FormSubmission(**form.model_dump(), output_pdf_path=path)
return create_form(db, submission)
return create_form(db, submission)
9 changes: 8 additions & 1 deletion src/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ def __init__(self):
self.file_manipulator = FileManipulator()

def fill_form(self, user_input: str, fields: list, pdf_form_path: str):
return self.file_manipulator.fill_form(user_input, fields, pdf_form_path)
path, review_flag = self.file_manipulator.fill_form(
user_input=user_input,
fields=fields,
pdf_form_path=pdf_form_path
)
return path, review_flag



def create_template(self, pdf_path: str):
return self.file_manipulator.create_template(pdf_path)
8 changes: 1 addition & 7 deletions src/file_manipulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from src.filler import Filler
from src.llm import LLM
from commonforms import prepare_form


class FileManipulator:
Expand All @@ -12,14 +13,7 @@ def create_template(self, pdf_path: str):
"""
By using commonforms, we create an editable .pdf template and we store it.
"""
# Lazy import
from commonforms import prepare_form
template_path = pdf_path[:-4] + "_template.pdf"

os.system("taskkill /F /IM ollama.exe >nul 2>&1")
print("Cleared existing Ollama instances. Starting fresh...")


prepare_form(pdf_path, template_path)
return template_path

Expand Down
Loading