File size: 3,578 Bytes
e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 e4599d1 e8ae712 |
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 |
# cURL Examples for Image Colorization API
## Base URL
Replace `YOUR_SPACE_URL` with your Hugging Face Space URL (e.g., `https://your-space-name.hf.space`)
```bash
BASE_URL="https://YOUR_SPACE_URL"
# Or for local testing:
# BASE_URL="http://localhost:7860"
```
## 1. Health Check
Check if the API is running and models are loaded:
```bash
curl -X GET "${BASE_URL}/health"
```
**Response:**
```json
{
"status": "healthy",
"model_loaded": true,
"model_type": "hf_inference_api",
"provider": "fal-ai"
}
```
## 2. API Info
Get API information:
```bash
curl -X GET "${BASE_URL}/api"
```
## 3. Colorize Image (with Firebase Auth)
### With Bearer Token (Firebase ID Token):
```bash
curl -X POST "${BASE_URL}/colorize" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-F "file=@path/to/your/image.jpg" \
-F "positive_prompt=vibrant natural colors, high quality" \
-F "negative_prompt=blurry, low quality" \
-F "seed=123" \
-F "num_inference_steps=8"
```
### With App Check Token:
```bash
curl -X POST "${BASE_URL}/colorize" \
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
-F "file=@path/to/your/image.jpg" \
-F "positive_prompt=vibrant natural colors, high quality"
```
### Minimal Request (default prompt):
```bash
curl -X POST "${BASE_URL}/colorize" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-F "file=@image.jpg"
```
**Response:**
```json
{
"success": true,
"result_id": "uuid-here",
"caption": "colorize this image with vibrant natural colors, high quality",
"download_url": "/results/uuid-here.png",
"api_download": "/download/uuid-here"
}
```
## 4. Download Colorized Image
### With Authentication:
```bash
curl -X GET "${BASE_URL}/download/RESULT_ID" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-o colorized_image.png
```
### Public Access (if available):
```bash
curl -X GET "${BASE_URL}/results/FILENAME.png" \
-o colorized_image.png
```
## 5. Complete Workflow Example
```bash
# 1. Check health
curl -X GET "${BASE_URL}/health"
# 2. Colorize image
RESPONSE=$(curl -X POST "${BASE_URL}/colorize" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-F "file=@input.jpg" \
-F "positive_prompt=colorize with vibrant natural colors")
# 3. Extract result_id from response
RESULT_ID=$(echo $RESPONSE | jq -r '.result_id')
# 4. Download the result
curl -X GET "${BASE_URL}/download/${RESULT_ID}" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-o output.png
```
## 6. Testing Without Authentication
If `DISABLE_AUTH=true` is set in environment variables:
```bash
curl -X POST "${BASE_URL}/colorize" \
-F "file=@image.jpg" \
-F "positive_prompt=colorize this image"
```
## 7. Using jq for Pretty JSON Output
```bash
# Health check with formatted output
curl -X GET "${BASE_URL}/health" | jq
# Colorize with formatted response
curl -X POST "${BASE_URL}/colorize" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-F "file=@image.jpg" | jq
```
## 8. Error Handling Examples
### Check for errors:
```bash
curl -X GET "${BASE_URL}/health" | jq '.model_error'
```
### Verbose output for debugging:
```bash
curl -v -X POST "${BASE_URL}/colorize" \
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
-F "file=@image.jpg"
```
## Notes:
- Replace `YOUR_FIREBASE_ID_TOKEN` with your actual Firebase authentication token
- Replace `YOUR_SPACE_URL` with your Hugging Face Space URL
- Image formats supported: JPG, PNG, etc.
- The API uses Hugging Face Inference API (fal-ai provider) for colorization
- Default model: `black-forest-labs/FLUX.1-Kontext-dev`
|