Update app.py
Browse files
app.py
CHANGED
|
@@ -243,11 +243,14 @@ def create_variations(base_pattern, genre):
|
|
| 243 |
return random.choice(variations)
|
| 244 |
|
| 245 |
def generate_working_strudel_code(prompt, genre="techno", complexity="moderate"):
|
| 246 |
-
"""Generate guaranteed working Strudel code"""
|
| 247 |
|
| 248 |
-
# Get base working pattern
|
| 249 |
base_pattern = get_random_working_pattern(genre, complexity)
|
| 250 |
|
|
|
|
|
|
|
|
|
|
| 251 |
# Create variations based on prompt keywords
|
| 252 |
if any(word in prompt.lower() for word in ["fast", "speed", "quick", "rapid", "energetic"]):
|
| 253 |
if "sometimes(fast(2))" not in base_pattern:
|
|
@@ -277,8 +280,12 @@ def generate_working_strudel_code(prompt, genre="techno", complexity="moderate")
|
|
| 277 |
if ".pan(" not in base_pattern:
|
| 278 |
base_pattern = base_pattern.replace(".gain(", ".pan(sine.slow(4)).gain(")
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# Add comment based on prompt
|
| 281 |
-
comment_line = f"// {prompt[:50]}{'...' if len(prompt) > 50 else ''}"
|
| 282 |
|
| 283 |
return f"{comment_line}\n{base_pattern}"
|
| 284 |
|
|
@@ -424,24 +431,27 @@ def generate_interface(prompt, genre, complexity, include_visuals, use_ai):
|
|
| 424 |
return "Please enter a description of the music you want to create."
|
| 425 |
|
| 426 |
if use_ai:
|
| 427 |
-
# Use AI generation with
|
|
|
|
|
|
|
|
|
|
| 428 |
system_prompt = f"""Generate working Strudel live coding pattern for: {prompt}
|
| 429 |
-
Genre: {genre}, Complexity: {complexity}
|
| 430 |
|
| 431 |
Example Strudel patterns:
|
| 432 |
s("bd*4, hh*8").gain(0.8)
|
| 433 |
stack(s("bd ~ sn ~"), n("0 2 4").s("sine").octave(3).gain(0.7))
|
| 434 |
n("[0 3 5 7]*2").s("sawtooth").octave(2).lpf(1200).gain(0.8).scale("a:minor")
|
| 435 |
|
| 436 |
-
Generate a {complexity} {genre} pattern:"""
|
| 437 |
|
| 438 |
try:
|
| 439 |
outputs = code_generator(
|
| 440 |
system_prompt,
|
| 441 |
max_length=len(system_prompt.split()) + 80,
|
| 442 |
-
temperature=0.
|
| 443 |
do_sample=True,
|
| 444 |
-
top_p=0.
|
| 445 |
num_return_sequences=1
|
| 446 |
)
|
| 447 |
|
|
@@ -464,7 +474,7 @@ Generate a {complexity} {genre} pattern:"""
|
|
| 464 |
|
| 465 |
if clean_lines:
|
| 466 |
strudel_code = '\n'.join(clean_lines)
|
| 467 |
-
strudel_code = f"// AI Generated: {prompt}\n{strudel_code}"
|
| 468 |
else:
|
| 469 |
# Fallback to curated patterns if AI fails
|
| 470 |
strudel_code = generate_working_strudel_code(prompt, genre, complexity)
|
|
@@ -484,7 +494,7 @@ Generate a {complexity} {genre} pattern:"""
|
|
| 484 |
# Create Gradio interface
|
| 485 |
with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app:
|
| 486 |
gr.Markdown("""
|
| 487 |
-
# π΅ CODEL: Strudel Code Generator
|
| 488 |
|
| 489 |
Generate high-quality Strudel live coding patterns!
|
| 490 |
|
|
@@ -492,7 +502,7 @@ with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app
|
|
| 492 |
ποΈ **Real Strudel syntax** - copy & paste ready
|
| 493 |
π¨ **Random genre-specific visuals** - different every time!
|
| 494 |
π΅ **6 genres** with authentic patterns
|
| 495 |
-
|
| 496 |
|
| 497 |
**Usage:** Describe music β Generate β Copy to [strudel.cc](https://strudel.cc) β Play!
|
| 498 |
""")
|
|
@@ -555,7 +565,7 @@ with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app
|
|
| 555 |
gr.Markdown("### πͺ Premium Examples (Pro Quality)")
|
| 556 |
with gr.Row():
|
| 557 |
working_examples = [
|
| 558 |
-
["
|
| 559 |
["Deep house with swing", "house", "moderate"],
|
| 560 |
["Ethereal ambient soundscape", "ambient", "complex"],
|
| 561 |
["Crunchy hip-hop beat", "hiphop", "moderate"],
|
|
|
|
| 243 |
return random.choice(variations)
|
| 244 |
|
| 245 |
def generate_working_strudel_code(prompt, genre="techno", complexity="moderate"):
|
| 246 |
+
"""Generate guaranteed working Strudel code - ALWAYS RANDOM"""
|
| 247 |
|
| 248 |
+
# Get base working pattern - ALWAYS RANDOM
|
| 249 |
base_pattern = get_random_working_pattern(genre, complexity)
|
| 250 |
|
| 251 |
+
# Add random variations to make it even more unique
|
| 252 |
+
base_pattern = create_variations(base_pattern, genre)
|
| 253 |
+
|
| 254 |
# Create variations based on prompt keywords
|
| 255 |
if any(word in prompt.lower() for word in ["fast", "speed", "quick", "rapid", "energetic"]):
|
| 256 |
if "sometimes(fast(2))" not in base_pattern:
|
|
|
|
| 280 |
if ".pan(" not in base_pattern:
|
| 281 |
base_pattern = base_pattern.replace(".gain(", ".pan(sine.slow(4)).gain(")
|
| 282 |
|
| 283 |
+
# Add random timestamp to ensure uniqueness
|
| 284 |
+
import time
|
| 285 |
+
timestamp = int(time.time() * 1000) % 10000 # Last 4 digits of timestamp
|
| 286 |
+
|
| 287 |
# Add comment based on prompt
|
| 288 |
+
comment_line = f"// {prompt[:50]}{'...' if len(prompt) > 50 else ''} #{timestamp}"
|
| 289 |
|
| 290 |
return f"{comment_line}\n{base_pattern}"
|
| 291 |
|
|
|
|
| 431 |
return "Please enter a description of the music you want to create."
|
| 432 |
|
| 433 |
if use_ai:
|
| 434 |
+
# Use AI generation with random temperature and seed for variety
|
| 435 |
+
import time
|
| 436 |
+
random_seed = int(time.time() * 1000) % 1000 # Random seed based on timestamp
|
| 437 |
+
|
| 438 |
system_prompt = f"""Generate working Strudel live coding pattern for: {prompt}
|
| 439 |
+
Genre: {genre}, Complexity: {complexity}, Variation: {random_seed}
|
| 440 |
|
| 441 |
Example Strudel patterns:
|
| 442 |
s("bd*4, hh*8").gain(0.8)
|
| 443 |
stack(s("bd ~ sn ~"), n("0 2 4").s("sine").octave(3).gain(0.7))
|
| 444 |
n("[0 3 5 7]*2").s("sawtooth").octave(2).lpf(1200).gain(0.8).scale("a:minor")
|
| 445 |
|
| 446 |
+
Generate a unique {complexity} {genre} pattern:"""
|
| 447 |
|
| 448 |
try:
|
| 449 |
outputs = code_generator(
|
| 450 |
system_prompt,
|
| 451 |
max_length=len(system_prompt.split()) + 80,
|
| 452 |
+
temperature=random.uniform(0.7, 1.2), # Random temperature for variety
|
| 453 |
do_sample=True,
|
| 454 |
+
top_p=random.uniform(0.8, 0.95), # Random top_p for variety
|
| 455 |
num_return_sequences=1
|
| 456 |
)
|
| 457 |
|
|
|
|
| 474 |
|
| 475 |
if clean_lines:
|
| 476 |
strudel_code = '\n'.join(clean_lines)
|
| 477 |
+
strudel_code = f"// AI Generated: {prompt} #{random_seed}\n{strudel_code}"
|
| 478 |
else:
|
| 479 |
# Fallback to curated patterns if AI fails
|
| 480 |
strudel_code = generate_working_strudel_code(prompt, genre, complexity)
|
|
|
|
| 494 |
# Create Gradio interface
|
| 495 |
with gr.Blocks(title="Working Strudel Generator", theme=gr.themes.Soft()) as app:
|
| 496 |
gr.Markdown("""
|
| 497 |
+
# π΅ CODEL: AI Strudel Code Generator
|
| 498 |
|
| 499 |
Generate high-quality Strudel live coding patterns!
|
| 500 |
|
|
|
|
| 502 |
ποΈ **Real Strudel syntax** - copy & paste ready
|
| 503 |
π¨ **Random genre-specific visuals** - different every time!
|
| 504 |
π΅ **6 genres** with authentic patterns
|
| 505 |
+
|
| 506 |
|
| 507 |
**Usage:** Describe music β Generate β Copy to [strudel.cc](https://strudel.cc) β Play!
|
| 508 |
""")
|
|
|
|
| 565 |
gr.Markdown("### πͺ Premium Examples (Pro Quality)")
|
| 566 |
with gr.Row():
|
| 567 |
working_examples = [
|
| 568 |
+
["Techno with filter sweeps", "techno", "complex"],
|
| 569 |
["Deep house with swing", "house", "moderate"],
|
| 570 |
["Ethereal ambient soundscape", "ambient", "complex"],
|
| 571 |
["Crunchy hip-hop beat", "hiphop", "moderate"],
|