Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,22 @@ from pathlib import Path
|
|
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
|
@@ -194,17 +209,24 @@ effect_options = [
|
|
194 |
]
|
195 |
|
196 |
interface = gr.Interface(
|
197 |
-
fn=
|
198 |
inputs=[
|
199 |
-
gr.
|
200 |
gr.CheckboxGroup(choices=effect_options, label="Apply Effects in Order"),
|
201 |
gr.Checkbox(label="Isolate Vocals After Effects"),
|
202 |
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0] if preset_names else None),
|
203 |
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
204 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
outputs=[
|
206 |
gr.Audio(label="Processed Audio", type="filepath"),
|
207 |
gr.Image(label="Waveform Preview")
|
|
|
208 |
],
|
209 |
title="AI Audio Studio - Pro Edition",
|
210 |
description="Apply multiple effects, isolate vocals, and export polished tracks — all powered by AI!",
|
|
|
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
|
|
|
209 |
]
|
210 |
|
211 |
interface = gr.Interface(
|
212 |
+
fn=batch_process_audio,
|
213 |
inputs=[
|
214 |
+
gr.File(label="Upload Multiple Audio Files", file_count="multiple"),
|
215 |
gr.CheckboxGroup(choices=effect_options, label="Apply Effects in Order"),
|
216 |
gr.Checkbox(label="Isolate Vocals After Effects"),
|
217 |
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0] if preset_names else None),
|
218 |
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
219 |
],
|
220 |
+
outputs=gr.File(label="Download ZIP of All Processed Files"),
|
221 |
+
title="AI Audio Studio - Batch Edition",
|
222 |
+
description="Upload multiple files, apply effects in bulk, and download all results in a single ZIP.",
|
223 |
+
allow_flagging="never"
|
224 |
+
)
|
225 |
+
],
|
226 |
outputs=[
|
227 |
gr.Audio(label="Processed Audio", type="filepath"),
|
228 |
gr.Image(label="Waveform Preview")
|
229 |
+
gr.File(label="Download All Processed Files (ZIP)")
|
230 |
],
|
231 |
title="AI Audio Studio - Pro Edition",
|
232 |
description="Apply multiple effects, isolate vocals, and export polished tracks — all powered by AI!",
|