Spaces:
Sleeping
Sleeping
π Hugging Face Spaces Deployment Checklist
β Pre-Deployment Verification
Files Ready
- β
app.py- FastAPI application (port 7860) - β
ocr_invoice.py- OCR processor - β
cost_tracker.py- Cost tracking - β
auth.py- Authentication - β
setup_hf_credentials.py- HF credentials handler - β
requirements.txt- Dependencies - β
Dockerfile- Container configuration - β
README.md- With HF front matter - β
allowed_users.txt- User access list - β
static/- Frontend files (HTML, CSS, images, logo)
Configuration Ready
- β Port 7860 configured in app.py
- β Docker configuration complete
- β Credential handling implemented
- β All emojis fixed (UTF-8)
- β Logo size optimized (160px)
π Deployment Steps
1. Create New Space on Hugging Face
- Go to https://huggingface.co/spaces
- Click "Create new Space"
- Choose a name (e.g.,
invoice-ocr-system) - Select Docker as SDK
- Choose visibility (Public or Private)
- Click "Create Space"
2. Configure Secrets
Go to your Space Settings β Variables and Secrets β Add Secrets:
| Secret Name | Value | Description |
|---|---|---|
PROJECT_ID |
836634225535 |
Google Cloud Project ID |
LOCATION |
eu |
Document AI location |
PROCESSOR_ID |
696ca0c7b4383217 |
Document AI Processor ID |
GEMINI_API_KEY |
AIzaSyDnUgvtOAmJO2U-Xr90VimD24rydEATH_U |
Gemini API Key |
GOOGLE_APPLICATION_CREDENTIALS_JSON |
(copy from invoice_key.json) | Full JSON credentials file content |
For GOOGLE_APPLICATION_CREDENTIALS_JSON:
Copy the ENTIRE content of your invoice_key.json file as a single line or formatted JSON.
3. Upload Files
Option A: Git Push (Recommended)
# Clone your space
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
cd YOUR_SPACE_NAME
# Copy all files
cp -r /path/to/ocr_invoice/* .
# Commit and push
git add .
git commit -m "Initial deployment"
git push
Option B: Web Upload
- Use the Files tab in your Space
- Upload all files maintaining folder structure
- Make sure
static/folder and all contents are uploaded
4. Verify Deployment
- Wait for build to complete (check Build logs)
- Once running, test the application:
- β Homepage loads correctly
- β Logo displays (160px size)
- β All emojis show correctly (π π€ π¦ π€ π π π° π¦ π΅ π π β )
- β Upload an invoice
- β Check extraction results
- β Verify history works
- β Test download JSON
5. Monitor Costs
Check your Google Cloud console for:
- Document AI usage (~$0.0015 per page)
- Gemini API calls (free tier available)
π§ Troubleshooting
Build Fails
- Check Build logs in Space
- Verify all files uploaded correctly
- Check Dockerfile syntax
Credentials Error
- Verify all 5 secrets are set correctly
- Check GOOGLE_APPLICATION_CREDENTIALS_JSON is valid JSON
- Look at Container logs for credential setup messages
App Won't Start
- Check Container logs for Python errors
- Verify port 7860 is configured
- Check all dependencies in requirements.txt
No Emojis / Corrupted Display
- Hard refresh browser (Ctrl + Shift + R)
- Clear browser cache
- Check file encoding is UTF-8
π Post-Deployment
Access Control
- Update
allowed_users.txtwith Hugging Face usernames - Test OAuth login flow
- Verify unauthorized users are blocked
Performance Monitoring
- Monitor processing times
- Check error rates
- Track API costs
Updates
To update your deployed app:
# Make changes locally
# Commit and push
git add .
git commit -m "Update: description"
git push
Space will automatically rebuild and redeploy.
π Success!
Your Invoice OCR System is now live on Hugging Face Spaces!
Share your Space URL: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
Need Help?
- Hugging Face Docs: https://huggingface.co/docs/hub/spaces
- Discord: Hugging Face Community