chefcodesocr / DEPLOYMENT.md
Mariem-Daha's picture
Upload 27 files
4ded6c8 verified

πŸš€ 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

  1. Go to https://huggingface.co/spaces
  2. Click "Create new Space"
  3. Choose a name (e.g., invoice-ocr-system)
  4. Select Docker as SDK
  5. Choose visibility (Public or Private)
  6. 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

  1. Wait for build to complete (check Build logs)
  2. 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.txt with 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?