File size: 11,667 Bytes
2ae242d |
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# Colorize API Documentation
## Base URL
```
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space
```
For local development:
```
http://localhost:7860
```
## Authentication
All endpoints (except `/health` and public result endpoints) require Firebase App Check authentication.
Include the App Check token in the request header:
```
X-Firebase-AppCheck: <your-app-check-token>
```
## Endpoints
### 1. Health Check
Check the health status of the API and model.
**Endpoint:** `GET /health`
**Authentication:** Not required
**Response:**
```json
{
"status": "healthy",
"model_loaded": true
}
```
**Example:**
```bash
curl https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/health
```
**Response Codes:**
- `200 OK` - API is healthy
- `503 Service Unavailable` - Model not loaded
---
### 2. Upload Image
Upload an image and get the uploaded image URL.
**Endpoint:** `POST /upload`
**Authentication:** Required (Firebase App Check token)
**Request:**
- **Method:** `POST`
- **Content-Type:** `multipart/form-data`
- **Headers:**
- `X-Firebase-AppCheck: <token>`
- **Body:**
- `file`: Image file (JPEG, PNG, etc.)
**Response:**
```json
{
"success": true,
"image_id": "550e8400-e29b-41d4-a716-446655440000",
"image_url": "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/uploads/550e8400-e29b-41d4-a716-446655440000.jpg",
"filename": "550e8400-e29b-41d4-a716-446655440000.jpg"
}
```
**Example using cURL:**
```bash
curl -X POST \
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/upload \
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
-F "file=@/path/to/image.jpg"
```
**Example using JavaScript:**
```javascript
const formData = new FormData();
formData.append('file', imageFile);
const response = await fetch('https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/upload', {
method: 'POST',
headers: {
'X-Firebase-AppCheck': appCheckToken
},
body: formData
});
const result = await response.json();
console.log(result.image_url);
```
**Response Codes:**
- `200 OK` - Image uploaded successfully
- `400 Bad Request` - Invalid file type or missing file
- `401 Unauthorized` - Missing or invalid App Check token
- `500 Internal Server Error` - Server error during upload
---
### 3. Colorize Image
Colorize a grayscale or low-color image using ColorizeNet model.
**Endpoint:** `POST /colorize`
**Authentication:** Required (Firebase App Check token)
**Request:**
- **Method:** `POST`
- **Content-Type:** `multipart/form-data`
- **Headers:**
- `X-Firebase-AppCheck: <token>`
- **Body:**
- `file`: Image file (JPEG, PNG, etc.)
**Response:**
```json
{
"success": true,
"result_id": "550e8400-e29b-41d4-a716-446655440000",
"download_url": "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/results/550e8400-e29b-41d4-a716-446655440000.jpg",
"api_download_url": "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/download/550e8400-e29b-41d4-a716-446655440000",
"filename": "550e8400-e29b-41d4-a716-446655440000.jpg"
}
```
**Example using cURL:**
```bash
curl -X POST \
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize \
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
-F "file=@/path/to/grayscale_image.jpg"
```
**Example using JavaScript:**
```javascript
const formData = new FormData();
formData.append('file', imageFile);
const response = await fetch('https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize', {
method: 'POST',
headers: {
'X-Firebase-AppCheck': appCheckToken
},
body: formData
});
const result = await response.json();
console.log('Colorized image:', result.download_url);
// Open in browser: window.open(result.download_url);
```
**Response Codes:**
- `200 OK` - Image colorized successfully
- `400 Bad Request` - Invalid file type or missing file
- `401 Unauthorized` - Missing or invalid App Check token
- `503 Service Unavailable` - Colorization model not loaded
- `500 Internal Server Error` - Error during colorization
**Processing Time:**
- CPU: ~15-30 seconds
- GPU: ~5-15 seconds
---
### 4. Download Result (API)
Download the colorized image by file ID using the API endpoint.
**Endpoint:** `GET /download/{file_id}`
**Authentication:** Required (Firebase App Check token)
**Parameters:**
- `file_id` (path parameter): The result ID returned from `/colorize` endpoint
**Response:**
- **Content-Type:** `image/jpeg`
- **Body:** Image file binary data
**Example using cURL:**
```bash
curl -X GET \
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/download/550e8400-e29b-41d4-a716-446655440000 \
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
-o colorized_image.jpg
```
**Example using JavaScript:**
```javascript
const response = await fetch(
`https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/download/${fileId}`,
{
headers: {
'X-Firebase-AppCheck': appCheckToken
}
}
);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
// Use the URL to display or download the image
```
**Response Codes:**
- `200 OK` - Image downloaded successfully
- `401 Unauthorized` - Missing or invalid App Check token
- `404 Not Found` - Result not found
---
### 5. Get Result (Public)
Get the colorized image directly (public endpoint, no authentication required).
**Endpoint:** `GET /results/{filename}`
**Authentication:** Not required
**Parameters:**
- `filename` (path parameter): The filename returned from `/colorize` endpoint
**Response:**
- **Content-Type:** `image/jpeg`
- **Body:** Image file binary data
**Example:**
```bash
# Direct browser access
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/results/550e8400-e29b-41d4-a716-446655440000.jpg
```
**Example using HTML:**
```html
<img src="https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/results/550e8400-e29b-41d4-a716-446655440000.jpg" alt="Colorized Image">
```
**Example using JavaScript:**
```javascript
// Direct URL - can be opened in browser or used in img tag
const imageUrl = `https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/results/${filename}`;
window.open(imageUrl); // Opens in new tab
```
**Response Codes:**
- `200 OK` - Image retrieved successfully
- `404 Not Found` - File not found
---
### 6. Get Uploaded File (Public)
Get an uploaded image directly (public endpoint, no authentication required).
**Endpoint:** `GET /uploads/{filename}`
**Authentication:** Not required
**Parameters:**
- `filename` (path parameter): The filename returned from `/upload` endpoint
**Response:**
- **Content-Type:** `image/jpeg`
- **Body:** Image file binary data
**Example:**
```bash
# Direct browser access
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/uploads/550e8400-e29b-41d4-a716-446655440000.jpg
```
**Response Codes:**
- `200 OK` - Image retrieved successfully
- `404 Not Found` - File not found
---
## Firebase App Check Integration
### Frontend Setup
```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 for API requests
async function getAppCheckToken() {
const { getToken } = await import('firebase/app-check');
try {
const token = await getToken(appCheck);
return token.token;
} catch (error) {
console.error('Error getting App Check token:', error);
return null;
}
}
```
### Using the Token
```javascript
async function colorizeImage(imageFile) {
const token = await getAppCheckToken();
if (!token) {
throw new Error('Failed to get App Check token');
}
const formData = new FormData();
formData.append('file', imageFile);
const response = await fetch(
'https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize',
{
method: 'POST',
headers: {
'X-Firebase-AppCheck': token
},
body: formData
}
);
if (!response.ok) {
const error = await response.json();
throw new Error(error.detail || 'Colorization failed');
}
return await response.json();
}
```
---
## Error Responses
All error responses follow this format:
```json
{
"detail": "Error message description"
}
```
### Common Error Codes
- `400 Bad Request` - Invalid request (missing file, wrong file type, etc.)
- `401 Unauthorized` - Missing or invalid Firebase App Check token
- `404 Not Found` - Resource not found (file, result, etc.)
- `500 Internal Server Error` - Server error during processing
- `503 Service Unavailable` - Model not loaded or service unavailable
---
## Complete Example: Colorize Image Workflow
### Step 1: Get App Check Token
```javascript
const token = await getAppCheckToken();
```
### Step 2: Upload and Colorize
```javascript
const formData = new FormData();
formData.append('file', imageFile);
const response = await fetch(
'https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize',
{
method: 'POST',
headers: {
'X-Firebase-AppCheck': token
},
body: formData
}
);
const result = await response.json();
```
### Step 3: Display Result
```javascript
// Option 1: Use the public URL (no auth needed)
const imageUrl = result.download_url;
document.getElementById('result-image').src = imageUrl;
// Option 2: Download via API (requires auth)
const downloadResponse = await fetch(
`https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/download/${result.result_id}`,
{
headers: {
'X-Firebase-AppCheck': token
}
}
);
const blob = await downloadResponse.blob();
const url = URL.createObjectURL(blob);
document.getElementById('result-image').src = url;
```
---
## Rate Limits
- No explicit rate limits set
- Processing time: 15-30 seconds (CPU) or 5-15 seconds (GPU)
- Concurrent requests may be queued
## Supported Image Formats
- JPEG (.jpg, .jpeg)
- PNG (.png)
- Other formats supported by PIL/Pillow
## Image Size Recommendations
- Maximum recommended: 2048x2048 pixels
- Images are automatically resized to 512x512 for processing
- Original aspect ratio is preserved in the output
---
## Testing
### Test Health Endpoint
```bash
curl https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/health
```
### Test Colorize Endpoint (with token)
```bash
curl -X POST \
https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize \
-H "X-Firebase-AppCheck: YOUR_TOKEN" \
-F "file=@test_image.jpg" \
-o response.json
cat response.json
```
---
## Support
For issues or questions:
1. Check the health endpoint to verify API status
2. Verify your Firebase App Check token is valid
3. Check the build logs in Hugging Face Spaces
4. Ensure the model is loaded (check `/health` endpoint)
---
## Changelog
### Version 1.0.0
- Initial release
- Image upload endpoint
- Image colorization endpoint
- Firebase App Check integration
- Public result URLs
|