| # Setup Guide for Colorize API | |
| ## Prerequisites | |
| 1. Python 3.10+ | |
| 2. Docker (for containerized deployment) | |
| 3. Firebase Admin SDK credentials file | |
| 4. Hugging Face account with access to the Colorize Space | |
| ## Local Development Setup | |
| ### 1. Install Dependencies | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| ### 2. Firebase Credentials | |
| Copy your Firebase Admin SDK JSON file to the project root: | |
| - Source: `C:\Colorize\colorize-662df-firebase-adminsdk-fbsvc-e080668793.json` | |
| - Destination: `colorize-662df-firebase-adminsdk-fbsvc-e080668793.json` | |
| Or set the path in environment variable: | |
| ```bash | |
| export FIREBASE_CREDENTIALS_PATH=/path/to/your/firebase-credentials.json | |
| ``` | |
| ### 3. Run the API | |
| ```bash | |
| uvicorn app.main:app --reload --port 7860 | |
| ``` | |
| The API will be available at `http://localhost:7860` | |
| ## Docker Setup | |
| ### 1. Build the Docker Image | |
| ```bash | |
| docker build -t colorize-api . | |
| ``` | |
| ### 2. Run the Container | |
| ```bash | |
| docker run -p 7860:7860 \ | |
| -v $(pwd)/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json:/app/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json \ | |
| -e BASE_URL=http://localhost:7860 \ | |
| colorize-api | |
| ``` | |
| ## Hugging Face Spaces Deployment | |
| ### 1. Prepare Your Repository | |
| ```bash | |
| # Initialize git repository | |
| git init | |
| git add . | |
| git commit -m "Initial commit: Colorize API with Firebase App Check" | |
| ``` | |
| ### 2. Set Up Hugging Face Space | |
| 1. Go to https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize | |
| 2. If the space doesn't exist, create a new Docker space | |
| ### 3. Add Firebase Credentials as Secret | |
| In Hugging Face Space settings: | |
| 1. Go to Settings → Secrets | |
| 2. Add a new secret: | |
| - Name: `FIREBASE_CREDENTIALS` | |
| - Value: Contents of your Firebase Admin SDK JSON file | |
| ### 4. Update Dockerfile for Secrets (if needed) | |
| The Dockerfile will automatically use the credentials file if it exists. For Hugging Face Spaces, you may need to create the file from secrets: | |
| ```dockerfile | |
| # Add this to Dockerfile if using HF secrets | |
| RUN echo "$FIREBASE_CREDENTIALS" > colorize-662df-firebase-adminsdk-fbsvc-e080668793.json || true | |
| ``` | |
| ### 5. Push to Hugging Face | |
| ```bash | |
| git remote add origin https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize | |
| git push -u origin main | |
| ``` | |
| ## Testing the API | |
| ### Health Check | |
| ```bash | |
| curl http://localhost:7860/health | |
| ``` | |
| ### Upload Image (with App Check token) | |
| ```bash | |
| curl -X POST http://localhost:7860/upload \ | |
| -H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \ | |
| -F "file=@path/to/image.jpg" | |
| ``` | |
| ### Colorize Image (with App Check token) | |
| ```bash | |
| curl -X POST http://localhost:7860/colorize \ | |
| -H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \ | |
| -F "file=@path/to/grayscale_image.jpg" | |
| ``` | |
| ## Frontend Integration | |
| ### Initialize Firebase App Check | |
| ```javascript | |
| 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); | |
| // Initialize App Check | |
| const appCheck = initializeAppCheck(app, { | |
| provider: new ReCaptchaEnterpriseProvider('YOUR_RECAPTCHA_SITE_KEY'), | |
| isTokenAutoRefreshEnabled: true | |
| }); | |
| // Get token and make API call | |
| async function colorizeImage(imageFile) { | |
| const token = await appCheck.getToken(); | |
| const formData = new FormData(); | |
| formData.append('file', imageFile); | |
| const response = await fetch('https://your-space.hf.space/colorize', { | |
| method: 'POST', | |
| headers: { | |
| 'X-Firebase-AppCheck': token.token | |
| }, | |
| body: formData | |
| }); | |
| const result = await response.json(); | |
| console.log('Colorized image URL:', result.download_url); | |
| return result; | |
| } | |
| ``` | |
| ## Troubleshooting | |
| ### Model Loading Issues | |
| If the ColorizeNet model fails to load: | |
| 1. Check your internet connection (model downloads from Hugging Face) | |
| 2. Verify you have sufficient disk space | |
| 3. Check logs for specific error messages | |
| ### Firebase App Check Issues | |
| If App Check verification fails: | |
| 1. Verify your Firebase credentials file is correct | |
| 2. Check that App Check is enabled in Firebase Console | |
| 3. Ensure the token is being sent in the `X-Firebase-AppCheck` header | |
| ### Port Issues | |
| Hugging Face Spaces uses port 7860 by default. Make sure your Dockerfile exposes this port. | |
| ## Environment Variables | |
| - `FIREBASE_CREDENTIALS_PATH`: Path to Firebase Admin SDK JSON file | |
| - `ENABLE_APP_CHECK`: Enable/disable Firebase App Check (true/false) | |
| - `BASE_URL`: Base URL for generating download URLs | |
| - `PORT`: Port to run the API on (default: 7860) | |
| - `MODEL_ID`: Hugging Face model ID (default: rsortino/ColorizeNet) | |
| - `NUM_INFERENCE_STEPS`: Number of inference steps (default: 20) | |