davanstrien HF Staff Claude Opus 4.5 commited on
Commit
55b755d
·
1 Parent(s): 60f0a91

Add getting-started marimo notebook

Browse files

First marimo-based UV script demonstrating dual-mode execution:
- Interactive tutorial via `uvx marimo edit --sandbox`
- Batch script via `uv run`

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. README.md +70 -0
  2. getting-started.py +143 -0
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ viewer: false
3
+ tags:
4
+ - uv-script
5
+ - marimo
6
+ - tutorial
7
+ ---
8
+
9
+ # Marimo UV Scripts
10
+
11
+ [Marimo](https://marimo.io/) notebooks that work as both **interactive tutorials** and **batch scripts**.
12
+
13
+ ## What is this?
14
+
15
+ Marimo notebooks are pure Python files that can be:
16
+ - **Edited interactively** with a reactive notebook interface
17
+ - **Run as scripts** with `uv run` - same as any UV script
18
+
19
+ This makes them perfect for tutorials and educational content where you want users to explore step-by-step, but also run the whole thing as a batch job.
20
+
21
+ ## Available Scripts
22
+
23
+ | Script | Description |
24
+ |--------|-------------|
25
+ | `getting-started.py` | Introduction to UV scripts and HF datasets |
26
+
27
+ ## Usage
28
+
29
+ ### Run as a script
30
+
31
+ ```bash
32
+ # Run directly from Hugging Face
33
+ uv run https://huggingface.co/datasets/uv-scripts/marimo/raw/main/getting-started.py --help
34
+
35
+ # Load a dataset and show info
36
+ uv run https://huggingface.co/datasets/uv-scripts/marimo/raw/main/getting-started.py --dataset squad
37
+ ```
38
+
39
+ ### Run interactively
40
+
41
+ ```bash
42
+ # Clone and edit locally
43
+ git clone https://huggingface.co/datasets/uv-scripts/marimo
44
+ cd marimo
45
+
46
+ # Open in marimo editor (--sandbox auto-installs dependencies)
47
+ uvx marimo edit --sandbox getting-started.py
48
+ ```
49
+
50
+ ### Run on HF Jobs
51
+
52
+ ```bash
53
+ hf jobs uv run --flavor cpu-basic \
54
+ -e HF_TOKEN=$(python3 -c "from huggingface_hub import get_token; print(get_token())") \
55
+ https://huggingface.co/datasets/uv-scripts/marimo/raw/main/getting-started.py \
56
+ --dataset squad
57
+ ```
58
+
59
+ ## Why Marimo?
60
+
61
+ - **Reactive**: Cells automatically re-run when dependencies change
62
+ - **Pure Python**: No JSON, git-friendly, readable as plain code
63
+ - **Self-contained**: Inline dependencies via PEP 723 metadata
64
+ - **Dual-mode**: Same file works as notebook and script
65
+
66
+ ## Learn More
67
+
68
+ - [Marimo documentation](https://docs.marimo.io/)
69
+ - [UV scripts guide](https://docs.astral.sh/uv/guides/scripts/)
70
+ - [uv-scripts organization](https://huggingface.co/uv-scripts)
getting-started.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.10"
3
+ # dependencies = [
4
+ # "marimo",
5
+ # "datasets",
6
+ # "huggingface-hub",
7
+ # ]
8
+ # ///
9
+ """
10
+ Getting Started with UV Scripts + Marimo
11
+
12
+ This notebook demonstrates how marimo notebooks can work as both:
13
+ - Interactive tutorials: `uvx marimo edit --sandbox getting-started.py`
14
+ - Batch scripts: `uv run getting-started.py --dataset squad`
15
+
16
+ Run with --help to see available options.
17
+ """
18
+
19
+ import marimo
20
+
21
+ app = marimo.App(width="medium")
22
+
23
+
24
+ @app.cell
25
+ def _():
26
+ import marimo as mo
27
+
28
+ mo.md(
29
+ """
30
+ # Getting Started with UV Scripts
31
+
32
+ This notebook shows how to work with Hugging Face datasets using UV scripts.
33
+
34
+ **Two ways to run this:**
35
+ - **Interactive**: `uvx marimo edit --sandbox getting-started.py`
36
+ - **As a script**: `uv run getting-started.py --dataset squad`
37
+ """
38
+ )
39
+ return (mo,)
40
+
41
+
42
+ @app.cell
43
+ def _(mo):
44
+ import argparse
45
+ import sys
46
+
47
+ parser = argparse.ArgumentParser(
48
+ description="Load and explore a Hugging Face dataset"
49
+ )
50
+ parser.add_argument(
51
+ "--dataset",
52
+ default="stanfordnlp/imdb",
53
+ help="Dataset to load (default: stanfordnlp/imdb)",
54
+ )
55
+ parser.add_argument(
56
+ "--split",
57
+ default="train",
58
+ help="Split to load (default: train)",
59
+ )
60
+ parser.add_argument(
61
+ "--num-samples",
62
+ type=int,
63
+ default=5,
64
+ help="Number of samples to display (default: 5)",
65
+ )
66
+
67
+ # Parse known args to avoid issues with marimo's internal args
68
+ args, _ = parser.parse_known_args()
69
+
70
+ mo.md(
71
+ f"""
72
+ ## Configuration
73
+
74
+ - **Dataset**: `{args.dataset}`
75
+ - **Split**: `{args.split}`
76
+ - **Samples to show**: `{args.num_samples}`
77
+ """
78
+ )
79
+ return args, argparse, parser, sys
80
+
81
+
82
+ @app.cell
83
+ def _(args, mo):
84
+ from datasets import load_dataset
85
+
86
+ mo.md(f"Loading dataset `{args.dataset}`...")
87
+ return (load_dataset,)
88
+
89
+
90
+ @app.cell
91
+ def _(args, load_dataset, mo):
92
+ # Load the dataset
93
+ dataset = load_dataset(args.dataset, split=args.split)
94
+
95
+ mo.md(
96
+ f"""
97
+ ## Dataset Info
98
+
99
+ - **Name**: {args.dataset}
100
+ - **Split**: {args.split}
101
+ - **Number of rows**: {len(dataset):,}
102
+ - **Features**: {list(dataset.features.keys())}
103
+ """
104
+ )
105
+ return (dataset,)
106
+
107
+
108
+ @app.cell
109
+ def _(args, dataset, mo):
110
+ # Show sample data
111
+ samples = dataset.select(range(min(args.num_samples, len(dataset))))
112
+
113
+ mo.md(f"## Sample Data (first {len(samples)} rows)")
114
+ return (samples,)
115
+
116
+
117
+ @app.cell
118
+ def _(samples):
119
+ # Display as a table (marimo will render this nicely)
120
+ samples.to_pandas()
121
+ return
122
+
123
+
124
+ @app.cell
125
+ def _(mo):
126
+ mo.md(
127
+ """
128
+ ## Next Steps
129
+
130
+ Now that you've seen the basics, try:
131
+
132
+ 1. **Change the dataset**: Run with `--dataset emotion` or any HF dataset
133
+ 2. **Explore interactively**: Edit cells, add visualizations
134
+ 3. **Run as batch**: `uv run getting-started.py --dataset squad --num-samples 10`
135
+
136
+ Check out more UV scripts at [uv-scripts on Hugging Face](https://huggingface.co/uv-scripts)
137
+ """
138
+ )
139
+ return
140
+
141
+
142
+ if __name__ == "__main__":
143
+ app.run()