Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,22 +13,7 @@ from pathlib import Path
|
|
13 |
import matplotlib.pyplot as plt
|
14 |
from io import BytesIO
|
15 |
from PIL import Image
|
16 |
-
import zipfile
|
17 |
-
|
18 |
-
def batch_process_audio(files, selected_effects, isolate_vocals, preset_name, export_format):
|
19 |
-
output_dir = tempfile.mkdtemp()
|
20 |
-
results = []
|
21 |
-
|
22 |
-
for file in files:
|
23 |
-
processed_path = process_audio(file.name, selected_effects, isolate_vocals, preset_name, export_format)
|
24 |
-
results.append(processed_path[0]) # Take just the file path
|
25 |
|
26 |
-
zip_path = os.path.join(output_dir, "batch_output.zip")
|
27 |
-
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
28 |
-
for i, res in enumerate(results):
|
29 |
-
zipf.write(res, f"processed_{i}.{export_format.lower()}")
|
30 |
-
|
31 |
-
return zip_path
|
32 |
# === Helper Functions ===
|
33 |
def audiosegment_to_array(audio):
|
34 |
return np.array(audio.get_array_of_samples()), audio.frame_rate
|
@@ -195,7 +180,25 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
195 |
final_audio.export(output_path, format=export_format.lower())
|
196 |
return output_path, show_waveform(output_path)
|
197 |
|
198 |
-
# ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
effect_options = [
|
200 |
"Noise Reduction",
|
201 |
"Compress Dynamic Range",
|
@@ -208,19 +211,47 @@ effect_options = [
|
|
208 |
"Normalize"
|
209 |
]
|
210 |
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
gr.
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
)
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
import matplotlib.pyplot as plt
|
14 |
from io import BytesIO
|
15 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# === Helper Functions ===
|
18 |
def audiosegment_to_array(audio):
|
19 |
return np.array(audio.get_array_of_samples()), audio.frame_rate
|
|
|
180 |
final_audio.export(output_path, format=export_format.lower())
|
181 |
return output_path, show_waveform(output_path)
|
182 |
|
183 |
+
# === Batch Processing Function ===
|
184 |
+
import zipfile
|
185 |
+
|
186 |
+
def batch_process_audio(files, selected_effects, isolate_vocals, preset_name, export_format):
|
187 |
+
output_dir = tempfile.mkdtemp()
|
188 |
+
results = []
|
189 |
+
|
190 |
+
for file in files:
|
191 |
+
processed_path = process_audio(file.name, selected_effects, isolate_vocals, preset_name, export_format)
|
192 |
+
results.append(processed_path[0]) # Take just the file path
|
193 |
+
|
194 |
+
zip_path = os.path.join(output_dir, "batch_output.zip")
|
195 |
+
with zipfile.ZipFile(zip_path, 'w') as zipf:
|
196 |
+
for i, res in enumerate(results):
|
197 |
+
zipf.write(res, f"processed_{i}.{export_format.lower()}")
|
198 |
+
|
199 |
+
return zip_path
|
200 |
+
|
201 |
+
# === Effect List ===
|
202 |
effect_options = [
|
203 |
"Noise Reduction",
|
204 |
"Compress Dynamic Range",
|
|
|
211 |
"Normalize"
|
212 |
]
|
213 |
|
214 |
+
# === Multi-Tab UI ===
|
215 |
+
with gr.Blocks(title="AI Audio Studio") as demo:
|
216 |
+
gr.Markdown("## 🎧 AI Audio Studio\nUpload, edit, export — all powered by AI")
|
217 |
+
|
218 |
+
# ----- Batch Processing Tab -----
|
219 |
+
with gr.Tab("🔊 Batch Processing"):
|
220 |
+
gr.Interface(
|
221 |
+
fn=batch_process_audio,
|
222 |
+
inputs=[
|
223 |
+
gr.File(label="Upload Multiple Audio Files", file_count="multiple"),
|
224 |
+
gr.CheckboxGroup(choices=effect_options, label="Apply Effects in Order"),
|
225 |
+
gr.Checkbox(label="Isolate Vocals After Effects"),
|
226 |
+
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0] if preset_names else None),
|
227 |
+
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
228 |
+
],
|
229 |
+
outputs=gr.File(label="Download ZIP of All Processed Files"),
|
230 |
+
title="Batch Audio Processor",
|
231 |
+
description="Upload multiple files, apply effects in bulk, and download all results in a single ZIP.",
|
232 |
+
allow_flagging="never",
|
233 |
+
submit_btn="Process All Files",
|
234 |
+
clear_btn=False
|
235 |
+
)
|
236 |
+
|
237 |
+
# ----- Single File Studio Tab -----
|
238 |
+
with gr.Tab("🎵 Single File Studio"):
|
239 |
+
gr.Interface(
|
240 |
+
fn=process_audio,
|
241 |
+
inputs=[
|
242 |
+
gr.Audio(label="Upload Audio", type="filepath"),
|
243 |
+
gr.CheckboxGroup(choices=effect_options, label="Apply Effects in Order"),
|
244 |
+
gr.Checkbox(label="Isolate Vocals After Effects"),
|
245 |
+
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0] if preset_names else None),
|
246 |
+
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
247 |
+
],
|
248 |
+
outputs=[
|
249 |
+
gr.Audio(label="Processed Audio", type="filepath"),
|
250 |
+
gr.Image(label="Waveform Preview")
|
251 |
+
],
|
252 |
+
title="Edit One File at a Time",
|
253 |
+
description="Apply effects, preview waveform, and export as MP3 or WAV",
|
254 |
+
allow_flagging="never"
|
255 |
+
)
|
256 |
+
|
257 |
+
demo.launch()
|