Spaces:
Runtime error
A newer version of the Gradio SDK is available: 6.13.0
π Hugging Face Deployment Guide
Complete guide to deploy eDOCr2 on Hugging Face Spaces.
π Prerequisites
- Hugging Face Account - Sign up here
- Git LFS installed - For uploading large model files
- 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
- Go to huggingface.co/spaces
- Click "Create new Space"
- Fill in details:
- Space name:
edocr2(or your choice) - License: MIT
- SDK: Gradio
- Hardware: CPU Basic (free) or GPU (paid)
- Space name:
- 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
- Go to your Space URL:
https://huggingface.co/spaces/YOUR_USERNAME/edocr2 - Wait for the build to complete (5-10 minutes)
- 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
.kerasfiles - 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_sizeinapp.py(line withmax_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
- Go to Space Settings
- Select Hardware tab
- 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
- Go to Space Settings
- Toggle "Private" switch
- Only you can access the Space
Add Secrets
For API keys or sensitive data:
- Settings β Variables and secrets
- Add New secret
- 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:
- Go to Space Settings
- "Custom domain" section
- Add your domain
- 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
- Hugging Face Docs: huggingface.co/docs/hub/spaces
- Gradio Docs: gradio.app/docs
- Git LFS: git-lfs.github.com
π Success!
Your eDOCr2 Space is now live! Share it with:
https://huggingface.co/spaces/YOUR_USERNAME/edocr2
Need help? Open an issue on GitHub