Deployment Guide
Quick Start
1. Copy Firebase Credentials
Copy your Firebase Admin SDK JSON file to the project root:
# Windows
copy C:\Colorize\colorize-662df-firebase-adminsdk-fbsvc-e080668793.json .
# Linux/Mac
cp /path/to/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json .
Important: For Hugging Face Spaces, you should add this as a secret instead of committing it to the repository.
2. Deploy to Hugging Face Spaces
# Initialize git repository
git init
git add .
git commit -m "Deploy Colorize API"
# Add Hugging Face remote
git remote add origin https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize
# Push to Hugging Face
git push -u origin main
3. Configure Hugging Face Space Secrets
- Go to your Space: https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize
- Navigate to Settings → Secrets
- Add a new secret:
- Name:
FIREBASE_CREDENTIALS - Value: Paste the entire contents of your Firebase Admin SDK JSON file
- Name:
4. Update Dockerfile for Secrets (Optional)
If you want to use the secret, you can modify the Dockerfile to create the file from the secret:
# Add this before the CMD line
RUN if [ -n "$FIREBASE_CREDENTIALS" ]; then \
echo "$FIREBASE_CREDENTIALS" > colorize-662df-firebase-adminsdk-fbsvc-e080668793.json; \
fi
Testing Locally
Run with Docker
# Build image
docker build -t colorize-api .
# Run container
docker run -p 7860:7860 \
-v $(pwd)/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json:/app/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json \
colorize-api
Run without Docker
# Install dependencies
pip install -r requirements.txt
# Run API
uvicorn app.main:app --host 0.0.0.0 --port 7860
API Endpoints
Once deployed, your API will be available at:
https://logicgoinfotechspaces-colorize.hf.space/health- Health checkhttps://logicgoinfotechspaces-colorize.hf.space/colorize- Colorize imagehttps://logicgoinfotechspaces-colorize.hf.space/upload- Upload image
Frontend Integration Example
// Initialize Firebase
import { initializeApp } from "firebase/app";
import { initializeAppCheck, ReCaptchaEnterpriseProvider } from "firebase/app-check";
const firebaseConfig = {
apiKey: "AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68",
authDomain: "colorize-662df.firebaseapp.com",
projectId: "colorize-662df",
storageBucket: "colorize-662df.firebasestorage.app",
messagingSenderId: "69166278311",
appId: "1:69166278311:web:0e8c50b8dd8627aaeadd82",
measurementId: "G-58CC2J8XKX"
};
const app = initializeApp(firebaseConfig);
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaEnterpriseProvider('YOUR_RECAPTCHA_SITE_KEY'),
isTokenAutoRefreshEnabled: true
});
// Colorize image function
async function colorizeImage(file) {
const { getToken } = await import('firebase/app-check');
const token = await getToken(appCheck);
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://logicgoinfotechspaces-colorize.hf.space/colorize', {
method: 'POST',
headers: {
'X-Firebase-AppCheck': token.token
},
body: formData
});
return await response.json();
}
Troubleshooting
Model Not Loading
- Check Hugging Face Space logs
- Verify model ID:
rsortino/ColorizeNet - Ensure sufficient disk space (models can be large)
Firebase App Check Failing
- Verify credentials are correctly set as a secret
- Check that App Check is enabled in Firebase Console
- Ensure reCAPTCHA Enterprise is set up
Port Issues
Hugging Face Spaces automatically handles port 7860. The Dockerfile is configured for this.