Update app.py
Browse files
app.py
CHANGED
@@ -244,22 +244,62 @@ await initHydra({{feedStrudel:5}})
|
|
244 |
if not generated_code.startswith("$:"):
|
245 |
generated_code = f"$: {generated_code}"
|
246 |
|
247 |
-
complete_code = f"""{visual_code}{generated_code}
|
248 |
-
|
249 |
-
// Global effects (uncomment to use)
|
250 |
-
// all(x => x.fft(5).scope())"""
|
251 |
|
252 |
return complete_code
|
253 |
|
254 |
# Main generation function
|
255 |
-
def generate_interface(prompt, genre, complexity, include_visuals, visual_style):
|
256 |
"""Main interface function that generates working code"""
|
257 |
|
258 |
if not prompt.strip():
|
259 |
return "Please enter a description of the music you want to create."
|
260 |
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
# Create complete working template
|
265 |
complete_code = create_complete_strudel_code(strudel_code, include_visuals, visual_style)
|
@@ -269,7 +309,7 @@ def generate_interface(prompt, genre, complexity, include_visuals, visual_style)
|
|
269 |
# Create Gradio interface
|
270 |
with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app:
|
271 |
gr.Markdown("""
|
272 |
-
# π΅
|
273 |
|
274 |
Generate Strudel live coding patterns!
|
275 |
|
@@ -308,12 +348,17 @@ with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app
|
|
308 |
value=True
|
309 |
)
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
value=
|
314 |
-
label="ποΈ Visual Style"
|
315 |
)
|
316 |
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
generate_btn = gr.Button("π΅ Generate Working Code", variant="primary", size="lg")
|
318 |
|
319 |
with gr.Column():
|
@@ -328,7 +373,6 @@ with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app
|
|
328 |
1. **Copy** all the code above
|
329 |
2. **Go to** [strudel.cc](https://strudel.cc)
|
330 |
3. **Paste** and **click the play button** βΆοΈ
|
331 |
-
4. **It will work!** π
|
332 |
|
333 |
**π§ Customization:**
|
334 |
- Change `.gain()` values (0.1 to 1.0)
|
@@ -363,7 +407,8 @@ with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app
|
|
363 |
genre_dropdown,
|
364 |
complexity_dropdown,
|
365 |
include_visuals,
|
366 |
-
visual_style
|
|
|
367 |
],
|
368 |
outputs=output_code
|
369 |
)
|
|
|
244 |
if not generated_code.startswith("$:"):
|
245 |
generated_code = f"$: {generated_code}"
|
246 |
|
247 |
+
complete_code = f"""{visual_code}{generated_code}"""
|
|
|
|
|
|
|
248 |
|
249 |
return complete_code
|
250 |
|
251 |
# Main generation function
|
252 |
+
def generate_interface(prompt, genre, complexity, include_visuals, visual_style, use_ai):
|
253 |
"""Main interface function that generates working code"""
|
254 |
|
255 |
if not prompt.strip():
|
256 |
return "Please enter a description of the music you want to create."
|
257 |
|
258 |
+
if use_ai:
|
259 |
+
# Use AI generation
|
260 |
+
system_prompt = f"""Generate working Strudel live coding pattern for: {prompt}
|
261 |
+
Genre: {genre}, Complexity: {complexity}
|
262 |
+
|
263 |
+
Example patterns:
|
264 |
+
s("bd*4").gain(0.8)
|
265 |
+
stack(s("bd ~ ~ ~"), n("0 2 4").s("sine").octave(3))
|
266 |
+
|
267 |
+
Pattern:"""
|
268 |
+
|
269 |
+
try:
|
270 |
+
outputs = code_generator(
|
271 |
+
system_prompt,
|
272 |
+
max_length=len(system_prompt.split()) + 50,
|
273 |
+
temperature=0.7,
|
274 |
+
do_sample=True,
|
275 |
+
top_p=0.9,
|
276 |
+
num_return_sequences=1
|
277 |
+
)
|
278 |
+
|
279 |
+
generated_text = outputs[0]['generated_text']
|
280 |
+
strudel_code = generated_text[len(system_prompt):].strip()
|
281 |
+
|
282 |
+
# Clean the AI output
|
283 |
+
lines = strudel_code.split('\n')
|
284 |
+
clean_lines = []
|
285 |
+
for line in lines[:5]: # Limit to 5 lines
|
286 |
+
line = line.strip()
|
287 |
+
if line and (line.startswith('s(') or line.startswith('n(') or line.startswith('stack(') or
|
288 |
+
'.gain(' in line or '.s(' in line or line.endswith(')')):
|
289 |
+
clean_lines.append(line)
|
290 |
+
|
291 |
+
if clean_lines:
|
292 |
+
strudel_code = '\n'.join(clean_lines)
|
293 |
+
strudel_code = f"// AI Generated: {prompt}\n{strudel_code}"
|
294 |
+
else:
|
295 |
+
# Fallback to random if AI fails
|
296 |
+
strudel_code = generate_working_strudel_code(prompt, genre, complexity)
|
297 |
+
except:
|
298 |
+
# Fallback to random if AI fails
|
299 |
+
strudel_code = generate_working_strudel_code(prompt, genre, complexity)
|
300 |
+
else:
|
301 |
+
# Use random generation
|
302 |
+
strudel_code = generate_working_strudel_code(prompt, genre, complexity)
|
303 |
|
304 |
# Create complete working template
|
305 |
complete_code = create_complete_strudel_code(strudel_code, include_visuals, visual_style)
|
|
|
309 |
# Create Gradio interface
|
310 |
with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app:
|
311 |
gr.Markdown("""
|
312 |
+
# π΅ CODEL: Strudel Code Generator
|
313 |
|
314 |
Generate Strudel live coding patterns!
|
315 |
|
|
|
348 |
value=True
|
349 |
)
|
350 |
|
351 |
+
use_ai = gr.Checkbox(
|
352 |
+
label="π€ Use AI generation",
|
353 |
+
value=False
|
|
|
354 |
)
|
355 |
|
356 |
+
visual_style = gr.Dropdown(
|
357 |
+
choices=["reactive", "kaleidoscope", "flowing", "geometric"],
|
358 |
+
value="reactive",
|
359 |
+
label="ποΈ Visual Style"
|
360 |
+
)
|
361 |
+
|
362 |
generate_btn = gr.Button("π΅ Generate Working Code", variant="primary", size="lg")
|
363 |
|
364 |
with gr.Column():
|
|
|
373 |
1. **Copy** all the code above
|
374 |
2. **Go to** [strudel.cc](https://strudel.cc)
|
375 |
3. **Paste** and **click the play button** βΆοΈ
|
|
|
376 |
|
377 |
**π§ Customization:**
|
378 |
- Change `.gain()` values (0.1 to 1.0)
|
|
|
407 |
genre_dropdown,
|
408 |
complexity_dropdown,
|
409 |
include_visuals,
|
410 |
+
visual_style,
|
411 |
+
use_ai
|
412 |
],
|
413 |
outputs=output_code
|
414 |
)
|