nghia28/formscan-api
0
FormScan ID Extraction API
An advanced PDF ID number extraction API powered by YOLO object detection and Tesseract OCR.
Features
- ๐ฏ Multi-Pattern YOLO Detection: Detects ID documents in PDF files
- ๐ OCR Pattern Matching: Extracts ID numbers with high accuracy
- ๐ธ Image Compression: Ultra/Aggressive compression modes
- โก Fast Processing: Optimized pipeline for quick results
- ๐ก๏ธ Rate Limiting: Built-in protection against abuse
- ๐ Auto Cleanup: Automatic file cleanup after processing
API Endpoints
Health Check
GET /healthExtract ID Numbers
POST /extractParameters:
file: PDF file (required)compression: Compression mode - "ultra" or "aggressive" (default: "ultra")keep_files: Keep intermediate files (default: true)use_multi_pattern: Use multi-pattern detection (default: true)
Usage Example
curl -X POST "https://YOUR-SPACE-NAME.hf.space/extract" \
-F "file=@document.pdf" \
-F "compression=ultra" \
-F "use_multi_pattern=true"Technical Stack
- Framework: FastAPI
- Object Detection: YOLOv8 (Ultralytics)
- OCR Engine: Tesseract OCR
- PDF Processing: PyMuPDF (fitz)
- Image Processing: OpenCV, Pillow
- Deep Learning: PyTorch
Workflow
- PDF โ Images: Convert PDF pages to images
- YOLO Detection: Apply YOLO patterns to detect ID regions
- Region Cropping: Crop detected ID regions
- OCR Pattern Matching: Apply OCR patterns to crops
- ID Extraction: Extract ID numbers using Tesseract
- Compression: Compress and optimize output images
Models
- YOLO Pattern Models: Located in
yolo_pattern/ - OCR Pattern Models: Located in
ocr_pattern/
API Documentation
Once deployed, visit:
- Swagger UI:
https://YOUR-SPACE-NAME.hf.space/docs - ReDoc:
https://YOUR-SPACE-NAME.hf.space/redoc
License
See LICENSE file for details.
Support
For issues or questions, please create an issue on the GitHub repository.
