ocr / DEPLOYMENT.md
jeyanthangj2004's picture
Upload 110 files
3f42a6f verified

A newer version of the Gradio SDK is available: 6.13.0

Upgrade

πŸš€ Hugging Face Deployment Guide

Complete guide to deploy eDOCr2 on Hugging Face Spaces.

πŸ“‹ Prerequisites

  1. Hugging Face Account - Sign up here
  2. Git LFS installed - For uploading large model files
  3. Model files downloaded - From GitHub Releases

πŸ“¦ Required Files

Your repository should contain:

edocr2/
β”œβ”€β”€ app.py                          # Gradio application
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ packages.txt                    # System dependencies
β”œβ”€β”€ README.md                       # Space description
β”œβ”€β”€ .gitattributes                  # Git LFS configuration
β”œβ”€β”€ edocr2/                         # eDOCr2 package
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ keras_ocr/
β”‚   └── models/                     # Model files (IMPORTANT!)
β”‚       β”œβ”€β”€ recognizer_gdts.keras   # 67.2 MB
β”‚       β”œβ”€β”€ recognizer_gdts.txt
β”‚       β”œβ”€β”€ recognizer_dimensions_2.keras  # 67.2 MB
β”‚       └── recognizer_dimensions_2.txt
└── tests/
    └── test_samples/               # Example images (optional)

πŸ”§ Step-by-Step Deployment

Step 1: Download Model Files

Download the 4 model files from GitHub Releases:

cd edocr2-main
mkdir -p edocr2/models
cd edocr2/models

# Download models (Linux/Mac)
wget https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_gdts.keras
wget https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_gdts.txt
wget https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_dimensions_2.keras
wget https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_dimensions_2.txt

cd ../..

Windows PowerShell:

cd edocr2-main
New-Item -ItemType Directory -Force -Path edocr2\models
cd edocr2\models

Invoke-WebRequest -Uri "https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_gdts.keras" -OutFile "recognizer_gdts.keras"
Invoke-WebRequest -Uri "https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_gdts.txt" -OutFile "recognizer_gdts.txt"
Invoke-WebRequest -Uri "https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_dimensions_2.keras" -OutFile "recognizer_dimensions_2.keras"
Invoke-WebRequest -Uri "https://github.com/javvi51/edocr2/releases/download/v1.0.0/recognizer_dimensions_2.txt" -OutFile "recognizer_dimensions_2.txt"

cd ..\..

Step 2: Install Git LFS

Linux/Mac:

# Ubuntu/Debian
sudo apt-get install git-lfs

# macOS
brew install git-lfs

# Initialize
git lfs install

Windows: Download from git-lfs.github.com and install.

Step 3: Create Hugging Face Space

  1. Go to huggingface.co/spaces
  2. Click "Create new Space"
  3. Fill in details:
    • Space name: edocr2 (or your choice)
    • License: MIT
    • SDK: Gradio
    • Hardware: CPU Basic (free) or GPU (paid)
  4. Click "Create Space"

Step 4: Clone the Space Repository

# Clone your new space
git clone https://huggingface.co/spaces/YOUR_USERNAME/edocr2
cd edocr2

Step 5: Copy Files to Space

# Copy all files from edocr2-main to the space
cp -r /path/to/edocr2-main/* .

# Or on Windows
xcopy /E /I C:\path\to\edocr2-main\* .

Step 6: Track Large Files with Git LFS

# Track model files
git lfs track "*.keras"
git lfs track "edocr2/models/*.keras"

# Verify LFS is working
git lfs ls-files

Step 7: Commit and Push

# Add all files
git add .

# Commit
git commit -m "Initial deployment of eDOCr2"

# Push to Hugging Face
git push origin main

Note: Uploading large files (140 MB total) may take several minutes.

Step 8: Wait for Build

  1. Go to your Space URL: https://huggingface.co/spaces/YOUR_USERNAME/edocr2
  2. Wait for the build to complete (5-10 minutes)
  3. Check the "Logs" tab for any errors

βœ… Verification

Once deployed, your Space should:

  • βœ… Show the Gradio interface
  • βœ… Load models successfully (check logs)
  • βœ… Accept image uploads
  • βœ… Process drawings and show results

πŸ› Troubleshooting

Build Fails

Error: No module named 'edocr2'

Solution: Ensure the edocr2/ folder is in the root directory.

Models Not Found

Error: Model files not found!

Solution:

  • Check edocr2/models/ contains all 4 files
  • Verify Git LFS tracked the .keras files
  • Re-push with git lfs push --all origin main

Out of Memory

Error: Killed or memory errors

Solution:

  • Upgrade to GPU hardware (Settings β†’ Hardware)
  • Or reduce max_img_size in app.py (line with max_img_size=1048)

Timeout Errors

Error: Processing takes too long

Solution:

  • Upgrade to GPU hardware
  • Reduce image resolution before upload
  • Set timeout in Space settings

βš™οΈ Configuration

Change Hardware

  1. Go to Space Settings
  2. Select Hardware tab
  3. Choose:
    • CPU Basic (Free) - Slower, ~30s per image
    • CPU Upgrade ($0.03/hr) - Faster
    • T4 GPU ($0.60/hr) - Fastest, ~10s per image

Set as Private

  1. Go to Space Settings
  2. Toggle "Private" switch
  3. Only you can access the Space

Add Secrets

For API keys or sensitive data:

  1. Settings β†’ Variables and secrets
  2. Add New secret
  3. Access in code: os.environ['SECRET_NAME']

πŸ“Š Monitoring

View Logs

  • Click "Logs" tab in your Space
  • Monitor model loading and processing
  • Check for errors

Analytics

  • Go to "Analytics" tab
  • View usage statistics
  • Monitor performance

πŸ”„ Updating the Space

To update your deployed Space:

# Make changes to files
# Then commit and push
git add .
git commit -m "Update: description of changes"
git push origin main

The Space will automatically rebuild.

πŸ’° Cost Estimation

Free Tier (CPU Basic)

  • βœ… Unlimited usage
  • ⏱️ ~20-30s per image
  • πŸ’Ύ 2 GB RAM
  • πŸ”‹ 2 vCPU

Paid Tier (T4 GPU)

  • πŸ’΅ $0.60/hour
  • ⏱️ ~5-10s per image
  • πŸ’Ύ 16 GB RAM
  • πŸš€ Much faster

Tip: Use CPU Basic for testing, upgrade to GPU for production.

🌐 Custom Domain

To use a custom domain:

  1. Go to Space Settings
  2. "Custom domain" section
  3. Add your domain
  4. Follow DNS configuration instructions

πŸ“± Embedding

Embed your Space in a website:

<iframe
  src="https://YOUR_USERNAME-edocr2.hf.space"
  frameborder="0"
  width="850"
  height="450"
></iframe>

πŸ”— Useful Links

πŸŽ‰ Success!

Your eDOCr2 Space is now live! Share it with:

https://huggingface.co/spaces/YOUR_USERNAME/edocr2

Need help? Open an issue on GitHub