File size: 2,637 Bytes
60c56d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
title: Colorize Image API
emoji: 🎨
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: 1.0.0
app_file: Dockerfile
pinned: false
license: mit
---

# 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 deployment
- 📥 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

### Environment Variables

Set these in your Hugging Face Space secrets:

- `FIREBASE_CREDENTIALS_PATH`: Path to Firebase credentials JSON file (or set as secret)
- `ENABLE_APP_CHECK`: Enable/disable Firebase App Check (default: true)
- `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:
```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);
const appCheck = initializeAppCheck(app, {
  provider: new ReCaptchaEnterpriseProvider('your-recaptcha-site-key'),
  isTokenAutoRefreshEnabled: true
});
```

2. Include the token in API requests:
```javascript
const token = await appCheck.getToken();
fetch('https://your-space.hf.space/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