Spaces:
Sleeping
Hugging Face Spaces Setup Guide
This guide provides specific instructions for deploying the EZOFIS OCR application to Hugging Face Spaces.
Prerequisites
- β Firebase project configured
- β Brevo account set up
- β Hugging Face account with a Space created
Step 1: Frontend Environment Variables
Set these in Hugging Face Spaces β Settings β Variables and secrets:
Variables (Public):
VITE_FIREBASE_API_KEYβ Set as Secret (Private) βVITE_FIREBASE_AUTH_DOMAINβ Set as Variable (Public)VITE_FIREBASE_PROJECT_IDβ Set as Variable (Public)VITE_FIREBASE_STORAGE_BUCKETβ Set as Variable (Public)VITE_FIREBASE_MESSAGING_SENDER_IDβ Set as Variable (Public)VITE_FIREBASE_APP_IDβ Set as Variable (Public)VITE_API_BASE_URLβ Set as Variable (Public) (e.g.,https://your-username-ezofisocr.hf.space)
Note: These variables are used during the Docker build process. The Dockerfile has been updated to accept them as build arguments.
Step 2: Backend Environment Variables
Set these in Hugging Face Spaces β Settings β Variables and secrets:
Secrets (Private):
FIREBASE_SERVICE_ACCOUNT_JSON- Get your Firebase service account JSON file (from Firebase Console β Project Settings β Service accounts)
- Copy the entire JSON content (all in one line or formatted)
- Paste it as the value for this secret
- Example format:
{"type":"service_account","project_id":"your-project","private_key_id":"...","private_key":"-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n","client_email":"...","client_id":"...","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_x509_cert_url":"..."}
BREVO_API_KEY- Get from Brevo β Settings β API Keys
- Format:
xkeysib-...
JWT_SECRET_KEY- Generate a secure random key:
openssl rand -hex 32 - Or use Python:
python -c "import secrets; print(secrets.token_hex(32))"
- Generate a secure random key:
Variables (Public):
BREVO_SENDER_EMAIL- Your verified sender email in Brevo
- Example:
noreply@yourdomain.com
BREVO_SENDER_NAME- Display name for emails
- Example:
EZOFIS AI
FRONTEND_URL- Your Hugging Face Space URL
- Format:
https://your-username-ezofisocr.hf.space - Replace
your-usernamewith your actual Hugging Face username
Step 3: Verify Dockerfile
The Dockerfile has been updated to accept frontend environment variables as build arguments. Make sure your Dockerfile includes:
# Accept build arguments for Vite environment variables
ARG VITE_FIREBASE_API_KEY
ARG VITE_FIREBASE_AUTH_DOMAIN
ARG VITE_FIREBASE_PROJECT_ID
ARG VITE_FIREBASE_STORAGE_BUCKET
ARG VITE_FIREBASE_MESSAGING_SENDER_ID
ARG VITE_FIREBASE_APP_ID
ARG VITE_API_BASE_URL
# Set as environment variables so Vite can access them during build
ENV VITE_FIREBASE_API_KEY=$VITE_FIREBASE_API_KEY
ENV VITE_FIREBASE_AUTH_DOMAIN=$VITE_FIREBASE_AUTH_DOMAIN
ENV VITE_FIREBASE_PROJECT_ID=$VITE_FIREBASE_PROJECT_ID
ENV VITE_FIREBASE_STORAGE_BUCKET=$VITE_FIREBASE_STORAGE_BUCKET
ENV VITE_FIREBASE_MESSAGING_SENDER_ID=$VITE_FIREBASE_MESSAGING_SENDER_ID
ENV VITE_FIREBASE_APP_ID=$VITE_FIREBASE_APP_ID
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
Step 4: Deploy
- Commit and push your code to the Hugging Face Space repository
- Make sure
frontend/build-env.shis included in your commit
- Make sure
- Wait for the build to complete (check the "Logs" tab)
- Look for "Checking environment variables..." messages in the build logs
- Verify all variables show "β ... is set" (not "WARNING: ... is not set")
- Test the deployment:
- Open your Space URL
- Try Firebase login
- Try OTP authentication
Important: After setting or updating environment variables in Hugging Face Spaces, you need to rebuild the Space for the changes to take effect. The frontend is built during the Docker build process, so environment variable changes require a rebuild.
Troubleshooting
Build Fails with "VITE_* variables not found"
- Solution: Make sure all
VITE_*variables are set in Spaces β Variables and secrets - Hugging Face Spaces automatically makes environment variables available during build
- The Dockerfile uses a build script to create a
.envfile from these variables
Firebase Authentication Not Working - "auth/invalid-api-key" Error
- Check:
VITE_FIREBASE_API_KEYis set correctly (as a Secret) and contains the full API key - Check: All other
VITE_FIREBASE_*variables are set with correct values - Check: After updating variables, rebuild the Space (the frontend needs to be rebuilt)
- Check: Firebase Console β Authentication β Sign-in method β Google is enabled
- Check: The API key matches the one in Firebase Console β Project Settings β Your apps
- Solution: If the error persists, check the build logs to see if the
.envfile is being created correctly
OTP Emails Not Sending
- Check:
BREVO_API_KEYis set correctly (as a Secret) - Check:
BREVO_SENDER_EMAILis verified in Brevo - Check:
BREVO_SENDER_NAMEis set - Check: You haven't exceeded Brevo free tier (300 emails/day)
Backend Errors
- Check:
FIREBASE_SERVICE_ACCOUNT_JSONcontains the full JSON (all fields) - Check:
JWT_SECRET_KEYis set - Check:
FRONTEND_URLmatches your Space URL exactly
Environment Variables Checklist
Frontend (Build-time):
-
VITE_FIREBASE_API_KEY(Secret) -
VITE_FIREBASE_AUTH_DOMAIN(Variable) -
VITE_FIREBASE_PROJECT_ID(Variable) -
VITE_FIREBASE_STORAGE_BUCKET(Variable) -
VITE_FIREBASE_MESSAGING_SENDER_ID(Variable) -
VITE_FIREBASE_APP_ID(Variable) -
VITE_API_BASE_URL(Variable)
Backend (Runtime):
-
FIREBASE_SERVICE_ACCOUNT_JSON(Secret) -
BREVO_API_KEY(Secret) -
JWT_SECRET_KEY(Secret) -
BREVO_SENDER_EMAIL(Variable) -
BREVO_SENDER_NAME(Variable) -
FRONTEND_URL(Variable)
Notes
Build vs Runtime: Frontend variables (
VITE_*) are used during Docker build, backend variables are used at runtime.Secrets vs Variables:
- Use Secrets for sensitive data (API keys, private keys, JWT secrets)
- Use Variables for non-sensitive configuration (URLs, display names)
Firebase Service Account JSON: When copying the JSON, make sure to include the entire content, including the
private_keyfield with newlines preserved (they should be\nin the JSON string).Space URL: Your Space URL format is
https://{username}-{space-name}.hf.space. Make sureFRONTEND_URLandVITE_API_BASE_URLmatch this exactly.
Support
If you encounter issues:
- Check the build logs in Hugging Face Spaces
- Verify all environment variables are set correctly
- Ensure Firebase and Brevo are properly configured
- Review the main setup guide:
FIREBASE_OTP_SETUP.md