File size: 2,482 Bytes
89bed8d
96559f5
4df38d2
395c133
7de4f1f
 
b256866
 
 
96559f5
 
265c6e4
 
96559f5
 
 
 
 
 
b256866
96559f5
 
 
 
 
265c6e4
96559f5
 
 
 
265c6e4
96559f5
 
 
 
 
265c6e4
96559f5
 
 
265c6e4
96559f5
ae0e14f
265c6e4
96559f5
7de4f1f
395c133
96559f5
 
 
 
 
 
 
b256866
 
 
 
 
 
 
96559f5
 
7de4f1f
 
 
96559f5
265c6e4
96559f5
265c6e4
b256866
96559f5
265c6e4
 
96559f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import os
from audio_separator.separator import Separator

# Initialize the Separator

separator = Separator()

def separate_audio(input_file, output_dir, model_name, output_format):
    # Create output directory if it doesn't exist
    os.makedirs(output_dir, exist_ok=True)


    # Separate the audio
    separator.separate_audio_file(
        input_file,
        output_dir,
        model_name=model_name,
        denoise=True,
        output_format=output_format,
        normalization_threshold=0.9,
        mdx_segment_size=256,
        mdx_overlap=8,
        primary_stem_only=False
    )

    # Rename the output files to match the requested format
    os.rename(os.path.join(output_dir, 'Vocals.wav'), os.path.join(output_dir, '1_main_vocal.wav'))
    os.rename(os.path.join(output_dir, 'Other.wav'), os.path.join(output_dir, '2_backing_vocal.wav'))
    os.rename(os.path.join(output_dir, 'Instrumental.wav'), os.path.join(output_dir, '3_instrumental.wav'))

    return [
        os.path.join(output_dir, '1_main_vocal.wav'),
        os.path.join(output_dir, '2_backing_vocal.wav'),
        os.path.join(output_dir, '3_instrumental.wav')
    ]

def process_audio(audio_file, model_name):
    output_dir = "output"
    return separate_audio(audio_file.name, output_dir, model_name)

# Define the Gradio interface
iface = gr.Blocks(theme='hev832/Applio')

with iface:
    gr.Markdown("# Hex Separator")
    with gr.Row():
        with gr.Column():
            audio_input = gr.Audio(type="filepath", label="Input Audio")
            model_name = gr.Dropdown(
                choices=["UVR-MDX-NET-Inst_HQ_3", "UVR_MDXNET_KARA_2", "UVR-MDX-NET-Inst_HQ_4"],
                label="Model",
                value="UVR-MDX-NET-Inst_HQ_3"
            )
        with gr.Column():
            audio_format = gr.Dropdown(
                choices=["wav", "mp3", "flac"], 
                label="Audio Format",
                value="wav"
            )
            
            submit_btn = gr.Button("Separate Audio")
        with gr.Column():
            with gr.Row():
                vocal_output = gr.Audio(label="Main Vocal")
                backing_vocal_output = gr.Audio(label="Backing Vocal")
            instrumental_output = gr.Audio(label="Instrumental")

    submit_btn.click(
        process_audio,
        inputs=[audio_input, model_name, audio_format],
        outputs=[vocal_output, backing_vocal_output, instrumental_output]
    )

iface.launch()