BUBOUTLW commited on
Commit
2a09745
·
verified ·
1 Parent(s): a9f24ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -67
app.py CHANGED
@@ -20,7 +20,6 @@ def generate_cpu_safe_beat(style, bpm):
20
  t = np.linspace(0, seconds, int(sr * seconds))
21
  beat = np.zeros_like(t)
22
 
23
- # --- Style presets ---
24
  if style == "Country Rap":
25
  kick_freq, snare_freq, hat_freq = 55, 180, 8000
26
  elif style == "Trap":
@@ -29,7 +28,7 @@ def generate_cpu_safe_beat(style, bpm):
29
  kick_freq, snare_freq, hat_freq = 60, 150, 6000
30
  elif style == "Drill":
31
  kick_freq, snare_freq, hat_freq = 40, 160, 9000
32
- else: # BoomBap
33
  kick_freq, snare_freq, hat_freq = 70, 190, 7000
34
 
35
  beat_interval = 60.0 / float(bpm)
@@ -37,80 +36,56 @@ def generate_cpu_safe_beat(style, bpm):
37
 
38
  for i in range(hits):
39
  pos = int(i * beat_interval * sr)
40
-
41
- # Kick
42
  if pos + 2000 <= len(beat):
43
  beat[pos:pos+2000] += np.sin(2 * np.pi * kick_freq * t[:2000]) * 0.9
44
-
45
- # Snare on alternate beats
46
  if i % 2 == 1 and pos + 2000 <= len(beat):
47
  beat[pos:pos+2000] += np.sin(2 * np.pi * snare_freq * t[:2000]) * 0.5
48
-
49
- # Hats
50
  if pos + 500 <= len(beat):
51
  beat[pos:pos+500] += np.random.randn(500) * 0.1
52
 
53
- # Normalize safely
54
- max_val = float(np.max(np.abs(beat))) if np.max(np.abs(beat)) != 0 else 1.0
55
  beat = beat / max_val
56
-
57
- # Convert to 16-bit PCM
58
  beat_int16 = (beat * 32767).astype(np.int16)
59
 
60
- # File path
61
  filename = f"beat_{uuid.uuid4().hex}.wav"
62
  filepath = f"/tmp/{filename}"
63
 
64
- # Write WAV (no scipy)
65
  with wave.open(filepath, "w") as wf:
66
  wf.setnchannels(1)
67
- wf.setsampwidth(2) # 16-bit
68
  wf.setframerate(sr)
69
  wf.writeframes(beat_int16.tobytes())
70
 
71
  return filepath
72
 
73
 
74
- # -------------------------------
75
- # BEAT GENERATOR CALLBACK
76
- # -------------------------------
77
  def ui_generate_beats(style, bpm, loops):
78
  audio = None
79
- loops = int(loops)
80
- for _ in range(loops):
81
  audio = generate_cpu_safe_beat(style, bpm)
82
  return audio
83
 
84
 
85
- # -------------------------------
86
- # CONTENT GENERATOR CALLBACK
87
- # -------------------------------
88
  def ui_generate_content(niche, tone, goal):
89
- hooks = generate_hooks(niche, tone)
90
- captions = generate_captions(niche, tone)
91
- ideas = generate_content_ideas(niche, goal)
92
- scripts = generate_short_scripts(niche, tone)
93
-
94
  return (
95
- "\n".join(hooks),
96
- "\n".join(captions),
97
- "\n".join(ideas),
98
- "\n".join(scripts)
99
  )
100
 
101
 
102
- # -------------------------------
103
- # PACK BUILDER CALLBACK
104
- # -------------------------------
105
  def ui_build_pack(niche, style, bpm, tone, goal):
106
- zip_path = build_creator_pack(niche, style, bpm, tone, goal)
107
- return zip_path
108
 
109
 
110
  # --------------------------------------------------
111
- # CUSTOM CSS
112
  # --------------------------------------------------
113
  custom_css = """
 
 
114
  body {
115
  background-color: #050505;
116
  }
@@ -124,19 +99,14 @@ body {
124
  margin-bottom: 10px;
125
  }
126
 
127
- .gradio-container {
128
- border-radius: 12px;
129
- background-color: #111111;
130
- }
131
-
132
  button {
133
  background: linear-gradient(90deg, #ff3c00, #b10000);
134
  color: #ffffff !important;
135
  font-weight: bold !important;
136
  border-radius: 10px !important;
137
- border: none !important;
138
  font-size: 18px !important;
139
  padding: 10px 16px !important;
 
140
  box-shadow: 0px 0px 12px rgba(255,60,0,0.7);
141
  transition: 0.15s;
142
  }
@@ -156,30 +126,33 @@ input, textarea, select {
156
  label {
157
  color: #f1f1f1 !important;
158
  }
 
 
159
  """
160
 
161
 
162
  # --------------------------------------------------
163
  # APP UI
164
  # --------------------------------------------------
