-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarimo_example.py
More file actions
149 lines (113 loc) · 3.28 KB
/
Copy pathmarimo_example.py
File metadata and controls
149 lines (113 loc) · 3.28 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
spore.host — marimo notebook example
Run with:
pip install marimo spore-host
marimo edit marimo_example.py
"""
import marimo as mo
app = mo.App(width="medium")
@app.cell
def _():
import spore
mo.md(f"**spore-host** {spore.__version__} — ephemeral EC2 compute")
@app.cell
def _(mo):
mo.md("""
## Find instances
Search for EC2 instance types using natural language.
""")
@app.cell
def _(mo):
query = mo.ui.text(
value="amd epyc genoa",
label="Search query",
placeholder="e.g. nvidia h100, arm64 32gb, amd genoa",
)
region = mo.ui.dropdown(
options=["us-east-1", "us-west-2", "eu-west-1", "ap-northeast-1"],
value="us-east-1",
label="Region",
)
mo.hstack([query, region])
@app.cell
def _(mo, query, region):
import spore
results = spore.truffle.find(query.value, region=region.value)
if not results:
mo.callout(mo.md("No results. Try a different query."), kind="warn")
else:
mo.table([
{
"Instance": r.instance_type,
"vCPUs": r.vcpus,
"Memory (GiB)": f"{r.memory_gib:.0f}",
"$/hr": f"${r.on_demand_price:.4f}" if r.on_demand_price else "—",
"AZs": len(r.available_azs),
}
for r in results
])
@app.cell
def _(mo):
mo.md("""
## Running instances
Current spawn-managed instances in your account.
""")
@app.cell
def _(mo):
refresh_btn = mo.ui.button(label="Refresh", kind="neutral")
refresh_btn
@app.cell
def _(mo, refresh_btn):
import spore
_ = refresh_btn.value # re-run when button clicked
instances = spore.spawn.list(state="all")
if not instances:
mo.callout(mo.md("No instances found."), kind="info")
else:
rows = []
for inst in instances:
rows.append({
"Name": inst.name,
"Type": inst.instance_type,
"State": inst.state,
"Region": inst.region,
"IP": inst.public_ip or "—",
"TTL": inst.ttl or "—",
})
mo.table(rows)
@app.cell
def _(mo):
mo.md("""
## Manage an instance
Enter an instance name or ID to manage it.
""")
@app.cell
def _(mo):
inst_input = mo.ui.text(label="Instance name or ID", placeholder="sim-run-42")
inst_input
@app.cell
def _(inst_input, mo):
import spore
if not inst_input.value:
mo.stop(True, mo.md("Enter an instance name above."))
try:
inst = spore.spawn.status(inst_input.value)
state_color = {
"running": "green", "stopped": "orange",
"terminated": "gray", "pending": "blue",
}.get(inst.state, "gray")
mo.md(f"""
**{inst.name}** `{inst.instance_id}`
| Field | Value |
|-------|-------|
| Type | {inst.instance_type} |
| State | <span style="color:{state_color}">**{inst.state}**</span> |
| Region | {inst.region} |
| IP | {inst.public_ip or "—"} |
| TTL | {inst.ttl or "—"} |
| Idle timeout | {inst.idle_timeout or "—"} |
""")
except Exception as e:
mo.callout(mo.md(f"Error: {e}"), kind="danger")
if __name__ == "__main__":
app.run()