Colorize Image API
FastAPI-based image colorization service using ColorizeNet model with Firebase App Check integration.
Features
- 🖼️ Image upload and colorization
- 🔒 Firebase App Check authentication
- 🐳 Docker support
- 🚀 Hugging Face Spaces deployment ready
- 📥 Download URLs for browser access
API Endpoints
Health Check
GET /health
Returns the health status of the API and model.
Upload Image
POST /upload
Headers: X-Firebase-AppCheck: <token>
Body: multipart/form-data with image file
Uploads an image and returns the image URL.
Colorize Image
POST /colorize
Headers: X-Firebase-AppCheck: <token>
Body: multipart/form-data with image file
Colorizes a grayscale image and returns the result URL.
Download Result
GET /download/{file_id}
Headers: X-Firebase-AppCheck: <token>
Downloads the colorized image by file ID.
Get Result (Public)
GET /results/{filename}
Public endpoint to access colorized images in browser.
Setup
Local Development
- Install dependencies:
pip install -r requirements.txt
- Place Firebase credentials file:
colorize-662df-firebase-adminsdk-fbsvc-e080668793.json
- Run the application:
uvicorn app.main:app --reload
Docker
- Build the image:
docker build -t colorize-api .
- Run the container:
docker run -p 8000:8000 \
-v $(pwd)/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json:/app/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json \
colorize-api
Hugging Face Spaces
- Push to Hugging Face Space:
git init
git add .
git commit -m "Initial commit"
git remote add origin https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize
git push -u origin main
Environment Variables
ENABLE_APP_CHECK: Enable/disable Firebase App Check (default: true)FIREBASE_CREDENTIALS_PATH: Path to Firebase credentials JSON fileBASE_URL: Base URL for the API (for generating download URLs)MODEL_ID: Hugging Face model ID (default: rsortino/ColorizeNet)NUM_INFERENCE_STEPS: Number of inference steps (default: 20)
Firebase App Check Setup
- Initialize Firebase App Check in your frontend:
import { initializeApp } from "firebase/app";
import { initializeAppCheck, ReCaptchaEnterpriseProvider } from "firebase/app-check";
const app = initializeApp(firebaseConfig);
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaEnterpriseProvider('your-recaptcha-site-key'),
isTokenAutoRefreshEnabled: true
});
- Include the token in API requests:
const token = await appCheck.getToken();
fetch('/colorize', {
method: 'POST',
headers: {
'X-Firebase-AppCheck': token.token
},
body: formData
});
Model
This API uses the rsortino/ColorizeNet model from Hugging Face for image colorization.
License
MIT