33__generated_with = "0.23.3"
44app = marimo .App (width = "medium" )
55
6- with app .setup (hide_code = True ):
6+ async with app .setup (hide_code = True ):
77 import marimo as mo
8-
9-
10- @app .cell (hide_code = True )
11- async def _ (Path , dataset_path , public_folder_path , requests , zipfile ):
128 import sys
139 import os
10+ from pathlib import Path
11+ import zipfile
12+ import requests
13+
14+ public_folder_path = Path ("./public" )
15+ dataset_path = public_folder_path / "dataset"
16+ assets_path = public_folder_path / "assets"
1417
1518 # Seaborn isn't installed by default in Pyodide, so we install it here (only if the notebook runs on WebAssembly):
1619 if "pyodide" in sys .modules :
@@ -24,40 +27,35 @@ async def _(Path, dataset_path, public_folder_path, requests, zipfile):
2427
2528 # Download and unzip the dataset from the repository
2629 if not dataset_path .exists ():
27- with mo .status .spinner (title = "⏬ Downloading the dataset..." ) as _spinner :
28- zip_path = Path ("public" ) / "dataset.zip"
29- url = mo .notebook_location () / "public" / "dataset.zip"
30- r = requests .get (str (url ))
31- r .raise_for_status ()
32- zip_path .write_bytes (r .content )
33- with zipfile .ZipFile (zip_path , "r" ) as zf :
34- zf .extractall (public_folder_path )
35- print (f"Extracted dataset in: { public_folder_path } " )
36- zip_path .unlink (missing_ok = True ) # Delete the zipped dataset
30+ # with mo.status.spinner(title="⏬ Downloading the dataset...") as _spinner:
31+ zip_path = Path ("public" ) / "dataset.zip"
32+ url = mo .notebook_location () / "public" / "dataset.zip"
33+ r = requests .get (str (url ))
34+ r .raise_for_status ()
35+ zip_path .write_bytes (r .content )
36+ with zipfile .ZipFile (zip_path , "r" ) as zf :
37+ zf .extractall (public_folder_path )
38+ print (f"Extracted dataset in: { public_folder_path } " )
39+ zip_path .unlink (missing_ok = True ) # Delete the zipped dataset
3740
3841 # Download the figures (TODO: this is probably not the best way to handle this)
39- assets_path = public_folder_path / "assets"
4042 if not assets_path .exists ():
4143 os .mkdir (assets_path )
4244
4345 _img_dst = assets_path / "inference.png"
4446 if not _img_dst .exists ():
4547 _img_src = "https://raw.githubusercontent.com/EPFL-Center-for-Imaging/vision-workshop/refs/heads/main/public/assets/inference.png"
46- response = requests .get (url )
48+ response = requests .get (_img_src )
4749 with open (_img_dst , "wb" ) as _f :
4850 _f .write (response .content )
4951 else :
5052 import seaborn as sns
51- return (sns ,)
5253
5354
5455@app .cell (hide_code = True )
5556def _ ():
5657 import base64
5758 import time
58- import zipfile
59- import requests
60- from pathlib import Path
6159 from io import BytesIO
6260 from pickle import dump
6361
@@ -81,7 +79,6 @@ def _():
8179 ConfusionMatrixDisplay ,
8280 Image ,
8381 ListedColormap ,
84- Path ,
8582 alt ,
8683 base64 ,
8784 confusion_matrix ,
@@ -90,9 +87,7 @@ def _():
9087 np ,
9188 pd ,
9289 plt ,
93- requests ,
9490 rescale_intensity ,
95- zipfile ,
9691 )
9792
9893
@@ -211,19 +206,15 @@ def _():
211206
212207
213208@app .cell
214- def _ (Path ):
215- public_folder_path = Path ("./public" )
216-
217- dataset_path = public_folder_path / "dataset"
218-
209+ def _ ():
219210 path_exists = "✅ yes" if dataset_path .exists () else "❌ no"
220211
221212 # We use Marimo's "vstack" to display items stacked vertically:
222213 mo .vstack ([
223214 mo .md (f"Dataset path: **{ str (dataset_path .resolve ())} **" ),
224215 mo .md (f"Path exists: **{ path_exists } **" )
225216 ])
226- return dataset_path , public_folder_path
217+ return
227218
228219
229220@app .cell (hide_code = True )
@@ -245,7 +236,7 @@ def _():
245236
246237
247238@app .cell
248- def _ (Path , dataset_path , img2url , imread , load_dataset_btn , pd ):
239+ def _ (img2url , imread , load_dataset_btn , pd ):
249240 # We use `mo.stop` so that this cell only executes when the button is clicked:
250241 mo .stop (not load_dataset_btn .value , mo .md ("Click the button to load the dataset." ))
251242
@@ -1141,7 +1132,7 @@ def _():
11411132
11421133
11431134@app .cell (hide_code = True )
1144- def _ (Path , dump , pipe , save_btn ):
1135+ def _ (dump , pipe , save_btn ):
11451136 mo .stop (not save_btn .value , mo .md ("Click the button to save the pipeline." ))
11461137
11471138 pipeline_file = Path ("./pipeline.pkl" )
@@ -1306,7 +1297,7 @@ def predict_on_regular_grid(model, nx=200, ny=200):
13061297
13071298
13081299@app .cell (hide_code = True )
1309- def _ (ListedColormap , extent , pd , plt , predict_on_regular_grid , sns ):
1300+ def _ (ListedColormap , extent , pd , plt , predict_on_regular_grid ):
13101301 def plot_classification_results (model , results , split = "validation" , palette_name = "pastel" ):
13111302 """Display a confusion matrix and a 2D scatter plot of PCA-0/PCA-1 coordinates colored according to class indices."""
13121303 global extent
@@ -1463,15 +1454,15 @@ def _(x_train_projected):
14631454
14641455
14651456@app .cell (hide_code = True )
1466- def _ (public_folder_path ):
1457+ def _ ():
14671458 _img_src = public_folder_path / "assets" / "training_fig.svg"
14681459
14691460 dataset_acquisition_fig = mo .vstack ([mo .image (src = _img_src , alt = "training_fig" , height = 600 , caption = "How the dataset was created" )], align = "center" )
14701461 return (dataset_acquisition_fig ,)
14711462
14721463
14731464@app .cell (hide_code = True )
1474- def _ (public_folder_path ):
1465+ def _ ():
14751466 _img_src = public_folder_path / "assets" / "inference.png"
14761467
14771468 inference_screenshot = mo .vstack ([mo .image (src = _img_src , alt = "screenshot" , height = 400 , caption = "Live inference (screenshot)" )], align = "center" )
0 commit comments