Repository navigation
Expand file tree
/
Copy pathquickstart.py
More file actions
73 lines (58 loc) · 2.09 KB
/
Copy pathquickstart.py
File metadata and controls
73 lines (58 loc) · 2.09 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "marimo>=0.22",
# "geopandas>=1.0",
# "pyarrow",
# "polyrender @ git+https://github.com/ckmah/polyrender.git@ed2f47e954ecf0ac846bca10668a2754b1a7725e",
# ]
# ///
import marimo
__generated_with = "0.23.1"
app = marimo.App(width="full")
@app.cell
def _():
import os
import textwrap
import geopandas as gpd
import marimo as mo
import polyrender as po
parquet_url = os.getenv(
"POLYRENDER_PARQUET_URL",
"https://huggingface.co/datasets/ckmah/polyrender/resolve/92678be92f8e0b06fc2a32b53885c4fdf3419ee3/liver_crop_sample.parquet",
)
return gpd, mo, parquet_url, po, textwrap
@app.cell
def _(gpd, mo, parquet_url, po, textwrap):
import pathlib
import tempfile
import urllib.parse
import urllib.request
scheme = urllib.parse.urlparse(parquet_url).scheme.lower()
if scheme in {"http", "https"}:
with urllib.request.urlopen(parquet_url, timeout=120) as response:
with tempfile.TemporaryDirectory() as temp_dir:
parquet_path = pathlib.Path(temp_dir) / "dataset.parquet"
parquet_path.write_bytes(response.read())
gdf = gpd.read_parquet(parquet_path)
else:
gdf = gpd.read_parquet(parquet_url)
intro = mo.md(
textwrap.dedent(
f"""
# Polyrender quick start
This notebook loads sample data from Hugging Face only, so it works
in hosted MoLab sessions where only this notebook file is copied.
Set `POLYRENDER_PARQUET_URL` to any public parquet URL.
Current source: `{parquet_url}`
Tip: In `on_demand=True` mode, click a cell in the minimap to build a
on-demand tile view. The camera also clamps max zoom-out so you cannot
pull back far enough to frame the entire dataset at once (keeps big
datasets from loading everything).
"""
).strip()
)
viewer = po.plot(gdf, on_demand=True)
return mo.vstack(intro, viewer)
if __name__ == "__main__":
app.run()