Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,11 +7,9 @@ import gradio as gr
|
|
| 7 |
# --------------------------
|
| 8 |
# TensorFlow config + Spleeter install
|
| 9 |
# --------------------------
|
| 10 |
-
# Enable eager execution & NumPy behavior for TF tensors
|
| 11 |
tf.config.run_functions_eagerly(True)
|
| 12 |
np_config.enable_numpy_behavior()
|
| 13 |
|
| 14 |
-
# Install Spleeter manually if missing
|
| 15 |
if not os.path.exists("/home/user/.spleeter_installed"):
|
| 16 |
import install_spleeter
|
| 17 |
open("/home/user/.spleeter_installed", "w").close()
|
|
@@ -20,31 +18,24 @@ if not os.path.exists("/home/user/.spleeter_installed"):
|
|
| 20 |
# Import Spleeter
|
| 21 |
# --------------------------
|
| 22 |
from spleeter.separator import Separator
|
| 23 |
-
from spleeter.audio.adapter import AudioAdapter
|
| 24 |
|
| 25 |
# --------------------------
|
| 26 |
# Initialize separator
|
| 27 |
# --------------------------
|
| 28 |
separator = Separator("spleeter:2stems", multiprocess=False)
|
| 29 |
-
audio_loader = AudioAdapter.default()
|
| 30 |
|
| 31 |
# --------------------------
|
| 32 |
# Separation function
|
| 33 |
# --------------------------
|
| 34 |
def separate_audio(audio_file):
|
| 35 |
-
#
|
| 36 |
-
waveform, sample_rate = audio_loader.load(audio_file, sample_rate=44100)
|
| 37 |
-
|
| 38 |
-
# Separate stems (vocals & accompaniment)
|
| 39 |
-
pred = separator.separate(waveform)
|
| 40 |
-
|
| 41 |
-
# Save results to temporary folder
|
| 42 |
tmp = tempfile.mkdtemp()
|
| 43 |
-
vocals_path = os.path.join(tmp, "vocals.wav")
|
| 44 |
-
instr_path = os.path.join(tmp, "accompaniment.wav")
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
return vocals_path, instr_path, "Done!"
|
| 50 |
|
|
@@ -58,4 +49,4 @@ iface = gr.Interface(
|
|
| 58 |
title="Spleeter Vocal/Instrumental Separator"
|
| 59 |
)
|
| 60 |
|
| 61 |
-
iface.launch()
|
|
|
|
| 7 |
# --------------------------
|
| 8 |
# TensorFlow config + Spleeter install
|
| 9 |
# --------------------------
|
|
|
|
| 10 |
tf.config.run_functions_eagerly(True)
|
| 11 |
np_config.enable_numpy_behavior()
|
| 12 |
|
|
|
|
| 13 |
if not os.path.exists("/home/user/.spleeter_installed"):
|
| 14 |
import install_spleeter
|
| 15 |
open("/home/user/.spleeter_installed", "w").close()
|
|
|
|
| 18 |
# Import Spleeter
|
| 19 |
# --------------------------
|
| 20 |
from spleeter.separator import Separator
|
|
|
|
| 21 |
|
| 22 |
# --------------------------
|
| 23 |
# Initialize separator
|
| 24 |
# --------------------------
|
| 25 |
separator = Separator("spleeter:2stems", multiprocess=False)
|
|
|
|
| 26 |
|
| 27 |
# --------------------------
|
| 28 |
# Separation function
|
| 29 |
# --------------------------
|
| 30 |
def separate_audio(audio_file):
|
| 31 |
+
# Create temporary folder for outputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
tmp = tempfile.mkdtemp()
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
# Separate directly to file (handles TensorFlow tensors internally)
|
| 35 |
+
separator.separate_to_file(audio_file, tmp, codec="wav")
|
| 36 |
+
|
| 37 |
+
vocals_path = os.path.join(tmp, os.path.splitext(os.path.basename(audio_file))[0], "vocals.wav")
|
| 38 |
+
instr_path = os.path.join(tmp, os.path.splitext(os.path.basename(audio_file))[0], "accompaniment.wav")
|
| 39 |
|
| 40 |
return vocals_path, instr_path, "Done!"
|
| 41 |
|
|
|
|
| 49 |
title="Spleeter Vocal/Instrumental Separator"
|
| 50 |
)
|
| 51 |
|
| 52 |
+
iface.launch(share=True) # Added public link
|