import gradio as gr import subprocess import tempfile import os import shutil def merge_audio(audio1_path, audio2_path): with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as out: out_path = out.name cmd = [ "ffmpeg", "-y", "-i", audio1_path, "-i", audio2_path, "-filter_complex", "[0:0][1:0]concat=n=2:v=0:a=1[out]", "-map", "[out]", out_path ] subprocess.run(cmd, check=True) # Copy to a new path so Gradio can serve it final_path = "/tmp/merged_output.mp3" shutil.copy(out_path, final_path) os.unlink(out_path) return final_path iface = gr.Interface( fn=merge_audio, inputs=[gr.Audio(type="filepath"), gr.Audio(type="filepath")], outputs=gr.File(label="Merged Audio"), title="MP3 Audio Merger", description="Upload two mp3 files and get a single merged mp3 file" ) if __name__ == "__main__": iface.launch()