Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,26 +3,35 @@ import gradio as gr
|
|
| 3 |
from audio_separator.separator import Separator
|
| 4 |
import tempfile
|
| 5 |
import shutil
|
| 6 |
-
import
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def separate_audio(input_file, model_name):
|
| 28 |
if input_file is None:
|
|
@@ -41,31 +50,37 @@ def separate_audio(input_file, model_name):
|
|
| 41 |
output_files = separator.separate(input_file)
|
| 42 |
|
| 43 |
stems = ["Vocals", "Drums", "Bass", "Other", "Guitar", "Piano"]
|
| 44 |
-
|
| 45 |
|
| 46 |
for stem in stems:
|
|
|
|
| 47 |
match = next(
|
| 48 |
(os.path.join(temp_dir, f) for f in output_files if stem in f),
|
| 49 |
None,
|
| 50 |
)
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
delayed_delete
|
| 54 |
-
return tuple(
|
| 55 |
|
| 56 |
except Exception as e:
|
| 57 |
if os.path.exists(temp_dir):
|
| 58 |
shutil.rmtree(temp_dir)
|
| 59 |
raise RuntimeError(f"Separation failed: {e}") from e
|
| 60 |
|
| 61 |
-
|
| 62 |
# ------------------ UI ------------------
|
| 63 |
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
gr.Markdown(
|
| 66 |
"""
|
| 67 |
-
# 🎵 AI 6-Stem Audio Separator
|
| 68 |
-
Split
|
| 69 |
"""
|
| 70 |
)
|
| 71 |
|
|
@@ -83,10 +98,10 @@ with gr.Blocks() as demo:
|
|
| 83 |
label="Select Model",
|
| 84 |
)
|
| 85 |
|
| 86 |
-
separate_btn = gr.Button("🚀 Separate
|
| 87 |
|
| 88 |
with gr.Column(scale=2):
|
| 89 |
-
gr.Markdown("### 🔊
|
| 90 |
|
| 91 |
with gr.Row():
|
| 92 |
output_vocals = gr.Audio(label="🎤 Vocals", type="filepath")
|
|
@@ -113,11 +128,6 @@ with gr.Blocks() as demo:
|
|
| 113 |
],
|
| 114 |
)
|
| 115 |
|
| 116 |
-
gr.Markdown(
|
| 117 |
-
"⚠️ **Note:** Processing may take 1–2 minutes depending on file length and Space hardware."
|
| 118 |
-
)
|
| 119 |
-
|
| 120 |
-
|
| 121 |
if __name__ == "__main__":
|
| 122 |
demo.launch(
|
| 123 |
ssr_mode=False,
|
|
|
|
| 3 |
from audio_separator.separator import Separator
|
| 4 |
import tempfile
|
| 5 |
import shutil
|
| 6 |
+
from ftplib import FTP
|
| 7 |
+
|
| 8 |
+
# --- CONFIGURATION (Update these with your Hostinger details) ---
|
| 9 |
+
FTP_HOST = os.environ.get("FTP_HOST")
|
| 10 |
+
FTP_USER = os.environ.get("FTP_USER")
|
| 11 |
+
FTP_PASS = os.environ.get("FTP_PASS")
|
| 12 |
+
FTP_DIR = "/basically/isolations"
|
| 13 |
+
BASE_URL = "https://thinkstarter.online/basically/isolations"
|
| 14 |
+
# ---------------------------------------------------------------
|
| 15 |
+
|
| 16 |
+
def upload_to_ftp(local_filepath):
|
| 17 |
+
"""Uploads a file to Hostinger via FTP and returns the public URL."""
|
| 18 |
+
filename = os.path.basename(local_filepath)
|
| 19 |
+
try:
|
| 20 |
+
with FTP(FTP_HOST) as ftp:
|
| 21 |
+
ftp.login(user=FTP_USER, passwd=FTP_PASS)
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
ftp.cwd(FTP_DIR)
|
| 25 |
+
except:
|
| 26 |
+
raise RuntimeError(f"Directory {FTP_DIR} not found on server.")
|
| 27 |
+
|
| 28 |
+
with open(local_filepath, 'rb') as f:
|
| 29 |
+
ftp.storbinary(f'STOR {filename}', f)
|
| 30 |
+
|
| 31 |
+
return f"{BASE_URL}/{filename}"
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"FTP Upload Error: {e}")
|
| 34 |
+
return None
|
| 35 |
|
| 36 |
def separate_audio(input_file, model_name):
|
| 37 |
if input_file is None:
|
|
|
|
| 50 |
output_files = separator.separate(input_file)
|
| 51 |
|
| 52 |
stems = ["Vocals", "Drums", "Bass", "Other", "Guitar", "Piano"]
|
| 53 |
+
results_urls = []
|
| 54 |
|
| 55 |
for stem in stems:
|
| 56 |
+
# Find the local file for this stem
|
| 57 |
match = next(
|
| 58 |
(os.path.join(temp_dir, f) for f in output_files if stem in f),
|
| 59 |
None,
|
| 60 |
)
|
| 61 |
+
|
| 62 |
+
if match:
|
| 63 |
+
# Upload to Hostinger and get URL [cite: 1, 2, 3]
|
| 64 |
+
url = upload_to_ftp(match)
|
| 65 |
+
results_urls.append(url)
|
| 66 |
+
else:
|
| 67 |
+
results_urls.append(None)
|
| 68 |
|
| 69 |
+
# Removed delayed_delete call [cite: 4]
|
| 70 |
+
return tuple(results_urls)
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
if os.path.exists(temp_dir):
|
| 74 |
shutil.rmtree(temp_dir)
|
| 75 |
raise RuntimeError(f"Separation failed: {e}") from e
|
| 76 |
|
|
|
|
| 77 |
# ------------------ UI ------------------
|
| 78 |
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
gr.Markdown(
|
| 81 |
"""
|
| 82 |
+
# 🎵 AI 6-Stem Audio Separator (FTP Upload)
|
| 83 |
+
Split music into tracks and upload directly to **Hostinger**.
|
| 84 |
"""
|
| 85 |
)
|
| 86 |
|
|
|
|
| 98 |
label="Select Model",
|
| 99 |
)
|
| 100 |
|
| 101 |
+
separate_btn = gr.Button("🚀 Separate & Upload", variant="primary")
|
| 102 |
|
| 103 |
with gr.Column(scale=2):
|
| 104 |
+
gr.Markdown("### 🔊 Remote Results (Hostinger URLs)")
|
| 105 |
|
| 106 |
with gr.Row():
|
| 107 |
output_vocals = gr.Audio(label="🎤 Vocals", type="filepath")
|
|
|
|
| 128 |
],
|
| 129 |
)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
if __name__ == "__main__":
|
| 132 |
demo.launch(
|
| 133 |
ssr_mode=False,
|