import gradio as gr import numpy as np import wave import struct import uuid from content_generator.hooks import generate_hooks from content_generator.captions import generate_captions from content_generator.ideas import generate_content_ideas from content_generator.scripts import generate_short_scripts from pack_builder.zip_builder import build_creator_pack # -------------------------------------------------- # CPU-SAFE BEAT GENERATOR (NO SCIPY) # -------------------------------------------------- def generate_cpu_safe_beat(style, bpm): sr = 44100 seconds = 8 t = np.linspace(0, seconds, int(sr * seconds)) beat = np.zeros_like(t) if style == "Country Rap": kick_freq, snare_freq, hat_freq = 55, 180, 8000 elif style == "Trap": kick_freq, snare_freq, hat_freq = 45, 200, 10000 elif style == "Dark Outlaw": kick_freq, snare_freq, hat_freq = 60, 150, 6000 elif style == "Drill": kick_freq, snare_freq, hat_freq = 40, 160, 9000 else: kick_freq, snare_freq, hat_freq = 70, 190, 7000 beat_interval = 60.0 / float(bpm) hits = int(seconds / beat_interval) for i in range(hits): pos = int(i * beat_interval * sr) if pos + 2000 <= len(beat): beat[pos:pos+2000] += np.sin(2 * np.pi * kick_freq * t[:2000]) * 0.9 if i % 2 == 1 and pos + 2000 <= len(beat): beat[pos:pos+2000] += np.sin(2 * np.pi * snare_freq * t[:2000]) * 0.5 if pos + 500 <= len(beat): beat[pos:pos+500] += np.random.randn(500) * 0.1 max_val = float(np.max(np.abs(beat))) or 1.0 beat = beat / max_val beat_int16 = (beat * 32767).astype(np.int16) filename = f"beat_{uuid.uuid4().hex}.wav" filepath = f"/tmp/{filename}" with wave.open(filepath, "w") as wf: wf.setnchannels(1) wf.setsampwidth(2) wf.setframerate(sr) wf.writeframes(beat_int16.tobytes()) return filepath def ui_generate_beats(style, bpm, loops): audio = None for _ in range(int(loops)): audio = generate_cpu_safe_beat(style, bpm) return audio def ui_generate_content(niche, tone, goal): return ( "\n".join(generate_hooks(niche, tone)), "\n".join(generate_captions(niche, tone)), "\n".join(generate_content_ideas(niche, goal)), "\n".join(generate_short_scripts(niche, tone)) ) def ui_build_pack(niche, style, bpm, tone, goal): return build_creator_pack(niche, style, bpm, tone, goal) # -------------------------------------------------- # EMBEDDED BRUSHED GUNMETAL BACKGROUND (BASE64) # -------------------------------------------------- gunmetal_bg = """ """ # -------------------------------------------------- # APP UI # -------------------------------------------------- with gr.Blocks(title="304 Reaper AI Content + Beat Generator") as demo: gr.HTML(gunmetal_bg) gr.HTML("