Fix geospatial demo for HyperView 0.6.2 dataset API
Browse files
demo.py
CHANGED
|
@@ -13,6 +13,7 @@ from datasets import load_dataset
|
|
| 13 |
from PIL import Image, ImageOps
|
| 14 |
|
| 15 |
import hyperview as hv
|
|
|
|
| 16 |
|
| 17 |
SPACE_DIR = Path(__file__).resolve().parent
|
| 18 |
SPACE_HOST = os.environ.get("HYPERVIEW_HOST", "127.0.0.1")
|
|
@@ -393,23 +394,27 @@ def add_geospatial_samples(dataset: hv.Dataset) -> None:
|
|
| 393 |
else 0
|
| 394 |
)
|
| 395 |
else:
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
sample_id = str(row["sample_id"])
|
| 401 |
-
exists = sample_id in existing_ids
|
| 402 |
-
if exists and not FORCE_SAMPLE_REFRESH:
|
| 403 |
-
skipped_existing += 1
|
| 404 |
-
continue
|
| 405 |
-
dataset.add_image(
|
| 406 |
-
row["filepath"],
|
| 407 |
label=row["label"],
|
| 408 |
metadata=row["metadata"],
|
| 409 |
-
sample_id=sample_id,
|
| 410 |
)
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
added = upserted - updated
|
| 415 |
if skipped_existing:
|
|
|
|
| 13 |
from PIL import Image, ImageOps
|
| 14 |
|
| 15 |
import hyperview as hv
|
| 16 |
+
from hyperview.core import Sample
|
| 17 |
|
| 18 |
SPACE_DIR = Path(__file__).resolve().parent
|
| 19 |
SPACE_HOST = os.environ.get("HYPERVIEW_HOST", "127.0.0.1")
|
|
|
|
| 394 |
else 0
|
| 395 |
)
|
| 396 |
else:
|
| 397 |
+
samples = [
|
| 398 |
+
Sample(
|
| 399 |
+
id=str(row["sample_id"]),
|
| 400 |
+
filepath=row["filepath"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
label=row["label"],
|
| 402 |
metadata=row["metadata"],
|
|
|
|
| 403 |
)
|
| 404 |
+
for row in image_rows
|
| 405 |
+
if FORCE_SAMPLE_REFRESH or str(row["sample_id"]) not in existing_ids
|
| 406 |
+
]
|
| 407 |
+
skipped_existing = 0 if FORCE_SAMPLE_REFRESH else len(image_rows) - len(samples)
|
| 408 |
+
upserted, add_samples_skipped = dataset.add_samples(
|
| 409 |
+
samples,
|
| 410 |
+
skip_existing=not FORCE_SAMPLE_REFRESH,
|
| 411 |
+
)
|
| 412 |
+
skipped_existing += add_samples_skipped
|
| 413 |
+
updated = (
|
| 414 |
+
sum(1 for row in image_rows if str(row["sample_id"]) in existing_ids)
|
| 415 |
+
if FORCE_SAMPLE_REFRESH
|
| 416 |
+
else 0
|
| 417 |
+
)
|
| 418 |
|
| 419 |
added = upserted - updated
|
| 420 |
if skipped_existing:
|