Vibes-remix / app.py
Curlyblaze's picture
Update app.py
b3e5cfc verified
import gradio as gr
import subprocess
import os
def def process_audio(input_file, speed, reverb):
if input_file is None:
return None
# Use an absolute path to avoid "File Not Found" errors
output_path = os.path.abspath("remix.mp3")
# Formula for professional atmosphere
filter_complex = (
f"asetrate=44100*{speed},aresample=44100,"
f"freeverb=roomsize=0.85:damp=0.5:dry=1:wet={reverb}"
)
command = [
'ffmpeg', '-y', '-i', input_file,
'-filter_complex', filter_complex,
output_path # Save to absolute path
]
# Execute the command and wait for it to finish completely
result = subprocess.run(command, capture_output=True, text=True)
# Debug: Check if FFmpeg actually created the file
if os.path.exists(output_path):
return output_path
else:
print(f"FFmpeg Error: {result.stderr}")
return None(input_file, speed, reverb):
if input_file is None:
return None
output_file = "remix.mp3"
# High-quality Ambient Filter Chain
# speed (0.7-1.0), reverb (0.0-1.0)
filter_complex = (
f"asetrate=44100*{speed},aresample=44100,"
f"freeverb=roomsize=0.85:damp=0.5:dry=1:wet={reverb}"
)
command = [
'ffmpeg', '-y', '-i', input_file,
'-filter_complex', filter_complex,
output_file
]
subprocess.run(command)
return output_file
# Create the Vibe Interface
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="indigo")) as demo:
gr.Markdown("# ๐ŸŒŒ Ambient Slowed + Reverb")
gr.Markdown("Upload a song to transform it into an atmospheric masterpiece.")
with gr.Row():
audio_in = gr.Audio(type="filepath", label="Upload Song")
audio_out = gr.Audio(label="Download Remix")
with gr.Row():
speed_slider = gr.Slider(0.7, 1.0, value=0.88, label="Vibe (Speed/Pitch)")
reverb_slider = gr.Slider(0.0, 0.8, value=0.4, label="Atmosphere (Reverb)")
btn = gr.Button("Generate Remix", variant="primary")
btn.click(process_audio, [audio_in, speed_slider, reverb_slider], audio_out)
demo.launch()