CoolFace
Apppublic

breakpointsoftware/document-parser

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
README.md105 linesDownload Raw Back to root
1---2title: Invoice Parser Agent3emoji: ๐Ÿ“š4colorFrom: pink5colorTo: purple6sdk: gradio7sdk_version: 6.20.08python_version: '3.12'9app_file: app.py10pinned: false11---12 13Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference14 15## Drive Folder Scan (Unprocessed Files)16 17The app supports scanning one or more Google Drive folders and parsing only files that were not processed before.18 19### Required environment variables20 21- `GOOGLE_SERVICE_ACCOUNT_JSON` or `GOOGLE_SERVICE_ACCOUNT_FILE`22- `GOOGLE_DRIVE_FOLDER_IDS`: comma-separated Drive folder IDs23 24Optional:25 26- `FIREBASE_TRACK_PROCESSED`: defaults to `true`27- `FIREBASE_TRACKER_COLLECTION`: defaults to `processed_files`28- `FIREBASE_DOCUMENTS_COLLECTION`: defaults to `processed_documents`29- `GOOGLE_DRIVE_FACTURAS_BASE_PATH`: defaults to `Facturas`30- `GOOGLE_DRIVE_INVOICE_ROOT_FOLDER_ID`: optional Drive folder id used as root when creating `GOOGLE_DRIVE_FACTURAS_BASE_PATH`31 32### How it works33 341. Click **Scan Drive folders** in the UI.352. The app recursively scans configured Drive folders.363. Supported file types are downloaded to a temporary local folder (`.txt`, `.pdf`, `.docx`, `.jpg`, `.jpeg`, `.png`).374. Files already registered in Firebase are skipped.385. New files are parsed and appended to the same grid used by uploads.39 40## Drive Orchestration (Status + modificationDate)41 42The orchestration script scans Drive, checks if a document was already processed, parses only new/modified documents, and saves parsed payload + lifecycle status in Firebase.43 44Before each document is persisted, the file is moved in Drive using this path rule:45 46- `Facturas/yyyyMM` for valid invoices where `fecha` can be parsed.47- `Facturas/Corrupted` when required sheet data is missing or `fecha` is not parseable.48 49You can change `Facturas` with `GOOGLE_DRIVE_FACTURAS_BASE_PATH`.50 51### Status rules52 53- `Parsed`: document was never processed before.54- `Modified`: document exists in Firebase but Drive `modifiedTime` changed.55- `Sent`: document was parsed and then sent to Google Sheets.56 57### Run orchestration58 59```bash60python document_orchester.py --model gpt-4o61```62 63Send parsed rows to Google Sheets and mark them as `Sent`:64 65```bash66python document_orchester.py --model gpt-4o --send67```68 69Optional flags:70 71- `--no-subfolders`: scan only direct files in configured folders.72- `--output <path>`: save orchestration summary JSON to a file.73 74## Public API Endpoint For Orchestrator75 76The Gradio app exposes a public API endpoint that internally calls the orchestrator flow.77 78Security:79 80- Set `ORCHESTRATOR_API_KEY` in the server environment.81- Every endpoint call must include that key in the payload.82 83Endpoint name:84 85- `orchestrate_drive_documents`86 87Local URL example:88 89```bash90curl -X POST "http://localhost:7860/gradio_api/call/orchestrate_drive_documents" \91	-H "Content-Type: application/json" \92	-d '{"data": ["gpt-4o", true, false, "YOUR_API_KEY"]}'93```94 95`data` argument order:96 971. `model` (string)982. `include_subfolders` (boolean)993. `send_to_sheet` (boolean)1004. `api_key` (string)101 102Response payload is the same summary produced by `orchestrate_drive_documents` in `document_orchester.py`.103 104When a row is missing required sheet data, it is written to a worksheet named `corrupted data` instead of the main sheet.105