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.

Add Whisper sandbox example (#10994)

Trevor Manz728708aff963
diff --git a/examples/misc/pixi_whisper.py b/examples/misc/pixi_whisper.py
new file mode 100644
index 0000000000..95805144b4
--- /dev/null
+++ b/examples/misc/pixi_whisper.py
@@ -0,0 +1,97 @@
+# /// script
+# requires-python = ">=3.12,<3.13"
+# dependencies = ["marimo>=0.25.0", "openai-whisper>=20250625"]
+#
+# [tool.pixi.workspace]
+# channels = ["conda-forge"]
+#
+# [tool.pixi.dependencies]
+# ffmpeg = "*"
+#
+# [tool.pixi.target.linux.dependencies]
+# pytorch-gpu = "*"
+#
+# [tool.pixi.target.win.dependencies]
+# pytorch-gpu = "*"
+#
+# [tool.pixi.target.osx.dependencies]
+# pytorch-cpu = "*"
+# ///
+
+import marimo
+
+__generated_with = "0.25.0"
+app = marimo.App(width="compact")
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""
+ With [Pixi installed](https://pixi.prefix.dev/latest/installation/), run:
+
+ ```bash
+ marimo edit --sandbox=pixi examples/misc/pixi_whisper.py
+ ```
+
+ Choose a recording to transcribe with Whisper. Pixi installs CUDA-enabled
+ PyTorch on Linux and Windows, and CPU PyTorch on macOS. The first run
+ downloads the model weights.
+ """)
+ return
+
+
+def _():
+ import torch
+ import whisper
+
+ device = "cuda" if torch.cuda.is_available() else "cpu"
+ model = whisper.load_model("tiny.en", device=device)
+ return model, whisper
+
+
+def _():
+ import marimo as mo
+
+ files = mo.ui.dropdown(
+ {
+ "The Ashiel Mystery": "https://librosa.org/data/audio/5703-47212-0000.ogg",
+ "The Age of Chivalry": "https://librosa.org/data/audio/3436-172162-0000.ogg",
+ "Sense and Sensibility": "https://librosa.org/data/audio/198-209-0000.ogg",
+ },
+ value="The Ashiel Mystery",
+ label="Recording:",
+ )
+ files
+ return files, mo
+
+
+def _(files, mo, whisper):
+ audio = whisper.load_audio(files.value)
+ mo.audio(audio, rate=16000)
+ return (audio,)
+
+
+def _(audio, model):
+ result = model.transcribe(audio, language="en", fp16=model.device.type == "cuda")
+ result["text"]
+ return
+
+
[email protected](hide_code=True)
+def _(mo):
+ mo.md("""
+ Audio: [LibriSpeech](https://www.openslr.org/12/), distributed by
+ [librosa](https://librosa.org/doc/main/recordings.html) under
+ [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
+ *The Ashiel Mystery* is read by Garth Comira, *The Age of Chivalry*
+ by Anders Lankford, and *Sense and Sensibility* by Heather Barnett.
+ """)
+ return
+
+
+if __name__ == "__main__":
+ app.run()