CoolFace
Apppublic

nghia28/formscan-api

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

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

bash
GET /health

Extract ID Numbers

bash
POST /extract

Parameters:

  • โ€”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

bash
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

  1. 1.PDF โ†’ Images: Convert PDF pages to images
  2. 2.YOLO Detection: Apply YOLO patterns to detect ID regions
  3. 3.Region Cropping: Crop detected ID regions
  4. 4.OCR Pattern Matching: Apply OCR patterns to crops
  5. 5.ID Extraction: Extract ID numbers using Tesseract
  6. 6.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.