165
- with gr.Blocks(title="304 Reaper AI Content + Beat Generator", css=custom_css) as demo:
 
 
 
 
166
  gr.HTML("<h1 id='main-title'>🔥 304 REAPER — AI CONTENT & BEAT GENERATOR</h1>")
167
 
168
  # ---------------------------
169
  # BEAT GENERATOR
170
  # ---------------------------
171
  with gr.Tab("🎵 Beat Forge"):
172
- gr.Markdown(
173
- "### Hand-Crafted Reaper Beats (CPU Safe)\n"
174
- "Pick your style, set the BPM, and let the Reaper cook."
175
- )
176
 
177
  style = gr.Dropdown(
178
  ["Country Rap", "Trap", "Dark Outlaw", "Drill", "BoomBap"],
179
  label="Beat Style"
180
  )
181
  bpm = gr.Slider(60, 180, value=120, label="BPM")
182
- loops = gr.Slider(1, 5, value=1, step=1, label="How Many Beats (returns last one)")
183
 
184
  generate_btn = gr.Button("⚡ Generate Beat")
185
  audio_out = gr.Audio(label="Generated Beat", type="filepath")
@@ -194,23 +167,20 @@ with gr.Blocks(title="304 Reaper AI Content + Beat Generator", css=custom_css) a
194
  # CONTENT GENERATOR
195
  # ---------------------------
196
  with gr.Tab("🧠 Content Lab"):
197
- gr.Markdown(
198
- "### Hooks, Captions, Ideas & Scripts\n"
199
- "Built for creators who need tools, not excuses."
200
- )
201
 
202
- niche = gr.Textbox(label="Niche (ex: Musicians, Real Estate, Fitness)")
203
- tone = gr.Textbox(label="Tone (ex: Aggressive, Funny, Motivational)")
204
- goal = gr.Textbox(label="Goal (ex: Viral, Sales, Engagement)")
205
 
206
- gen_content_btn = gr.Button("⚡ Generate Content Pack")
207
 
208
  hooks_out = gr.Textbox(label="Hooks")
209
  captions_out = gr.Textbox(label="Captions")
210
- ideas_out = gr.Textbox(label="Video Ideas")
211
- scripts_out = gr.Textbox(label="Short Scripts")
212
 
