Doubleupai commited on
Commit
1fcc9eb
·
verified ·
1 Parent(s): 500f0a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from spleeter.separator import Separator
3
+ from spleeter.audio.adapter import get_default_audio_adapter
4
+
5
+ # Initialize the separator with the 2stems model (vocals and accompaniment)
6
+ separator = Separator('spleeter:2stems')
7
+ audio_adapter = get_default_audio_adapter()
8
+
9
+ def remove_vocals(input_audio):
10
+ # Load the audio file
11
+ waveform, sample_rate = audio_adapter.load(input_audio)
12
+
13
+ # Separate the audio into vocals and accompaniment
14
+ prediction = separator.separate(waveform)
15
+
16
+ # Extract the accompaniment (non-vocal part)
17
+ accompaniment = prediction['accompaniment']
18
+
19
+ # Save the accompaniment to a temporary file
20
+ output_audio = "accompaniment.wav"
21
+ audio_adapter.save(output_audio, accompaniment, sample_rate)
22
+
23
+ return output_audio
24
+
25
+ # Create the Gradio interface
26
+ iface = gr.Interface(
27
+ fn=remove_vocals,
28
+ inputs="audio",
29
+ outputs="audio",
30
+ title="AI Vocal Remover",
31
+ description="Upload an audio file and the AI will remove the vocals, leaving the accompaniment.",
32
+ examples=[["example.mp3"]]
33
+ )
34
+
35
+ # Launch the interface
36
+ iface.launch()