Ryouko65777 commited on
Commit
1842b3d
·
verified ·
1 Parent(s): d66601e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from audio_separator.separator import Separator
4
+
5
+ # Function for separating the audio
6
+ def separate_audio(audio):
7
+ if audio is None:
8
+ return None, None
9
+
10
+ # Step 1: Get the audio file path
11
+ input_file = audio
12
+
13
+ # Step 2: Set up output directory and models for separation
14
+ output_dir = "./output"
15
+ os.makedirs(output_dir, exist_ok=True)
16
+
17
+ separator = Separator(output_dir=output_dir)
18
+
19
+ # Define output paths
20
+ vocals_path = os.path.join(output_dir, 'Vocals.wav')
21
+ instrumental_path = os.path.join(output_dir, 'Instrumental.wav')
22
+
23
+ with gr.Progress() as progress:
24
+ # Load model
25
+ progress(0, "Loading model...")
26
+ separator.load_model(model_filename='model_bs_roformer_ep_317_sdr_12.9755.ckpt')
27
+ progress(20, "Model loaded. Starting separation...")
28
+
29
+ # Step 3: Splitting track into Vocal and Instrumental
30
+ voc_inst = separator.separate(input_file)
31
+
32
+ # Check if separation was successful
33
+ if len(voc_inst) != 2:
34
+ return None, None
35
+
36
+ # Save the separated files
37
+ os.rename(voc_inst[0], instrumental_path)
38
+ os.rename(voc_inst[1], vocals_path)
39
+
40
+ progress(100, "Separation complete!")
41
+
42
+ # Return paths to the processed files
43
+ return instrumental_path, vocals_path
44
+
45
+ # Define the Gradio Interface
46
+ with gr.Blocks(theme="NoCrypt/miku@1.2.2") as demo:
47
+ gr.Markdown("# Audio Separator Gradio Demo")
48
+
49
+ with gr.Row():
50
+ with gr.Column():
51
+ link_input = gr.Audio(label="Upload Audio File", type="filepath")
52
+ separate_button = gr.Button("Separate Audio")
53
+
54
+ with gr.Column():
55
+ instrumental_output = gr.Audio(label="Instrumental Output", type="filepath")
56
+ vocals_output = gr.Audio(label="Vocals Output", type="filepath")
57
+
58
+ # Define button functionality
59
+ separate_button.click(
60
+ separate_audio,
61
+ inputs=[link_input],
62
+ outputs=[
63
+ instrumental_output,
64
+ vocals_output,
65
+ ]
66
+ )
67
+
68
+ # Launch the Gradio app
69
+ demo.launch(debug=True, share=True)