213
- gen_content_btn.click(
214
  ui_generate_content,
215
  inputs=[niche, tone, goal],
216
  outputs=[hooks_out, captions_out, ideas_out, scripts_out]
@@ -220,10 +190,7 @@ with gr.Blocks(title="304 Reaper AI Content + Beat Generator", css=custom_css) a
220
  # PACK BUILDER
221
  # ---------------------------
222
  with gr.Tab("📦 Full Creator Pack"):
223
- gr.Markdown(
224
- "### One-Click Creator ZIP\n"
225
- "Beat + content bundle for the niche you choose."
226
- )
227
 
228
  niche2 = gr.Textbox(label="Niche")
229
  style2 = gr.Dropdown(
@@ -234,8 +201,8 @@ with gr.Blocks(title="304 Reaper AI Content + Beat Generator", css=custom_css) a
234
  tone2 = gr.Textbox(label="Tone")
235
  goal2 = gr.Textbox(label="Goal")
236
 
237
- build_btn = gr.Button("⚡ Build Creator Pack (ZIP)")
238
- zip_out = gr.File(label="Download Pack")
239
 
240
  build_btn.click(
241
  ui_build_pack,
@@ -243,4 +210,5 @@ with gr.Blocks(title="304 Reaper AI Content + Beat Generator", css=custom_css) a
243
  outputs=zip_out
244
  )
245
 
 
246
  demo.launch()
 
20
  t = np.linspace(0, seconds, int(sr * seconds))
21
  beat = np.zeros_like(t)
22
 
 
23
  if style == "Country Rap":
24
  kick_freq, snare_freq, hat_freq = 55, 180, 8000
25
  elif style == "Trap":
 
28
  kick_freq, snare_freq, hat_freq = 60, 150, 6000
29
  elif style == "Drill":
30
  kick_freq, snare_freq, hat_freq = 40, 160, 9000
31
+ else:
32
  kick_freq, snare_freq, hat_freq = 70, 190, 7000
33
 
34
  beat_interval = 60.0 / float(bpm)
 
36
 
37
  for i in range(hits):
38
  pos = int(i * beat_interval * sr)
 
 
39
  if pos + 2000 <= len(beat):
40
  beat[pos:pos+2000] += np.sin(2 * np.pi * kick_freq * t[:2000]) * 0.9
 
 
41
  if i % 2 == 1 and pos + 2000 <= len(beat):
42
  beat[pos:pos+2000] += np.sin(2 * np.pi * snare_freq * t[:2000]) * 0.5
 
 
43
  if pos + 500 <= len(beat):
44
  beat[pos:pos+500] += np.random.randn(500) * 0.1
45
 
46
+ max_val = float(np.max(np.abs(beat))) or 1.0
 
47
  beat = beat / max_val
 
 
48
  beat_int16 = (beat * 32767).astype(np.int16)
49
 
 
50
  filename = f"beat_{uuid.uuid4().hex}.wav"
51
  filepath = f"/tmp/{filename}"
52
 
 
53
  with wave.open(filepath, "w") as wf:
54
  wf.setnchannels(1)
55
+ wf.setsampwidth(2)
56
  wf.setframerate(sr)
57
  wf.writeframes(beat_int16.tobytes())
58
 
59
  return filepath
60
 
61
 
 
 
 
62
  def ui_generate_beats(style, bpm, loops):
63
  audio = None
64
+ for _ in range(int(loops)):
 
65
  audio = generate_cpu_safe_beat(style, bpm)
66
  return audio
67
 
68
 
 
 
 
69
  def ui_generate_content(niche, tone, goal):
 
 
 
 
 
70
  return (
71
+ "\n".join(generate_hooks(niche, tone)),
72
+ "\n".join(generate_captions(niche, tone)),
73
+ "\n".join(generate_content_ideas(niche, goal)),
74
+ "\n".join(generate_short_scripts(niche, tone))
75
  )
76
 
77
 
 
 
 
78
  def ui_build_pack(niche, style, bpm, tone, goal):
79
+ return build_creator_pack(niche, style, bpm, tone, goal)
80
+
81
 
82
 
83
  # --------------------------------------------------
84
+ # CUSTOM CSS (LOADED THE OLD-SCHOOL WAY)
85
  # --------------------------------------------------
86
  custom_css = """
87
+ <style>
88
+
89
  body {
90
  background-color: #050505;
91
  }
 
99
  margin-bottom: 10px;
100
  }
101
 
 
 
 
 
 
102
  button {
103
  background: linear-gradient(90deg, #ff3c00, #b10000);
104
  color: #ffffff !important;
105
  font-weight: bold !important;
106
  border-radius: 10px !important;
 
107
  font-size: 18px !important;
108
  padding: 10px 16px !important;
109
+ border: none !important;
110
  box-shadow: 0px 0px 12px rgba(255,60,0,0.7);
111
  transition: 0.15s;
112
  }
 
126
  label {
127
  color: #f1f1f1 !important;
128
  }
129
+
130
+ </style>
131
  """
132
 
133
 
134
  # --------------------------------------------------
135
  # APP UI
136
  # --------------------------------------------------
137
+ with gr.Blocks(title="304 Reaper AI Content + Beat Generator") as demo:
138
+
139
+ # Load custom CSS
140
+ gr.HTML(custom_css)
141
+
142
  gr.HTML("<h1 id='main-title'>🔥 304 REAPER — AI CONTENT & BEAT GENERATOR</h1>")
143
 
144
  # ---------------------------
145
  # BEAT GENERATOR
146
  # ---------------------------
147
  with gr.Tab("🎵 Beat Forge"):
148
+ gr.Markdown("### Hand-Crafted Reaper Beats (CPU Safe)")
 
 
 
149
 
150
  style = gr.Dropdown(
151
  ["Country Rap", "Trap", "Dark Outlaw", "Drill", "BoomBap"],
152
  label="Beat Style"
153
  )
154
  bpm = gr.Slider(60, 180, value=120, label="BPM")
155
+ loops = gr.Slider(1, 5, value=1, label="How Many Beats")
156
 
157
  generate_btn = gr.Button("⚡ Generate Beat")
158
  audio_out = gr.Audio(label="Generated Beat", type="filepath")
 
167
  # CONTENT GENERATOR
168
  # ---------------------------
169
  with gr.Tab("🧠 Content Lab"):
170
+ gr.Markdown("### Hooks, Captions, Ideas & Scripts")
 
 
 
171
 
172
+ niche = gr.Textbox(label="Niche")
173
+ tone = gr.Textbox(label="Tone")
174
+ goal = gr.Textbox(label="Goal")
175
 
176
+ gen_btn = gr.Button("⚡ Generate Content")
177
 
178
  hooks_out = gr.Textbox(label="Hooks")
179
  captions_out = gr.Textbox(label="Captions")
180
+ ideas_out = gr.Textbox(label="Ideas")
181
+ scripts_out = gr.Textbox(label="Scripts")
182
 
183
+ gen_btn.click(
184
  ui_generate_content,
185
  inputs=[niche, tone, goal],
186
  outputs=[hooks_out, captions_out, ideas_out, scripts_out]
 
190
  # PACK BUILDER
191
  # ---------------------------
192
  with gr.Tab("📦 Full Creator Pack"):
193
+ gr.Markdown("### Build a Full Creator ZIP Pack")
 
 
 
194
 
195
  niche2 = gr.Textbox(label="Niche")
196
  style2 = gr.Dropdown(
 
201
  tone2 = gr.Textbox(label="Tone")
202
  goal2 = gr.Textbox(label="Goal")
203
 
204
+ build_btn = gr.Button("⚡ Build ZIP Pack")
205
+ zip_out = gr.File(label="Download")
206
 
207
  build_btn.click(
208
  ui_build_pack,
 
210
  outputs=zip_out
211
  )
212
 
213
+
214
  demo.launch()