Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
from
|
|
|
|
|
|
|
|
|
|
| 4 |
from content_generator.hooks import generate_hooks
|
| 5 |
from content_generator.captions import generate_captions
|
| 6 |
from content_generator.ideas import generate_content_ideas
|
|
@@ -8,23 +11,86 @@ from content_generator.scripts import generate_short_scripts
|
|
| 8 |
from pack_builder.zip_builder import build_creator_pack
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# -------------------------------
|
| 12 |
# BEAT GENERATOR CALLBACK
|
| 13 |
# -------------------------------
|
| 14 |
def ui_generate_beats(style, bpm, loops):
|
| 15 |
audio = None
|
| 16 |
loops = int(loops)
|
| 17 |
-
for _ in range(loops):
|
| 18 |
-
audio = generate_audio_loop(style, bpm)
|
| 19 |
-
return audio
|
| 20 |
-
|
| 21 |
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
# MIDI GENERATOR CALLBACK
|
| 25 |
-
# -------------------------------
|
| 26 |
-
def ui_generate_midi(bpm, pattern_type):
|
| 27 |
-
return generate_midi_pattern(bpm, pattern_type)
|
| 28 |
|
| 29 |
|
| 30 |
|
|
@@ -85,7 +151,6 @@ with gr.Blocks(title="AI Content + Beat Generator (Free Tier)") as demo:
|
|
| 85 |
)
|
| 86 |
|
| 87 |
|
| 88 |
-
|
| 89 |
# ---------------------------
|
| 90 |
# CONTENT GENERATOR
|
| 91 |
# ---------------------------
|
|
@@ -108,7 +173,6 @@ with gr.Blocks(title="AI Content + Beat Generator (Free Tier)") as demo:
|
|
| 108 |
)
|
| 109 |
|
| 110 |
|
| 111 |
-
|
| 112 |
# ---------------------------
|
| 113 |
# PACK BUILDER
|
| 114 |
# ---------------------------
|
|
@@ -132,6 +196,4 @@ with gr.Blocks(title="AI Content + Beat Generator (Free Tier)") as demo:
|
|
| 132 |
)
|
| 133 |
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from scipy.io.wavfile import write
|
| 4 |
+
import os
|
| 5 |
+
import uuid
|
| 6 |
+
|
| 7 |
from content_generator.hooks import generate_hooks
|
| 8 |
from content_generator.captions import generate_captions
|
| 9 |
from content_generator.ideas import generate_content_ideas
|
|
|
|
| 11 |
from pack_builder.zip_builder import build_creator_pack
|
| 12 |
|
| 13 |
|
| 14 |
+
# -----------------------------------------------------
|
| 15 |
+
# SIMPLE CPU-SAFE BEAT GENERATOR (NO MODELS)
|
| 16 |
+
# -----------------------------------------------------
|
| 17 |
+
def generate_cpu_safe_beat(style, bpm):
|
| 18 |
+
sr = 44100 # sample rate
|
| 19 |
+
seconds = 8 # loop length
|
| 20 |
+
t = np.linspace(0, seconds, int(sr * seconds))
|
| 21 |
+
|
| 22 |
+
beat = np.zeros_like(t)
|
| 23 |
+
|
| 24 |
+
# -------------------------------------------------
|
| 25 |
+
# STYLE PRESETS (lightweight procedural synthesis)
|
| 26 |
+
# -------------------------------------------------
|
| 27 |
+
if style == "Country Rap":
|
| 28 |
+
kick_freq = 55
|
| 29 |
+
snare_freq = 180
|
| 30 |
+
hat_freq = 8000
|
| 31 |
+
|
| 32 |
+
elif style == "Trap":
|
| 33 |
+
kick_freq = 45
|
| 34 |
+
snare_freq = 200
|
| 35 |
+
hat_freq = 10000
|
| 36 |
+
|
| 37 |
+
elif style == "Dark Outlaw":
|
| 38 |
+
kick_freq = 60
|
| 39 |
+
snare_freq = 150
|
| 40 |
+
hat_freq = 6000
|
| 41 |
+
|
| 42 |
+
elif style == "Drill":
|
| 43 |
+
kick_freq = 40
|
| 44 |
+
snare_freq = 160
|
| 45 |
+
hat_freq = 9000
|
| 46 |
+
|
| 47 |
+
else: # BoomBap
|
| 48 |
+
kick_freq = 70
|
| 49 |
+
snare_freq = 190
|
| 50 |
+
hat_freq = 7000
|
| 51 |
+
|
| 52 |
+
# -------------------------------------------------
|
| 53 |
+
# BEAT PATTERN (Kick, Snare, Hats)
|
| 54 |
+
# -------------------------------------------------
|
| 55 |
+
beat_interval = 60 / bpm
|
| 56 |
+
hits = int(seconds / beat_interval)
|
| 57 |
+
|
| 58 |
+
for i in range(hits):
|
| 59 |
+
pos = int(i * beat_interval * sr)
|
| 60 |
+
|
| 61 |
+
# Kick
|
| 62 |
+
beat[pos:pos+2000] += np.sin(2 * np.pi * kick_freq * t[:2000]) * 0.9
|
| 63 |
+
|
| 64 |
+
# Snare
|
| 65 |
+
if i % 2 == 1:
|
| 66 |
+
beat[pos:pos+2000] += np.sin(2 * np.pi * snare_freq * t[:2000]) * 0.5
|
| 67 |
+
|
| 68 |
+
# Hats
|
| 69 |
+
beat[pos:pos+500] += (np.random.randn(500)) * 0.1
|
| 70 |
+
|
| 71 |
+
# Normalize
|
| 72 |
+
beat /= np.max(np.abs(beat) + 1e-9)
|
| 73 |
+
|
| 74 |
+
# Save file
|
| 75 |
+
filename = f"beat_{uuid.uuid4().hex}.wav"
|
| 76 |
+
filepath = f"/tmp/{filename}"
|
| 77 |
+
write(filepath, sr, (beat * 32767).astype(np.int16))
|
| 78 |
+
|
| 79 |
+
return filepath
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
# -------------------------------
|
| 84 |
# BEAT GENERATOR CALLBACK
|
| 85 |
# -------------------------------
|
| 86 |
def ui_generate_beats(style, bpm, loops):
|
| 87 |
audio = None
|
| 88 |
loops = int(loops)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
for _ in range(loops):
|
| 91 |
+
audio = generate_cpu_safe_beat(style, bpm)
|
| 92 |
|
| 93 |
+
return audio
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
|
| 96 |
|
|
|
|
| 151 |
)
|
| 152 |
|
| 153 |
|
|
|
|
| 154 |
# ---------------------------
|
| 155 |
# CONTENT GENERATOR
|
| 156 |
# ---------------------------
|
|
|
|
| 173 |
)
|
| 174 |
|
| 175 |
|
|
|
|
| 176 |
# ---------------------------
|
| 177 |
# PACK BUILDER
|
| 178 |
# ---------------------------
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
|
|
|
|
|
|
|
| 199 |
demo.launch()
|