Spaces:
Running on Zero
Running on Zero
| title: Segment Everything API | |
| emoji: 🧩 | |
| colorFrom: indigo | |
| colorTo: blue | |
| sdk: gradio | |
| sdk_version: 6.26.0 | |
| app_file: app.py | |
| python_version: "3.12" | |
| short_description: SAM 2.1 masks as a decodable label-map PNG | |
| # Segment Everything API | |
| SAM 2.1 automatic mask generation, returned as **data instead of a picture**. | |
| Most segmentation demos hand back a colour-blended overlay, which cannot be | |
| decoded into masks again. This Space returns: | |
| | Output | What it is | | |
| |---|---| | |
| | `labels.png` | Lossless, untagged PNG. Each pixel carries its segment id as `R + G*256`; `0` means unsegmented. | | |
| | `manifest` | `{width, height, count, model, regions: [{id, area, bbox}]}` | | |
| | `preview` | A tinted image for eyeballing only — never parse it. | | |
| A client decodes `labels.png` once into a per-pixel label array and then does | |
| hit-testing, hover highlighting and selection entirely locally: **one call per | |
| image, no round trip per interaction**. | |
| ## API | |
| ```python | |
| from gradio_client import Client, handle_file | |
| client = Client("Snake4y5h/segment-everything-api") | |
| labels, manifest, preview = client.predict( | |
| image=handle_file("art.png"), | |
| points_per_crop=32, # 8 coarse … 64 fine | |
| min_area_frac=0.0002, # drop specks | |
| pred_iou_thresh=0.88, | |
| stability_score_thresh=0.95, | |
| api_name="/segment", | |
| ) | |
| ``` | |
| Decoding the label map (JavaScript): | |
| ```js | |
| const bmp = await createImageBitmap(pngBlob, { colorSpaceConversion: 'none' }); | |
| // draw to a canvas, then per pixel: id = data[p] + (data[p + 1] << 8) | |
| ``` | |
| Note `colorSpaceConversion: 'none'` — colour management would corrupt the ids. | |
| Long edge is capped at 2048px; the manifest reports the size actually segmented. | |