Spaces:
Running
on
T4
Running
on
T4
Commit
·
37fb070
1
Parent(s):
174828e
feat(api): simplify /inpaint response to return only filename; update docs
Browse files- HTTP_API_Documentation.txt +159 -26
- README.md +5 -2
- api/main.py +12 -2
HTTP_API_Documentation.txt
CHANGED
|
@@ -1,49 +1,182 @@
|
|
| 1 |
-
HTTP API Documentation
|
| 2 |
|
| 3 |
-
|
| 4 |
-
- Auth (optional): set API_TOKEN on server; send Authorization: Bearer <API_TOKEN>
|
| 5 |
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
-
- POST /inpaint-multipart (form-data: image, mask) -> {"result":"output_xxx.png"}
|
| 12 |
-
- GET /download/{filename} (only needed if you have a filename)
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 21 |
-F [email protected] \
|
| 22 |
https://logicgoinfotechspaces-object-remover.hf.space/upload-image
|
|
|
|
| 23 |
|
| 24 |
-
Upload
|
| 25 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 26 |
-F [email protected] \
|
| 27 |
https://logicgoinfotechspaces-object-remover.hf.space/upload-mask
|
|
|
|
| 28 |
|
| 29 |
-
Inpaint (
|
| 30 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 31 |
-H "Content-Type: application/json" \
|
| 32 |
-
-d '{"image_id":"
|
| 33 |
-
https://logicgoinfotechspaces-object-remover.hf.space/inpaint
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
Inpaint (
|
| 37 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 38 |
-F [email protected] \
|
| 39 |
-F [email protected] \
|
| 40 |
https://logicgoinfotechspaces-object-remover.hf.space/inpaint-multipart
|
|
|
|
| 41 |
|
| 42 |
-
Download (
|
| 43 |
-
curl -
|
| 44 |
-
-
|
|
|
|
|
|
|
|
|
|
| 45 |
-o result.png
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
HTTP API Documentation - Photo Object Removal Service
|
| 2 |
|
| 3 |
+
Base URL: https://logicgoinfotechspaces-object-remover.hf.space
|
|
|
|
| 4 |
|
| 5 |
+
Authentication:
|
| 6 |
+
- Optional Bearer token authentication
|
| 7 |
+
- Set API_TOKEN environment variable on server to enable auth
|
| 8 |
+
- Send header: Authorization: Bearer <API_TOKEN>
|
| 9 |
+
- If API_TOKEN not set, all endpoints are publicly accessible
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
Available Endpoints:
|
| 12 |
|
| 13 |
+
1. GET /health
|
| 14 |
+
- Health check endpoint
|
| 15 |
+
- Returns: {"status":"healthy"}
|
| 16 |
+
- No authentication required
|
| 17 |
|
| 18 |
+
2. POST /upload-image
|
| 19 |
+
- Upload an image file for processing
|
| 20 |
+
- Content-Type: multipart/form-data
|
| 21 |
+
- Form field: image (file)
|
| 22 |
+
- Returns: {"id":"<image_id>","filename":"original_name.png"}
|
| 23 |
+
- Supported formats: PNG, JPG, JPEG
|
| 24 |
+
|
| 25 |
+
3. POST /upload-mask
|
| 26 |
+
- Upload a mask file indicating areas to remove
|
| 27 |
+
- Content-Type: multipart/form-data
|
| 28 |
+
- Form field: mask (file)
|
| 29 |
+
- Returns: {"id":"<mask_id>","filename":"mask.png"}
|
| 30 |
+
- Mask formats:
|
| 31 |
+
* RGBA PNG: pixels with alpha=0 are treated as areas to remove
|
| 32 |
+
* RGB/Grayscale: pixels with value > 0 are treated as areas to remove
|
| 33 |
+
|
| 34 |
+
4. POST /inpaint
|
| 35 |
+
- Process inpainting using uploaded image and mask IDs
|
| 36 |
+
- Content-Type: application/json
|
| 37 |
+
- Body: {"image_id":"<image_id>","mask_id":"<mask_id>"}
|
| 38 |
+
- Returns: {"result":"output_xxx.png"}
|
| 39 |
+
- Simple response with just the filename
|
| 40 |
+
|
| 41 |
+
5. POST /inpaint-url
|
| 42 |
+
- Same as /inpaint but returns JSON with public download URL
|
| 43 |
+
- Content-Type: application/json
|
| 44 |
+
- Body: {"image_id":"<image_id>","mask_id":"<mask_id>"}
|
| 45 |
+
- Returns: {"result":"output_xxx.png","url":"https://.../download/output_xxx.png"}
|
| 46 |
+
- Use this endpoint if you need a shareable URL
|
| 47 |
+
|
| 48 |
+
6. POST /inpaint-multipart
|
| 49 |
+
- Process inpainting with direct file upload (no separate upload steps)
|
| 50 |
+
- Content-Type: multipart/form-data
|
| 51 |
+
- Form fields: image (file), mask (file)
|
| 52 |
+
- Returns: {"result":"output_xxx.png","url":"https://.../download/output_xxx.png"}
|
| 53 |
+
|
| 54 |
+
7. GET /download/{filename}
|
| 55 |
+
- Download result image by filename
|
| 56 |
+
- Public endpoint (no authentication required)
|
| 57 |
+
- Returns: image/png (binary data)
|
| 58 |
+
- Can be opened directly in browser
|
| 59 |
+
|
| 60 |
+
8. GET /result/{filename}
|
| 61 |
+
- View result image directly in browser
|
| 62 |
+
- Public endpoint (no authentication required)
|
| 63 |
+
- Returns: image/png with proper content-type for viewing
|
| 64 |
+
- Optimized for browser display
|
| 65 |
+
|
| 66 |
+
CURL EXAMPLES:
|
| 67 |
+
|
| 68 |
+
1. Health Check:
|
| 69 |
+
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 70 |
+
https://logicgoinfotechspaces-object-remover.hf.space/health
|
| 71 |
+
|
| 72 |
+
2. Upload Image:
|
| 73 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 74 |
-F [email protected] \
|
| 75 |
https://logicgoinfotechspaces-object-remover.hf.space/upload-image
|
| 76 |
+
# Response: {"id":"9cf61445-f83b-4c97-9272-c81647f90d68","filename":"image.png"}
|
| 77 |
|
| 78 |
+
3. Upload Mask:
|
| 79 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 80 |
-F [email protected] \
|
| 81 |
https://logicgoinfotechspaces-object-remover.hf.space/upload-mask
|
| 82 |
+
# Response: {"id":"d044a390-dde2-408a-b7cf-d508385e56ed","filename":"mask.png"}
|
| 83 |
|
| 84 |
+
4. Inpaint (returns simple JSON):
|
| 85 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 86 |
-H "Content-Type: application/json" \
|
| 87 |
+
-d '{"image_id":"9cf61445-f83b-4c97-9272-c81647f90d68","mask_id":"d044a390-dde2-408a-b7cf-d508385e56ed"}' \
|
| 88 |
+
https://logicgoinfotechspaces-object-remover.hf.space/inpaint
|
| 89 |
+
# Response: {"result":"output_b09568698bbd4aa591b1598c01f2f745.png"}
|
| 90 |
+
|
| 91 |
+
5. Inpaint-URL (returns JSON with public URL):
|
| 92 |
+
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 93 |
+
-H "Content-Type: application/json" \
|
| 94 |
+
-d '{"image_id":"9cf61445-f83b-4c97-9272-c81647f90d68","mask_id":"d044a390-dde2-408a-b7cf-d508385e56ed"}' \
|
| 95 |
+
https://logicgoinfotechspaces-object-remover.hf.space/inpaint-url
|
| 96 |
+
# Response: {"result":"output_b09568698bbd4aa591b1598c01f2f745.png","url":"https://logicgoinfotechspaces-object-remover.hf.space/download/output_b09568698bbd4aa591b1598c01f2f745.png"}
|
| 97 |
|
| 98 |
+
6. Inpaint Multipart (one-step processing):
|
| 99 |
curl -H "Authorization: Bearer <API_TOKEN>" \
|
| 100 |
-F [email protected] \
|
| 101 |
-F [email protected] \
|
| 102 |
https://logicgoinfotechspaces-object-remover.hf.space/inpaint-multipart
|
| 103 |
+
# Response: {"result":"output_xxx.png","url":"https://logicgoinfotechspaces-object-remover.hf.space/download/output_xxx.png"}
|
| 104 |
|
| 105 |
+
7. Download Result (public, no auth):
|
| 106 |
+
curl -L https://logicgoinfotechspaces-object-remover.hf.space/download/output_b09568698bbd4aa591b1598c01f2f745.png \
|
| 107 |
+
-o result.png
|
| 108 |
+
|
| 109 |
+
8. View Result in Browser (public, no auth):
|
| 110 |
+
curl -L https://logicgoinfotechspaces-object-remover.hf.space/result/output_b09568698bbd4aa591b1598c01f2f745.png \
|
| 111 |
-o result.png
|
| 112 |
|
| 113 |
+
POSTMAN EXAMPLES:
|
| 114 |
+
|
| 115 |
+
1. Health Check:
|
| 116 |
+
Method: GET
|
| 117 |
+
URL: https://logicgoinfotechspaces-object-remover.hf.space/health
|
| 118 |
+
Headers: Authorization: Bearer <API_TOKEN>
|
| 119 |
+
|
| 120 |
+
2. Upload Image:
|
| 121 |
+
Method: POST
|
| 122 |
+
URL: https://logicgoinfotechspaces-object-remover.hf.space/upload-image
|
| 123 |
+
Headers: Authorization: Bearer <API_TOKEN>
|
| 124 |
+
Body: form-data
|
| 125 |
+
Key: image, Type: File, Value: select your image file
|
| 126 |
+
|
| 127 |
+
3. Upload Mask:
|
| 128 |
+
Method: POST
|
| 129 |
+
URL: https://logicgoinfotechspaces-object-remover.hf.space/upload-mask
|
| 130 |
+
Headers: Authorization: Bearer <API_TOKEN>
|
| 131 |
+
Body: form-data
|
| 132 |
+
Key: mask, Type: File, Value: select your mask file
|
| 133 |
+
|
| 134 |
+
4. Inpaint (returns simple JSON):
|
| 135 |
+
Method: POST
|
| 136 |
+
URL: https://logicgoinfotechspaces-object-remover.hf.space/inpaint
|
| 137 |
+
Headers:
|
| 138 |
+
- Authorization: Bearer <API_TOKEN>
|
| 139 |
+
- Content-Type: application/json
|
| 140 |
+
Body: raw JSON
|
| 141 |
+
{
|
| 142 |
+
"image_id": "9cf61445-f83b-4c97-9272-c81647f90d68",
|
| 143 |
+
"mask_id": "d044a390-dde2-408a-b7cf-d508385e56ed"
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
5. Inpaint Multipart (one-step):
|
| 147 |
+
Method: POST
|
| 148 |
+
URL: https://logicgoinfotechspaces-object-remover.hf.space/inpaint-multipart
|
| 149 |
+
Headers: Authorization: Bearer <API_TOKEN>
|
| 150 |
+
Body: form-data
|
| 151 |
+
Key: image, Type: File, Value: select your image file
|
| 152 |
+
Key: mask, Type: File, Value: select your mask file
|
| 153 |
+
|
| 154 |
+
IMPORTANT NOTES:
|
| 155 |
+
|
| 156 |
+
Authentication:
|
| 157 |
+
- If API_TOKEN is set on the server, include Authorization header
|
| 158 |
+
- If API_TOKEN is not set, omit Authorization header
|
| 159 |
+
- /download/{filename} is always public (no auth required)
|
| 160 |
+
|
| 161 |
+
Mask Formats:
|
| 162 |
+
- RGBA PNG: pixels with alpha=0 are treated as areas to remove
|
| 163 |
+
- RGB/Grayscale: pixels with value > 0 are treated as areas to remove
|
| 164 |
+
- Create mask by painting white/colored areas over objects you want to remove
|
| 165 |
+
|
| 166 |
+
Error Handling:
|
| 167 |
+
- 404 Not Found on /inpaint: server restarted, IDs expired - re-upload files
|
| 168 |
+
- 401 Unauthorized: missing or invalid API_TOKEN
|
| 169 |
+
- 403 Forbidden: wrong API_TOKEN
|
| 170 |
+
|
| 171 |
+
Workflow Options:
|
| 172 |
+
1. Two-step: upload-image → upload-mask → inpaint (get filename)
|
| 173 |
+
2. One-step: inpaint-multipart (upload and process in single request)
|
| 174 |
+
3. Direct access: use /download/{filename} or /result/{filename} with returned filename
|
| 175 |
+
|
| 176 |
+
Browser Access:
|
| 177 |
+
- Paste any /download/{filename} or /result/{filename} URL directly in Chrome to view the result
|
| 178 |
+
- No authentication required for download/view URLs
|
| 179 |
+
- /result/{filename} is optimized for browser viewing
|
| 180 |
+
- Examples:
|
| 181 |
+
* https://logicgoinfotechspaces-object-remover.hf.space/download/output_b09568698bbd4aa591b1598c01f2f745.png
|
| 182 |
+
* https://logicgoinfotechspaces-object-remover.hf.space/result/output_b09568698bbd4aa591b1598c01f2f745.png
|
README.md
CHANGED
|
@@ -18,14 +18,17 @@ Endpoints:
|
|
| 18 |
- `GET /health` → {"status":"healthy"}
|
| 19 |
- `POST /upload-image` (form-data: image=file) → {"id":"<image_id>","filename":"name.png"}
|
| 20 |
- `POST /upload-mask` (form-data: mask=file) → {"id":"<mask_id>","filename":"mask.png"}
|
| 21 |
-
- `POST /inpaint` (JSON: {image_id, mask_id}) →
|
| 22 |
- `POST /inpaint-url` (JSON: {image_id, mask_id}) → {"result":"output_xxx.png","url":"https://.../download/output_xxx.png"}
|
| 23 |
- `POST /inpaint-multipart` (form-data: image=file, mask=file) → {"result":"output_xxx.png"}
|
| 24 |
- `GET /download/{filename}` → image file (public; optional for ID-based inpaint)
|
|
|
|
| 25 |
- `GET /logs` → recent uploads/results
|
| 26 |
|
| 27 |
Note:
|
| 28 |
-
- `POST /inpaint` returns
|
|
|
|
|
|
|
| 29 |
|
| 30 |
Local run:
|
| 31 |
- Install deps: `python3 -m pip install -r requirements.txt`
|
|
|
|
| 18 |
- `GET /health` → {"status":"healthy"}
|
| 19 |
- `POST /upload-image` (form-data: image=file) → {"id":"<image_id>","filename":"name.png"}
|
| 20 |
- `POST /upload-mask` (form-data: mask=file) → {"id":"<mask_id>","filename":"mask.png"}
|
| 21 |
+
- `POST /inpaint` (JSON: {image_id, mask_id}) → {"result":"output_xxx.png"}
|
| 22 |
- `POST /inpaint-url` (JSON: {image_id, mask_id}) → {"result":"output_xxx.png","url":"https://.../download/output_xxx.png"}
|
| 23 |
- `POST /inpaint-multipart` (form-data: image=file, mask=file) → {"result":"output_xxx.png"}
|
| 24 |
- `GET /download/{filename}` → image file (public; optional for ID-based inpaint)
|
| 25 |
+
- `GET /result/{filename}` → view result image in browser (public)
|
| 26 |
- `GET /logs` → recent uploads/results
|
| 27 |
|
| 28 |
Note:
|
| 29 |
+
- `POST /inpaint` returns simple JSON with just the filename.
|
| 30 |
+
- `POST /inpaint-url` returns JSON with filename and shareable URL.
|
| 31 |
+
- Use `/download/{filename}` or `/result/{filename}` to access the result image.
|
| 32 |
|
| 33 |
Local run:
|
| 34 |
- Install deps: `python3 -m pip install -r requirements.txt`
|
api/main.py
CHANGED
|
@@ -61,6 +61,7 @@ def root() -> Dict[str, object]:
|
|
| 61 |
"POST /inpaint": "JSON: {image_id, mask_id}",
|
| 62 |
"POST /inpaint-multipart": "form-data: image=file, mask=file",
|
| 63 |
"GET /download/{filename}": "download result image",
|
|
|
|
| 64 |
"GET /logs": "recent uploads/results",
|
| 65 |
},
|
| 66 |
"auth": "set API_TOKEN env var to require Authorization: Bearer <token> (except /health)",
|
|
@@ -129,7 +130,7 @@ def _load_rgba_mask_from_image(img: Image.Image) -> np.ndarray:
|
|
| 129 |
|
| 130 |
|
| 131 |
@app.post("/inpaint")
|
| 132 |
-
def inpaint(req: InpaintRequest, _: None = Depends(bearer_auth)):
|
| 133 |
if req.image_id not in file_store or file_store[req.image_id]["type"] != "image":
|
| 134 |
raise HTTPException(status_code=404, detail="image_id not found")
|
| 135 |
if req.mask_id not in file_store or file_store[req.mask_id]["type"] != "mask":
|
|
@@ -145,7 +146,7 @@ def inpaint(req: InpaintRequest, _: None = Depends(bearer_auth)):
|
|
| 145 |
Image.fromarray(result).save(result_path)
|
| 146 |
|
| 147 |
logs.append({"result": result_name, "timestamp": datetime.utcnow().isoformat()})
|
| 148 |
-
return
|
| 149 |
|
| 150 |
|
| 151 |
@app.post("/inpaint-url")
|
|
@@ -212,6 +213,15 @@ def download_file(filename: str):
|
|
| 212 |
return FileResponse(path)
|
| 213 |
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
@app.get("/logs")
|
| 216 |
def get_logs(_: None = Depends(bearer_auth)) -> JSONResponse:
|
| 217 |
return JSONResponse(content=logs)
|
|
|
|
| 61 |
"POST /inpaint": "JSON: {image_id, mask_id}",
|
| 62 |
"POST /inpaint-multipart": "form-data: image=file, mask=file",
|
| 63 |
"GET /download/{filename}": "download result image",
|
| 64 |
+
"GET /result/{filename}": "view result image in browser",
|
| 65 |
"GET /logs": "recent uploads/results",
|
| 66 |
},
|
| 67 |
"auth": "set API_TOKEN env var to require Authorization: Bearer <token> (except /health)",
|
|
|
|
| 130 |
|
| 131 |
|
| 132 |
@app.post("/inpaint")
|
| 133 |
+
def inpaint(req: InpaintRequest, _: None = Depends(bearer_auth)) -> Dict[str, str]:
|
| 134 |
if req.image_id not in file_store or file_store[req.image_id]["type"] != "image":
|
| 135 |
raise HTTPException(status_code=404, detail="image_id not found")
|
| 136 |
if req.mask_id not in file_store or file_store[req.mask_id]["type"] != "mask":
|
|
|
|
| 146 |
Image.fromarray(result).save(result_path)
|
| 147 |
|
| 148 |
logs.append({"result": result_name, "timestamp": datetime.utcnow().isoformat()})
|
| 149 |
+
return {"result": result_name}
|
| 150 |
|
| 151 |
|
| 152 |
@app.post("/inpaint-url")
|
|
|
|
| 213 |
return FileResponse(path)
|
| 214 |
|
| 215 |
|
| 216 |
+
@app.get("/result/{filename}")
|
| 217 |
+
def view_result(filename: str):
|
| 218 |
+
"""View result image directly in browser (same as download but with proper content-type for viewing)"""
|
| 219 |
+
path = os.path.join(OUTPUT_DIR, filename)
|
| 220 |
+
if not os.path.isfile(path):
|
| 221 |
+
raise HTTPException(status_code=404, detail="file not found")
|
| 222 |
+
return FileResponse(path, media_type="image/png")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
@app.get("/logs")
|
| 226 |
def get_logs(_: None = Depends(bearer_auth)) -> JSONResponse:
|
| 227 |
return JSONResponse(content=logs)
|