Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: examples in `modal` (#4504)

Edzukac30ac721bcbf
diff --git a/examples/cloud/modal/README.md b/examples/cloud/modal/README.md
index be95f81b8a..133cd35081 100644
--- a/examples/cloud/modal/README.md
+++ b/examples/cloud/modal/README.md
@@ -21,6 +21,8 @@ You can configure your GPU selection by editing `modal_edit`.
notebook as an app on Modal. Run with
```bash
-uvx -p 3.12 modal run modal_app.py
+uvx -p 3.12 \
+ --with modal \
+ --with marimo \
+ modal serve modal_app.py
```
-
diff --git a/examples/cloud/modal/modal_app.py b/examples/cloud/modal/modal_app.py
index d8f955623c..3cab3c8e86 100644
--- a/examples/cloud/modal/modal_app.py
+++ b/examples/cloud/modal/modal_app.py
@@ -11,17 +11,14 @@ app = modal.App()
@app.function(
- image=modal.Image.debian_slim().pip_install("marimo>=0.8.3", "fastapi"),
- gpu=False,
- concurrency_limit=1,
- allow_concurrent_inputs=2,
+ image=modal.Image.debian_slim()
+ .pip_install("marimo>=0.12.8", "fastapi")
+ .add_local_dir("./nbs", remote_path="/marimo"),
+ gpu=None,
+ max_containers=1,
memory=256,
- mounts=[modal.Mount.from_local_dir("./nbs", remote_path="/marimo")],
)
[email protected](max_inputs=2)
@asgi_app()
def marimo_asgi():
return server.build()
-
-
-if __name__ == "__main__":
- modal.serve(app)
diff --git a/examples/cloud/modal/modal_edit.py b/examples/cloud/modal/modal_edit.py
index a57427286c..b32f10ed8c 100644
--- a/examples/cloud/modal/modal_edit.py
+++ b/examples/cloud/modal/modal_edit.py
@@ -6,7 +6,7 @@ import modal
app = modal.App(
image=modal.Image.debian_slim()
- .pip_install("marimo>=0.9.32", "modal>=0.67.31")
+ .pip_install("marimo>=0.12.8", "modal>=0.73.166")
.add_local_dir("nbs", remote_path="/root/nbs")
)
@@ -14,7 +14,7 @@ TOKEN = secrets.token_urlsafe(16)
PORT = 2718
[email protected](concurrency_limit=1, timeout=1_500, gpu="t4")
[email protected](max_containers=1, timeout=1_500, gpu="t4")
def run_marimo(timeout: int):
with modal.forward(PORT) as tunnel:
marimo_process = subprocess.Popen(
diff --git a/examples/cloud/modal/nbs/notebook.py b/examples/cloud/modal/nbs/notebook.py
index 8291cd5f51..151723de14 100644
--- a/examples/cloud/modal/nbs/notebook.py
+++ b/examples/cloud/modal/nbs/notebook.py
@@ -1,27 +1,72 @@
import marimo
-__generated_with = "0.8.4"
+__generated_with = "0.12.8"
app = marimo.App()
@app.cell
-def __(mo):
+def _():
+ import marimo as mo
+ import sys
+ import platform
+ import os
+
+ return mo, os, platform, sys
+
+
[email protected](hide_code=True)
+def _(mo):
mo.md("""# Hello, from inside Modal!""")
return
@app.cell
-def __():
- import marimo as mo
- return (mo,)
+def _(mo):
+ import subprocess
+ try:
+ result = subprocess.run(
+ ["nvidia-smi"],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ check=True,
+ )
+ output = mo.md(
+ f"""## 🚀 GPU is available:
+ ```
+ {result.stdout.decode()}
-def __():
- import subprocess
+ ```
+ """,
+ )
+ except FileNotFoundError:
+ output = mo.md("## ✅️ We are running on CPU")
+
+ output
+ return output, result, subprocess
- subprocess.run(["nvidia-smi"])
- return subprocess
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""## Runtime information""")
+ return
+
+
+def _(mo, os, platform, sys):
+ runtime_info = {
+ "python_version": sys.version,
+ "platform": sys.platform,
+ "arch": platform.machine(),
+ "executable_path": sys.executable,
+ "implementation": sys.implementation.name,
+ "sys.path": sys.path,
+ "argv": sys.argv,
+ "working_directory": os.getcwd(),
+ "ls": os.listdir(os.getcwd()),
+ }
+ mo.ui.table(runtime_info, selection=None, page_size=len(runtime_info))
+ return (runtime_info,)
if __name__ == "__main__":