text-guided-image-colorization / .history /README_20251111094025.md
LogicGoInfotechSpaces's picture
Initial commit: Colorize API with Firebase App Check integration
60c56d7
|
raw
history blame
2.92 kB

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

  1. Install dependencies:
pip install -r requirements.txt
  1. Place Firebase credentials file:
colorize-662df-firebase-adminsdk-fbsvc-e080668793.json
  1. Run the application:
uvicorn app.main:app --reload

Docker

  1. Build the image:
docker build -t colorize-api .
  1. 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

  1. 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 file
  • BASE_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

  1. 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
});
  1. 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