Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import zipfile
|
|
| 7 |
import tempfile
|
| 8 |
import soundfile as sf
|
| 9 |
import traceback
|
| 10 |
-
import subprocess
|
| 11 |
from typing import Tuple, List
|
| 12 |
|
| 13 |
# --- Configuration ---
|
|
@@ -296,4 +296,100 @@ def create_market_ready_pack(
|
|
| 296 |
with open(license_filepath, 'w') as f:
|
| 297 |
f.write(license_content.strip())
|
| 298 |
|
| 299 |
-
# Create the final ZIP file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import tempfile
|
| 8 |
import soundfile as sf
|
| 9 |
import traceback
|
| 10 |
+
import subprocess
|
| 11 |
from typing import Tuple, List
|
| 12 |
|
| 13 |
# --- Configuration ---
|
|
|
|
| 296 |
with open(license_filepath, 'w') as f:
|
| 297 |
f.write(license_content.strip())
|
| 298 |
|
| 299 |
+
# Create the final ZIP file
|
| 300 |
+
zip_filename = os.path.join(temp_dir, f"{OUTPUT_FOLDER_NAME}_{key_mode_name}.zip")
|
| 301 |
+
|
| 302 |
+
with zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 303 |
+
for root, dirs, files in os.walk(output_root):
|
| 304 |
+
for file in files:
|
| 305 |
+
full_path = os.path.join(root, file)
|
| 306 |
+
relative_path = os.path.relpath(full_path, temp_dir)
|
| 307 |
+
zf.write(full_path, relative_path)
|
| 308 |
+
|
| 309 |
+
progress(1.0, desc="Packaging Complete!")
|
| 310 |
+
|
| 311 |
+
shutil.rmtree(output_root)
|
| 312 |
+
|
| 313 |
+
return zip_filename, f"✅ Success! Your market-ready '{os.path.basename(zip_filename)}' is ready. Key/BPM: {key_mode_name}. Stems Processed: {', '.join(display_stems)}. Download below."
|
| 314 |
+
|
| 315 |
+
except Exception as e:
|
| 316 |
+
error_message = f"Critical Error: {e}"
|
| 317 |
+
print(f"Full Traceback: {traceback.format_exc()}")
|
| 318 |
+
|
| 319 |
+
if temp_dir and os.path.exists(temp_dir):
|
| 320 |
+
shutil.rmtree(temp_dir)
|
| 321 |
+
gr.Warning("Cleaned up temporary files after failure.")
|
| 322 |
+
|
| 323 |
+
return None, f"❌ Processing failed. {error_message}. If Spleeter failed, ensure it is installed correctly."
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
# --- Gradio Interface Definition ---
|
| 327 |
+
|
| 328 |
+
with gr.Blocks(title="Market-Ready Loop Pack Generator") as demo:
|
| 329 |
+
gr.Markdown(
|
| 330 |
+
"""
|
| 331 |
+
# 🎧 Professional Loop Pack Automation Tool
|
| 332 |
+
|
| 333 |
+
Upload a full music track, select your stem separation model, and generate a
|
| 334 |
+
complete, royalty-free sample pack including time-aligned loops and transient-detected one-shots.
|
| 335 |
+
"""
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
with gr.Row():
|
| 339 |
+
audio_input = gr.Audio(
|
| 340 |
+
type="filepath",
|
| 341 |
+
sources=["upload"],
|
| 342 |
+
label="1. Upload Full Mix Audio File (WAV/MP3/FLAC)",
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
stem_model_input = gr.Dropdown(
|
| 346 |
+
label="2. Select Stem Separation Model",
|
| 347 |
+
choices=list(STEM_MODELS.keys()),
|
| 348 |
+
value='4-Stems (Drums, Bass, Vocals, Other)',
|
| 349 |
+
allow_custom_value=False,
|
| 350 |
+
info="Choose the number and type of stems to split the audio into (requires Spleeter installation)."
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
with gr.Row():
|
| 354 |
+
sensitivity_slider = gr.Slider(
|
| 355 |
+
minimum=1,
|
| 356 |
+
maximum=10,
|
| 357 |
+
step=1,
|
| 358 |
+
value=6,
|
| 359 |
+
label="3. One-Shot Sensitivity (1=Few/Loud, 10=Many/Quiet)",
|
| 360 |
+
info="Controls the transient detection threshold for one-shot slicing."
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
generate_button = gr.Button("🚀 Generate Loop Pack", variant="primary")
|
| 364 |
+
|
| 365 |
+
with gr.Column(scale=1):
|
| 366 |
+
status_output = gr.Textbox(label="Status / Feedback", interactive=False)
|
| 367 |
+
zip_output = gr.File(label="4. Download Final Loop Pack ZIP")
|
| 368 |
+
|
| 369 |
+
# Define the core process action
|
| 370 |
+
generate_button.click(
|
| 371 |
+
fn=create_market_ready_pack,
|
| 372 |
+
inputs=[audio_input, sensitivity_slider, stem_model_input],
|
| 373 |
+
outputs=[zip_output, status_output]
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
gr.Markdown(
|
| 377 |
+
"""
|
| 378 |
+
---
|
| 379 |
+
**Final Pack Structure (Example):**
|
| 380 |
+
- `PRO_LOOP_PACK_128BPM_CMinor.zip`
|
| 381 |
+
- `License.txt`
|
| 382 |
+
- `LOOPS/`
|
| 383 |
+
- `Drums/` (e.g., `128BPM_CMinor_Drums_4Bar_01.wav`)
|
| 384 |
+
- `Bass/`
|
| 385 |
+
- `Vocals/`
|
| 386 |
+
- ... (based on model selected)
|
| 387 |
+
- `ONESHOTS/`
|
| 388 |
+
- `Drums/` (e.g., `128BPM_CMinor_Drums_OneShot_001.wav`)
|
| 389 |
+
- `Bass/`
|
| 390 |
+
- ...
|
| 391 |
+
"""
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
if __name__ == "__main__":
|
| 395 |
+
demo.launch(enable_queue=True)
|