-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
219 lines (194 loc) · 8.75 KB
/
streamlit_app.py
File metadata and controls
219 lines (194 loc) · 8.75 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import base64
import streamlit as st
st.set_page_config(page_title="Streamlit Components Demo", layout="wide", page_icon="🧩")
st.title("🧩 Streamlit Components Showcase")
st.caption("Four custom components by Dan Sheils — Kanban · Audio Editor · Stepper · Node Editor")
tab1, tab2, tab3, tab4 = st.tabs(["📋 Kanban", "🎛️ Audio Editor", "🪜 Stepper", "🔗 Node Editor"])
# ─── Kanban ──────────────────────────────────────────────────────────────────
with tab1:
from streamlit_kanban import st_kanban
st.subheader("Drag-and-drop Kanban Board")
st.caption("Move cards between columns, click to edit, add new cards.")
DEFAULT_COLUMNS = [
{
"id": "backlog",
"title": "Backlog",
"color": "#6366f1",
"cards": [
{"id": "c1", "title": "Research competitors", "tag": "Research", "priority": "low"},
{"id": "c2", "title": "Define MVP scope", "tag": "Strategy", "priority": "high"},
],
},
{
"id": "in-progress",
"title": "In Progress",
"color": "#f59e0b",
"cards": [
{"id": "c3", "title": "Build auth flow", "tag": "Dev", "priority": "high"},
],
},
{
"id": "review",
"title": "In Review",
"color": "#8b5cf6",
"cards": [
{"id": "c4", "title": "Landing page redesign", "tag": "Design", "priority": "high"},
],
},
{
"id": "done",
"title": "Done",
"color": "#10b981",
"cards": [
{"id": "c5", "title": "Project kickoff", "tag": "Planning", "priority": "low"},
],
},
]
if "board" not in st.session_state:
st.session_state.board = DEFAULT_COLUMNS
result = st_kanban(st.session_state.board, key="demo_kanban")
if result:
st.session_state.board = result
with st.expander("Board JSON"):
st.json(st.session_state.board)
# ─── Audio Editor ────────────────────────────────────────────────────────────
with tab2:
from streamlit_audio_editor import st_audio_editor
st.subheader("Browser-Based Audio Editor & Jam Session")
st.caption("Load audio or enable your mic. Apply effects in real time. Hit REC to capture your jam.")
result = st_audio_editor(key="demo_audio")
if result and result.get("type") == "export":
col1, col2, col3 = st.columns(3)
col1.metric("Trim start", f"{result['trimStart']:.3f}s")
col2.metric("Trim end", f"{result['trimEnd']:.3f}s")
col3.metric("Duration", f"{result['trimEnd'] - result['trimStart']:.3f}s")
wav_bytes = base64.b64decode(result["wavBase64"])
st.audio(wav_bytes, format="audio/wav")
st.download_button("⬇ Download trimmed WAV", wav_bytes, "trimmed.wav", "audio/wav")
if result and result.get("type") == "recording":
st.success(f"🎤 Recording captured — {result['durationSec']:.1f}s")
audio_bytes = base64.b64decode(result["recordingBase64"])
st.audio(audio_bytes, format=result["mimeType"])
st.download_button("⬇ Download recording", audio_bytes, "jam.webm", result["mimeType"])
# ─── Stepper ─────────────────────────────────────────────────────────────────
with tab3:
from streamlit_stepper import st_stepper
st.subheader("Multi-Step Wizard")
st.caption("Fill out each step, validation blocks progress until required fields are complete.")
STEPS = [
{
"label": "Project",
"subtitle": "Name & describe",
"icon": "◈",
"fields": [
{"key": "name", "label": "Project name", "type": "text",
"placeholder": "e.g. Apollo Dashboard", "required": True},
{"key": "description", "label": "Description", "type": "textarea",
"placeholder": "What does this project do?", "required": False},
{"key": "type", "label": "Project type", "type": "select",
"options": ["Web App", "Data Pipeline", "ML Model", "API Service"],
"required": True},
],
},
{
"label": "Team",
"subtitle": "Add collaborators",
"icon": "◉",
"fields": [
{"key": "owner", "label": "Owner email", "type": "text",
"placeholder": "[email protected]", "required": True},
{"key": "size", "label": "Team size", "type": "select",
"options": ["Solo", "2–5", "6–15", "15+"], "required": True},
],
},
{
"label": "Review",
"subtitle": "Confirm & launch",
"icon": "◆",
"fields": [],
},
]
result = st_stepper(STEPS, orientation="horizontal", key="demo_stepper")
if result and result.get("completed"):
st.balloons()
st.success(f"Project **{result['values'].get('name', 'Untitled')}** created!")
st.json(result["values"])
# ─── Node Editor ─────────────────────────────────────────────────────────────
with tab4:
from streamlit_node_editor import st_node_editor
st.subheader("Node Graph Editor")
st.caption("Right-click the canvas to add nodes. Drag ports to connect. Click a wire to delete. Del key removes selected node.")
NODE_DEFS = {
"Load Checkpoint": {
"category": "Loaders",
"headerColor": "#fb923c",
"inputs": [],
"outputs": [
{"name": "MODEL", "type": "MODEL"},
{"name": "CLIP", "type": "CLIP"},
{"name": "VAE", "type": "VAE"},
],
"params": [
{"key": "ckpt_name", "label": "Checkpoint", "type": "select",
"options": ["v1-5-pruned.ckpt", "sd_xl_base.safetensors"]},
],
},
"CLIP Text Encode": {
"category": "Conditioning",
"headerColor": "#facc15",
"inputs": [{"name": "clip", "type": "CLIP"}],
"outputs": [{"name": "CONDITIONING", "type": "LATENT"}],
"params": [{"key": "text", "label": "Prompt", "type": "textarea"}],
},
"KSampler": {
"category": "Sampling",
"headerColor": "#818cf8",
"inputs": [
{"name": "model", "type": "MODEL"},
{"name": "positive", "type": "LATENT"},
{"name": "negative", "type": "LATENT"},
{"name": "latent_image", "type": "LATENT"},
],
"outputs": [{"name": "LATENT", "type": "LATENT"}],
"params": [
{"key": "steps", "label": "Steps", "type": "int", "default": 20},
{"key": "cfg", "label": "CFG", "type": "float", "default": 7.0},
{"key": "sampler", "label": "Sampler", "type": "select",
"options": ["euler", "euler_a", "dpm++2m", "ddim"]},
],
},
"Empty Latent Image": {
"category": "Latent",
"headerColor": "#c084fc",
"inputs": [],
"outputs": [{"name": "LATENT", "type": "LATENT"}],
"params": [
{"key": "width", "label": "Width", "type": "int", "default": 512},
{"key": "height", "label": "Height", "type": "int", "default": 512},
],
},
"VAE Decode": {
"category": "Latent",
"headerColor": "#f87171",
"inputs": [
{"name": "samples", "type": "LATENT"},
{"name": "vae", "type": "VAE"},
],
"outputs": [{"name": "IMAGE", "type": "IMAGE"}],
"params": [],
},
"Save Image": {
"category": "Output",
"headerColor": "#4ade80",
"inputs": [{"name": "images", "type": "IMAGE"}],
"outputs": [],
"params": [
{"key": "filename_prefix", "label": "Filename", "type": "string",
"default": "output"},
],
},
}
graph = st_node_editor(NODE_DEFS, height=650, key="demo_graph")
if graph:
with st.expander(f"Graph JSON — {len(graph['nodes'])} nodes, {len(graph['connections'])} connections"):
st.json(graph)