Text Extraction Done, UI Fixes Done, Extracted Template Layout Saved in DB

This commit is contained in:
2026-07-12 14:24:17 +05:30
parent 3163bb213e
commit 3d6614f408
79 changed files with 3139 additions and 81 deletions

42
SESSION_HANDOFF.md Normal file
View File

@@ -0,0 +1,42 @@
# Session Handoff & Context
**Date Saved**: June 7, 2026
**Conversation ID**: 43f3aa27-9124-446e-9713-4e31e083b4f5
## Project: Template Mapping Engine (OCR)
A system designed to extract document layouts via OCR and allow users to map specific bounding box regions to template fields using a drag-and-drop UI. Future documents from the same vendor are automatically recognized and mapped using a heuristic template engine.
## What Has Been Completed So Far
### 1. Backend Startup & Dependency Fixes:
- **Auto-Bootstrapping**: Updated `run_docengine.sh` and `run_backend.sh` to automatically set up virtual environments and install missing dependencies if key modules (`uvicorn`, `numpy`, etc.) are missing.
- **Python 3.13 Compatibility**: Upgraded `paddlepaddle` in `docengine/requirements.txt` to `>=3.0.0` to support Python 3.13 on macOS ARM64. Added missing dependencies (`numpy`, `opencv-python-headless`, `pdf2image`) to `backend/requirements.txt`.
- **CORS Config Fix**: Corrected a missing double-quote in `CORS_ORIGINS` in both `.env` and `.env.example` in `docengine/`.
### 2. Backend Code Integrity & Framework Alignment:
- **SQLAlchemy 2.0 / Imperative Mapping Fix**: Updated `user_roles_table` in `docengine/app/models/user.py` to use SQLAlchemy `Column` objects instead of `mapped_column`, preventing a database initialization crash.
- **Structlog Parameter Fix**: Replaced the `event` keyword argument with `phase` in `docengine/app/events/handlers.py` to prevent a duplicate parameter `TypeError` from the structlog library.
- **Optional Development Auth Bypass**: Modified `get_current_user` in `docengine/app/core/dependencies.py` to automatically fallback to the first database user (or a fake dev admin model) when no authorization token is supplied and `APP_ENV` is set to `"development"`. This prevents `401 Unauthorized` errors when testing endpoints locally.
### 3. Frontend Angular Implementation:
- **API Endpoint Alignments**: Removed the duplicate `/api` prefix from endpoints in `TemplateService.ts` (e.g. changing `${this.apiUrl}/api/documents/upload` to `${this.apiUrl}/documents/upload`). This resolves the `404 Not Found` error by aligning with the backend prefix `/api/v1/documents/upload`.
---
## Where to Pick Up Next
1. **Initialize Database Tables**:
- The database currently lacks the necessary schema tables (evidenced by the error: `relation "admin.users" does not exist`).
- Run the setup command to build the tables and apply migrations:
```bash
./run_docengine.sh setup
```
2. **Retest Upload Flow**:
- Once database tables exist, perform a document upload from the Angular frontend to visually verify the OCR bounding boxes and layout mapper.
3. **Verify Heuristic Template Recognition**:
- Test the template matching and layout coordinate storage workflows.
---
## How to Resume with AI Assistant
To resume this session in a new chat, you can tell the AI:
*"Please read `SESSION_HANDOFF.md` in the root of the OCR project to get context on the Template Engine we were building and the startup fixes, and let's continue."*