Spaces:
Running
Running
Serve the scenes from the Space: scenes.json, WebP pictures, masks and objects
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +2 -2
- app.js +11 -50
- make_space_data.py +62 -0
- masks/fibo_2_edit_turbo/billiard_02_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_02_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_02_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_03_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_03_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_03_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_03_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_04_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_04_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_04_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_04_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_05_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_05_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_05_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_05_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_06_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_06_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_06_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_06_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_07_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_07_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_07_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_07_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_08_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_08_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_08_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_08_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_09_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_09_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_09_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_09_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_10_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_10_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_10_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_10_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_11_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_11_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_11_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_11_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_12_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_12_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_12_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_12_d.png +0 -0
- masks/fibo_2_edit_turbo/billiard_13_a.png +0 -0
- masks/fibo_2_edit_turbo/billiard_13_b.png +0 -0
- masks/fibo_2_edit_turbo/billiard_13_c.png +0 -0
- masks/fibo_2_edit_turbo/billiard_13_d.png +0 -0
README.md
CHANGED
|
@@ -11,5 +11,5 @@ short_description: 472 scenes drawn by 9 image models, checked by SAM 3.1
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Browses the `situate_diffuse` subset of [iisys-hof/situate-diffuse](https://huggingface.co/datasets/iisys-hof/situate-diffuse):
|
| 14 |
-
every scene with the pictures of all 9 models, what SAM 3.1 found in them and their points.
|
| 15 |
-
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Browses the `situate_diffuse` subset of [iisys-hof/situate-diffuse](https://huggingface.co/datasets/iisys-hof/situate-diffuse):
|
| 14 |
+
every scene with the pictures of all 9 models, what SAM 3.1 found in them and their points. `make_space_data.py` writes
|
| 15 |
+
`scenes.json` (all columns but the pictures), `pictures/` (WebP) and `masks/` from the subset's Parquet files.
|
app.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
| 1 |
-
const DATASET = "iisys-hof/situate-diffuse";
|
| 2 |
-
const ROWS_API = "https://datasets-server.huggingface.co/rows";
|
| 3 |
-
const PAGE = 20; // rows per request: 100 rows of pictures are more than the api reads at once
|
| 4 |
const BATCH = 12; // scenes drawn at a time while scrolling
|
| 5 |
|
| 6 |
const MODELS = { // column -> shown name, as the models are called in settings.py
|
|
@@ -26,56 +23,15 @@ let viewing = null; // [scene, model index] of the open picture
|
|
| 26 |
const $ = (id) => document.getElementById(id);
|
| 27 |
|
| 28 |
|
| 29 |
-
async function loadRows() {
|
| 30 |
-
|
| 31 |
-
const rowsFile = new URLSearchParams(location.search).get("rows"); // a local json of rows, for testing
|
| 32 |
-
|
| 33 |
-
if (rowsFile) {
|
| 34 |
-
return (await (await fetch(rowsFile)).json()).map((item) => item.row);
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
const first = await fetchPage(0);
|
| 38 |
-
const offsets = [];
|
| 39 |
-
|
| 40 |
-
for (let offset = PAGE; offset < first.num_rows_total; offset += PAGE) {
|
| 41 |
-
offsets.push(offset);
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
const rest = await Promise.all(offsets.map(fetchPage));
|
| 45 |
-
|
| 46 |
-
return [first, ...rest].flatMap((page) => page.rows.map((item) => item.row));
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
async function fetchPage(offset) {
|
| 51 |
-
|
| 52 |
-
const url = `${ROWS_API}?dataset=${DATASET}&config=situate_diffuse&split=test&offset=${offset}&length=${PAGE}`;
|
| 53 |
-
|
| 54 |
-
for (let attempt = 0; attempt < 4; attempt++) {
|
| 55 |
-
const response = await fetch(url);
|
| 56 |
-
const page = await response.json();
|
| 57 |
-
|
| 58 |
-
if (response.ok && page.rows) {
|
| 59 |
-
return page;
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
await new Promise((done) => setTimeout(done, 2000 * (attempt + 1)));
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
throw new Error("the dataset viewer has no rows yet");
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
|
| 69 |
function readScene(row) {
|
| 70 |
|
| 71 |
const scene = { ...row, expected: JSON.parse(row.expected), models: {} };
|
| 72 |
|
| 73 |
for (const model of Object.keys(MODELS)) {
|
| 74 |
scene.models[model] = {
|
| 75 |
-
picture:
|
| 76 |
-
masks:
|
| 77 |
found: JSON.parse(row[`${model}_found`]),
|
| 78 |
-
objects: JSON.parse(row[`${model}_objects`]),
|
| 79 |
points: row[`${model}_points`],
|
| 80 |
rewrite: row[`${model}_rewrite`] ?? row.hidream_o1_image_reprompt_rewrite,
|
| 81 |
ownRewrite: `${model}_rewrite` in row,
|
|
@@ -340,13 +296,17 @@ function sceneCard(scene) {
|
|
| 340 |
}
|
| 341 |
|
| 342 |
|
| 343 |
-
function openViewer(scene, index) {
|
| 344 |
|
| 345 |
viewing = [scene, (index + order.length) % order.length];
|
| 346 |
const model = order[viewing[1]];
|
| 347 |
const result = scene.models[model];
|
| 348 |
|
| 349 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
const [x1, y1, x2, y2] = thing.box.map((v) => v / 10.24);
|
| 351 |
const label = [thing.what, thing.colour, thing.zone].filter(Boolean).join(" · ");
|
| 352 |
|
|
@@ -413,9 +373,10 @@ function keys(event) {
|
|
| 413 |
async function start() {
|
| 414 |
|
| 415 |
try {
|
| 416 |
-
|
|
|
|
| 417 |
} catch (error) {
|
| 418 |
-
$("status").textContent = `Could not load the scenes (${error.message}).
|
| 419 |
return;
|
| 420 |
}
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
const BATCH = 12; // scenes drawn at a time while scrolling
|
| 2 |
|
| 3 |
const MODELS = { // column -> shown name, as the models are called in settings.py
|
|
|
|
| 23 |
const $ = (id) => document.getElementById(id);
|
| 24 |
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
function readScene(row) {
|
| 27 |
|
| 28 |
const scene = { ...row, expected: JSON.parse(row.expected), models: {} };
|
| 29 |
|
| 30 |
for (const model of Object.keys(MODELS)) {
|
| 31 |
scene.models[model] = {
|
| 32 |
+
picture: `pictures/${model}/${row.scene_id}.webp`,
|
| 33 |
+
masks: `masks/${model}/${row.scene_id}.png`,
|
| 34 |
found: JSON.parse(row[`${model}_found`]),
|
|
|
|
| 35 |
points: row[`${model}_points`],
|
| 36 |
rewrite: row[`${model}_rewrite`] ?? row.hidream_o1_image_reprompt_rewrite,
|
| 37 |
ownRewrite: `${model}_rewrite` in row,
|
|
|
|
| 296 |
}
|
| 297 |
|
| 298 |
|
| 299 |
+
async function openViewer(scene, index) {
|
| 300 |
|
| 301 |
viewing = [scene, (index + order.length) % order.length];
|
| 302 |
const model = order[viewing[1]];
|
| 303 |
const result = scene.models[model];
|
| 304 |
|
| 305 |
+
if (!scene.sam) { // what Sam kept, per model; objects/ holds it apart to keep scenes.json small
|
| 306 |
+
scene.sam = await (await fetch(`objects/${scene.scene_id}.json`)).json();
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
const boxes = scene.sam[model].map((thing) => {
|
| 310 |
const [x1, y1, x2, y2] = thing.box.map((v) => v / 10.24);
|
| 311 |
const label = [thing.what, thing.colour, thing.zone].filter(Boolean).join(" · ");
|
| 312 |
|
|
|
|
| 373 |
async function start() {
|
| 374 |
|
| 375 |
try {
|
| 376 |
+
const response = await fetch("scenes.json");
|
| 377 |
+
scenes = (await response.json()).map(readScene);
|
| 378 |
} catch (error) {
|
| 379 |
+
$("status").textContent = `Could not load the scenes (${error.message}).`;
|
| 380 |
return;
|
| 381 |
}
|
| 382 |
|
make_space_data.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Writes what the page shows from the situate_diffuse parquet files: scenes.json (every column but the pictures and objects),
|
| 2 |
+
objects/<scene>.json (what Sam kept per model, loaded when a picture is opened), pictures/<model>/<scene>.webp and
|
| 3 |
+
masks/<model>/<scene>.png, so the Space needs no api.
|
| 4 |
+
|
| 5 |
+
python make_space_data.py ../situate-diffuse-hf/situate_diffuse
|
| 6 |
+
"""
|
| 7 |
+
import io
|
| 8 |
+
import json
|
| 9 |
+
import sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
import pyarrow.parquet as pq
|
| 13 |
+
from PIL import Image
|
| 14 |
+
|
| 15 |
+
HERE = Path(__file__).resolve().parent
|
| 16 |
+
SOURCE = Path(sys.argv[1])
|
| 17 |
+
QUALITY = 82 # webp, about a quarter of the jpg at no visible loss
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def round_boxes(objects): # whole pixels and 3 digits are all the page shows
|
| 21 |
+
|
| 22 |
+
for thing in objects:
|
| 23 |
+
thing["box"] = [round(v) for v in thing["box"]]
|
| 24 |
+
thing["score"] = round(thing["score"], 3)
|
| 25 |
+
|
| 26 |
+
return objects
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
scenes = []
|
| 30 |
+
|
| 31 |
+
for file in sorted(SOURCE.glob("*.parquet")):
|
| 32 |
+
for row in pq.read_table(file).to_pylist():
|
| 33 |
+
scene = {}
|
| 34 |
+
objects = {}
|
| 35 |
+
|
| 36 |
+
for column, value in row.items():
|
| 37 |
+
if column.endswith("_objects"):
|
| 38 |
+
objects[column.removesuffix("_objects")] = round_boxes(json.loads(value))
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
if not isinstance(value, dict):
|
| 42 |
+
scene[column] = value
|
| 43 |
+
continue
|
| 44 |
+
|
| 45 |
+
model = column.removesuffix("_masks")
|
| 46 |
+
|
| 47 |
+
if column.endswith("_masks"):
|
| 48 |
+
out = HERE / "masks" / model / f"{row['scene_id']}.png"
|
| 49 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 50 |
+
out.write_bytes(value["bytes"])
|
| 51 |
+
continue
|
| 52 |
+
|
| 53 |
+
out = HERE / "pictures" / model / f"{row['scene_id']}.webp"
|
| 54 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 55 |
+
Image.open(io.BytesIO(value["bytes"])).save(out, "WEBP", quality=QUALITY, method=6)
|
| 56 |
+
|
| 57 |
+
(HERE / "objects").mkdir(exist_ok=True)
|
| 58 |
+
(HERE / "objects" / f"{row['scene_id']}.json").write_text(json.dumps(objects, separators=(",", ":")))
|
| 59 |
+
scenes.append(scene)
|
| 60 |
+
|
| 61 |
+
(HERE / "scenes.json").write_text(json.dumps(scenes, separators=(",", ":")))
|
| 62 |
+
print(f"{len(scenes)} scenes -> {HERE}")
|
masks/fibo_2_edit_turbo/billiard_02_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_02_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_02_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_03_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_03_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_03_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_03_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_04_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_04_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_04_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_04_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_05_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_05_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_05_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_05_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_06_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_06_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_06_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_06_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_07_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_07_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_07_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_07_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_08_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_08_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_08_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_08_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_09_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_09_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_09_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_09_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_10_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_10_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_10_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_10_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_11_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_11_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_11_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_11_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_12_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_12_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_12_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_12_d.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_13_a.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_13_b.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_13_c.png
ADDED
|
masks/fibo_2_edit_turbo/billiard_13_d.png
ADDED
|