LogicGoInfotechSpaces commited on
Commit
e8ae712
·
1 Parent(s): ae9bbd0

Add comprehensive cURL examples for API testing

Browse files
Files changed (1) hide show
  1. 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
- https://logicgoinfotechspaces-text-guided-image-colorization.hf.space
 
 
 
 
 
6
  ```
7
 
8
- ## 1. Health Check (No Auth Required)
 
 
 
 
 
 
 
 
 
 
 
 
9
  ```bash
10
- curl -X GET "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/health" \
11
- -H "User-Agent: Mozilla/5.0"
12
  ```
13
 
14
- ## 2. Colorize Image (With Firebase Auth)
15
 
16
- ### Using Firebase ID Token
17
  ```bash
18
- curl -X POST "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize" \
19
  -H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
20
- -H "User-Agent: Mozilla/5.0" \
21
- -F "file=@/path/to/your/image.jpg"
 
 
 
22
  ```
23
 
24
- ### Using App Check Token
25
  ```bash
26
- curl -X POST "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize" \
27
  -H "X-Firebase-AppCheck: YOUR_APP_CHECK_TOKEN" \
28
- -H "User-Agent: Mozilla/5.0" \
29
- -F "file=@/path/to/your/image.jpg"
30
  ```
31
 
32
- ### Without Auth (if DISABLE_AUTH=true)
33
  ```bash
34
- curl -X POST "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize" \
35
- -H "User-Agent: Mozilla/5.0" \
36
- -F "file=@/path/to/your/image.jpg" \
37
- -o colorized_result.png
38
  ```
39
 
40
- ## 3. Windows PowerShell Example
41
- ```powershell
42
- $imagePath = "C:\projects\colorize_text\pexels-andrey-grushnikov-223358-707676.jpg"
43
- $headers = @{
44
- "User-Agent" = "Mozilla/5.0"
45
- }
46
- $form = @{
47
- file = Get-Item $imagePath
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. Python requests Example
57
- ```python
58
- import requests
59
 
60
- url = "https://logicgoinfotechspaces-text-guided-image-colorization.hf.space/colorize"
61
- headers = {
62
- "User-Agent": "Mozilla/5.0",
63
- # "Authorization": "Bearer YOUR_FIREBASE_ID_TOKEN", # Uncomment if auth enabled
64
- }
65
- files = {
66
- "file": ("image.jpg", open("path/to/image.jpg", "rb"), "image/jpeg")
67
- }
 
 
 
 
 
 
 
 
 
 
68
 
69
- response = requests.post(url, headers=headers, files=files)
70
- if response.status_code == 200:
71
- with open("colorized_result.png", "wb") as f:
72
- f.write(response.content)
73
- print("Colorized image saved!")
74
- else:
75
- print(f"Error: {response.status_code} - {response.text}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  ```
77
 
78
- ## Response
79
- - **Success (200)**: Returns PNG image file
80
- - **Error (400)**: Bad request (invalid file type)
81
- - **Error (401)**: Unauthorized (missing/invalid auth token)
82
- - **Error (503)**: Service unavailable (model not loaded)
 
 
 
 
 
 
 
 
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`