Spaces:
Running on Zero
Running on Zero
File size: 1,692 Bytes
029df1a 1a73df3 029df1a 1a73df3 029df1a 1a73df3 | 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 | ---
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.
|