-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgallery.py
More file actions
45 lines (32 loc) · 1.04 KB
/
gallery.py
File metadata and controls
45 lines (32 loc) · 1.04 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
import marimo
__generated_with = "0.20.2"
app = marimo.App()
@app.cell
def _():
import marimo as mo
import os
import sys
import subprocess
return mo, os, subprocess, sys
@app.cell
def _(mo, os, subprocess, sys):
_notebook_dir = "notebooks"
_notebook_files = sorted([f for f in os.listdir(_notebook_dir) if f.endswith(".py")]) if os.path.exists(_notebook_dir) else []
def _open_nb(path):
# Launch marimo edit in a new background process so it doesn't block this notebook
subprocess.Popen([sys.executable, "-m", "marimo", "edit", path])
_buttons = [
mo.ui.button(
label=f"🚀 Open {nb}",
on_change=lambda _, p=os.path.join(_notebook_dir, nb): _open_nb(p)
)
for nb in _notebook_files
]
mo.md(f"""
# 📚 Notebook Gallery
Click on a notebook below to open it in a new window:
{mo.vstack(_buttons) if _buttons else f"*No notebooks found in the `{_notebook_dir}` folder.*"}
""")
return
if __name__ == "__main__":
app.run()