Commit
·
e8ae712
1
Parent(s):
ae9bbd0
Add comprehensive cURL examples for API testing
Browse files- CURL_EXAMPLES.md +124 -55
CURL_EXAMPLES.md
CHANGED
|
@@ -1,83 +1,152 @@
|
|
| 1 |
-
# cURL Examples for Colorization API
|
| 2 |
|
| 3 |
## Base URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
```
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
```
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
```bash
|
| 10 |
-
curl -X GET "
|
| 11 |
-
-H "User-Agent: Mozilla/5.0"
|
| 12 |
```
|
| 13 |
|
| 14 |
-
##
|
| 15 |
|
| 16 |
-
###
|
| 17 |
```bash
|
| 18 |
-
curl -X POST "
|
| 19 |
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 20 |
-
-
|
| 21 |
-
-F "
|
|
|
|
|
|
|
|
|
|
| 22 |
```
|
| 23 |
|
| 24 |
-
###
|
| 25 |
```bash
|
| 26 |
-
curl -X POST "
|
| 27 |
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
|
| 28 |
-
-
|
| 29 |
-
-F "
|
| 30 |
```
|
| 31 |
|
| 32 |
-
###
|
| 33 |
```bash
|
| 34 |
-
curl -X POST "
|
| 35 |
-
-H "
|
| 36 |
-
-F "file
|
| 37 |
-
-o colorized_result.png
|
| 38 |
```
|
| 39 |
|
| 40 |
-
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
}
|
| 49 |
-
Invoke-RestMethod -Uri "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize" `
|
| 50 |
-
-Method Post `
|
| 51 |
-
-Headers $headers `
|
| 52 |
-
-Form $form `
|
| 53 |
-
-OutFile "colorized_result.png"
|
| 54 |
```
|
| 55 |
|
| 56 |
-
## 4.
|
| 57 |
-
```python
|
| 58 |
-
import requests
|
| 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# cURL Examples for Image Colorization API
|
| 2 |
|
| 3 |
## Base URL
|
| 4 |
+
Replace `YOUR_SPACE_URL` with your Hugging Face Space URL (e.g., `https://your-space-name.hf.space`)
|
| 5 |
+
|
| 6 |
+
```bash
|
| 7 |
+
BASE_URL="https://YOUR_SPACE_URL"
|
| 8 |
+
# Or for local testing:
|
| 9 |
+
# BASE_URL="http://localhost:7860"
|
| 10 |
```
|
| 11 |
+
|
| 12 |
+
## 1. Health Check
|
| 13 |
+
Check if the API is running and models are loaded:
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
curl -X GET "${BASE_URL}/health"
|
| 17 |
```
|
| 18 |
|
| 19 |
+
**Response:**
|
| 20 |
+
```json
|
| 21 |
+
{
|
| 22 |
+
"status": "healthy",
|
| 23 |
+
"model_loaded": true,
|
| 24 |
+
"model_type": "hf_inference_api",
|
| 25 |
+
"provider": "fal-ai"
|
| 26 |
+
}
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## 2. API Info
|
| 30 |
+
Get API information:
|
| 31 |
+
|
| 32 |
```bash
|
| 33 |
+
curl -X GET "${BASE_URL}/api"
|
|
|
|
| 34 |
```
|
| 35 |
|
| 36 |
+
## 3. Colorize Image (with Firebase Auth)
|
| 37 |
|
| 38 |
+
### With Bearer Token (Firebase ID Token):
|
| 39 |
```bash
|
| 40 |
+
curl -X POST "${BASE_URL}/colorize" \
|
| 41 |
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 42 |
+
-F "file=@path/to/your/image.jpg" \
|
| 43 |
+
-F "positive_prompt=vibrant natural colors, high quality" \
|
| 44 |
+
-F "negative_prompt=blurry, low quality" \
|
| 45 |
+
-F "seed=123" \
|
| 46 |
+
-F "num_inference_steps=8"
|
| 47 |
```
|
| 48 |
|
| 49 |
+
### With App Check Token:
|
| 50 |
```bash
|
| 51 |
+
curl -X POST "${BASE_URL}/colorize" \
|
| 52 |
-H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
|
| 53 |
+
-F "file=@path/to/your/image.jpg" \
|
| 54 |
+
-F "positive_prompt=vibrant natural colors, high quality"
|
| 55 |
```
|
| 56 |
|
| 57 |
+
### Minimal Request (default prompt):
|
| 58 |
```bash
|
| 59 |
+
curl -X POST "${BASE_URL}/colorize" \
|
| 60 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 61 |
+
-F "file=@image.jpg"
|
|
|
|
| 62 |
```
|
| 63 |
|
| 64 |
+
**Response:**
|
| 65 |
+
```json
|
| 66 |
+
{
|
| 67 |
+
"success": true,
|
| 68 |
+
"result_id": "uuid-here",
|
| 69 |
+
"caption": "colorize this image with vibrant natural colors, high quality",
|
| 70 |
+
"download_url": "/results/uuid-here.png",
|
| 71 |
+
"api_download": "/download/uuid-here"
|
| 72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
```
|
| 74 |
|
| 75 |
+
## 4. Download Colorized Image
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
### With Authentication:
|
| 78 |
+
```bash
|
| 79 |
+
curl -X GET "${BASE_URL}/download/RESULT_ID" \
|
| 80 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 81 |
+
-o colorized_image.png
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### Public Access (if available):
|
| 85 |
+
```bash
|
| 86 |
+
curl -X GET "${BASE_URL}/results/FILENAME.png" \
|
| 87 |
+
-o colorized_image.png
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## 5. Complete Workflow Example
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
# 1. Check health
|
| 94 |
+
curl -X GET "${BASE_URL}/health"
|
| 95 |
|
| 96 |
+
# 2. Colorize image
|
| 97 |
+
RESPONSE=$(curl -X POST "${BASE_URL}/colorize" \
|
| 98 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 99 |
+
-F "file=@input.jpg" \
|
| 100 |
+
-F "positive_prompt=colorize with vibrant natural colors")
|
| 101 |
+
|
| 102 |
+
# 3. Extract result_id from response
|
| 103 |
+
RESULT_ID=$(echo $RESPONSE | jq -r '.result_id')
|
| 104 |
+
|
| 105 |
+
# 4. Download the result
|
| 106 |
+
curl -X GET "${BASE_URL}/download/${RESULT_ID}" \
|
| 107 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 108 |
+
-o output.png
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
## 6. Testing Without Authentication
|
| 112 |
+
|
| 113 |
+
If `DISABLE_AUTH=true` is set in environment variables:
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
curl -X POST "${BASE_URL}/colorize" \
|
| 117 |
+
-F "file=@image.jpg" \
|
| 118 |
+
-F "positive_prompt=colorize this image"
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
## 7. Using jq for Pretty JSON Output
|
| 122 |
+
|
| 123 |
+
```bash
|
| 124 |
+
# Health check with formatted output
|
| 125 |
+
curl -X GET "${BASE_URL}/health" | jq
|
| 126 |
+
|
| 127 |
+
# Colorize with formatted response
|
| 128 |
+
curl -X POST "${BASE_URL}/colorize" \
|
| 129 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 130 |
+
-F "file=@image.jpg" | jq
|
| 131 |
```
|
| 132 |
|
| 133 |
+
## 8. Error Handling Examples
|
| 134 |
+
|
| 135 |
+
### Check for errors:
|
| 136 |
+
```bash
|
| 137 |
+
curl -X GET "${BASE_URL}/health" | jq '.model_error'
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
### Verbose output for debugging:
|
| 141 |
+
```bash
|
| 142 |
+
curl -v -X POST "${BASE_URL}/colorize" \
|
| 143 |
+
-H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
|
| 144 |
+
-F "file=@image.jpg"
|
| 145 |
+
```
|
| 146 |
|
| 147 |
+
## Notes:
|
| 148 |
+
- Replace `YOUR_FIREBASE_ID_TOKEN` with your actual Firebase authentication token
|
| 149 |
+
- Replace `YOUR_SPACE_URL` with your Hugging Face Space URL
|
| 150 |
+
- Image formats supported: JPG, PNG, etc.
|
| 151 |
+
- The API uses Hugging Face Inference API (fal-ai provider) for colorization
|
| 152 |
+
- Default model: `black-forest-labs/FLUX.1-Kontext-dev`
|