Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import spaces
|
| 5 |
import shutil
|
| 6 |
import argparse
|
|
@@ -11,10 +20,54 @@ os.system("wget https://github.com/noblebarkrr/mvsepless/raw/bd611441e48e918650e
|
|
| 11 |
from multi_inference import MVSEPLESS, OUTPUT_FORMATS
|
| 12 |
from assets.translations import TRANSLATIONS, TRANSLATIONS_STEMS
|
| 13 |
|
|
|
|
|
|
|
| 14 |
OUTPUT_DIR = os.path.join(os.getcwd(), "output")
|
| 15 |
plugins_dir = os.path.join(os.getcwd(), "plugins")
|
| 16 |
os.makedirs(plugins_dir, exist_ok=True)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
CURRENT_LANG = "ru"
|
| 19 |
|
| 20 |
def t(key, **kwargs):
|
|
@@ -36,6 +89,9 @@ mvsepless = MVSEPLESS()
|
|
| 36 |
|
| 37 |
@spaces.GPU
|
| 38 |
def sep_wrapper(a, b, c, d, e, f, g, h):
|
|
|
|
|
|
|
|
|
|
| 39 |
if not g:
|
| 40 |
g = 128
|
| 41 |
results = mvsepless.separator(input_file=a, output_dir=gen_out_dir(), model_type=b, model_name=c, ext_inst=d, vr_aggr=e, output_format=f, output_bitrate=f'{g}k', call_method="cli", selected_stems=h)
|
|
@@ -99,6 +155,7 @@ def create_app():
|
|
| 99 |
with gr.Column():
|
| 100 |
input_audio = gr.Audio(label=t("select_file"), interactive=True, type="filepath")
|
| 101 |
input_audio_path = gr.Textbox(label=t("audio_path"), info=t("audio_path_info"), interactive=True)
|
|
|
|
| 102 |
with gr.Column():
|
| 103 |
with gr.Row():
|
| 104 |
model_type = gr.Dropdown(label=t("model_type"), choices=mvsepless.get_mt(), value=mvsepless.get_mt()[0], interactive=True, filterable=False)
|
|
@@ -123,6 +180,7 @@ def create_app():
|
|
| 123 |
model_name.change(fn=(lambda x, y: gr.update(choices=mvsepless.get_stems(x, y), value=None)), inputs=[model_type, model_name], outputs=stems_list).then(fn=(lambda x, y: (gr.update(interactive=True if mvsepless.get_tgt_inst(x, y) == None else None, info=t("stems_info", target_instrument=mvsepless.get_tgt_inst(x, y)) if mvsepless.get_tgt_inst(x, y) is not None else t("stems_info2")), gr.update(value=mvsepless.get_tgt_inst(x, y)), gr.update(value=True if mvsepless.get_tgt_inst(x, y) is not None else False))), inputs=[model_type, model_name], outputs=[stems_list, target_instrument, extract_instrumental])
|
| 124 |
separate_btn.click(fn=sep_wrapper, inputs=[input_audio_path, model_type, model_name, extract_instrumental, vr_aggr, output_format, output_bitrate, stems_list], outputs=output_stems, show_progress_on=input_audio)
|
| 125 |
|
|
|
|
| 126 |
|
| 127 |
CURRENT_LANG = "ru"
|
| 128 |
css = """
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import time
|
| 4 |
+
try:
|
| 5 |
+
import yt_dlp
|
| 6 |
+
import validators
|
| 7 |
+
except ImportError:
|
| 8 |
+
os.system("pip install validators")
|
| 9 |
+
os.system("pip install yt-dlp")
|
| 10 |
+
import validators
|
| 11 |
+
import yt_dlp
|
| 12 |
+
|
| 13 |
import spaces
|
| 14 |
import shutil
|
| 15 |
import argparse
|
|
|
|
| 20 |
from multi_inference import MVSEPLESS, OUTPUT_FORMATS
|
| 21 |
from assets.translations import TRANSLATIONS, TRANSLATIONS_STEMS
|
| 22 |
|
| 23 |
+
COOKIE_FILE = None
|
| 24 |
+
DOWNLOAD_DIR = os.path.join(os.getcwd(), "downloaded")
|
| 25 |
OUTPUT_DIR = os.path.join(os.getcwd(), "output")
|
| 26 |
plugins_dir = os.path.join(os.getcwd(), "plugins")
|
| 27 |
os.makedirs(plugins_dir, exist_ok=True)
|
| 28 |
|
| 29 |
+
def load_cookie(file):
|
| 30 |
+
global COOKIE_FILE
|
| 31 |
+
COOKIE_FILE = file
|
| 32 |
+
gr.Warning(t("cookie_loaded"))
|
| 33 |
+
|
| 34 |
+
def download_file(url):
|
| 35 |
+
|
| 36 |
+
ydl_opts = {
|
| 37 |
+
'format': 'bestaudio/best',
|
| 38 |
+
'outtmpl': os.path.join(DOWNLOAD_DIR, '%(title)s.%(ext)s'),
|
| 39 |
+
'postprocessors': [{
|
| 40 |
+
'key': 'FFmpegExtractAudio',
|
| 41 |
+
'preferredcodec': 'mp3',
|
| 42 |
+
'preferredquality': '320',
|
| 43 |
+
}],
|
| 44 |
+
'noplaylist': True, # Скачивать только одно видео, не плейлист
|
| 45 |
+
'quiet': True, # Отключить вывод в консоль
|
| 46 |
+
'no_warnings': True, # Скрыть предупреждения
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
# Добавляем cookies если указаны
|
| 50 |
+
if COOKIE_FILE and os.path.exists(COOKIE_FILE):
|
| 51 |
+
ydl_opts['cookiefile'] = COOKIE_FILE
|
| 52 |
+
|
| 53 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 54 |
+
info = ydl.extract_info(url, download=True)
|
| 55 |
+
|
| 56 |
+
# Получаем имя файла из метаданных
|
| 57 |
+
if '_type' in info and info['_type'] == 'playlist':
|
| 58 |
+
# Для плейлистов берем первое видео
|
| 59 |
+
entry = info['entries'][0]
|
| 60 |
+
filename = ydl.prepare_filename(entry)
|
| 61 |
+
else:
|
| 62 |
+
# Для одиночного видео
|
| 63 |
+
filename = ydl.prepare_filename(info)
|
| 64 |
+
|
| 65 |
+
# Заменяем оригинальное расширение на .mp3
|
| 66 |
+
base, _ = os.path.splitext(filename)
|
| 67 |
+
audio_file = base + '.mp3'
|
| 68 |
+
|
| 69 |
+
return os.path.abspath(audio_file)
|
| 70 |
+
|
| 71 |
CURRENT_LANG = "ru"
|
| 72 |
|
| 73 |
def t(key, **kwargs):
|
|
|
|
| 89 |
|
| 90 |
@spaces.GPU
|
| 91 |
def sep_wrapper(a, b, c, d, e, f, g, h):
|
| 92 |
+
if a is not None:
|
| 93 |
+
if validators.url(a) and not os.path.exists(a):
|
| 94 |
+
a = download_file(a)
|
| 95 |
if not g:
|
| 96 |
g = 128
|
| 97 |
results = mvsepless.separator(input_file=a, output_dir=gen_out_dir(), model_type=b, model_name=c, ext_inst=d, vr_aggr=e, output_format=f, output_bitrate=f'{g}k', call_method="cli", selected_stems=h)
|
|
|
|
| 155 |
with gr.Column():
|
| 156 |
input_audio = gr.Audio(label=t("select_file"), interactive=True, type="filepath")
|
| 157 |
input_audio_path = gr.Textbox(label=t("audio_path"), info=t("audio_path_info"), interactive=True)
|
| 158 |
+
use_cookies = gr.UploadButton(label=t("use_cookies"), size="sm", file_count="single", file_types=[".txt"])
|
| 159 |
with gr.Column():
|
| 160 |
with gr.Row():
|
| 161 |
model_type = gr.Dropdown(label=t("model_type"), choices=mvsepless.get_mt(), value=mvsepless.get_mt()[0], interactive=True, filterable=False)
|
|
|
|
| 180 |
model_name.change(fn=(lambda x, y: gr.update(choices=mvsepless.get_stems(x, y), value=None)), inputs=[model_type, model_name], outputs=stems_list).then(fn=(lambda x, y: (gr.update(interactive=True if mvsepless.get_tgt_inst(x, y) == None else None, info=t("stems_info", target_instrument=mvsepless.get_tgt_inst(x, y)) if mvsepless.get_tgt_inst(x, y) is not None else t("stems_info2")), gr.update(value=mvsepless.get_tgt_inst(x, y)), gr.update(value=True if mvsepless.get_tgt_inst(x, y) is not None else False))), inputs=[model_type, model_name], outputs=[stems_list, target_instrument, extract_instrumental])
|
| 181 |
separate_btn.click(fn=sep_wrapper, inputs=[input_audio_path, model_type, model_name, extract_instrumental, vr_aggr, output_format, output_bitrate, stems_list], outputs=output_stems, show_progress_on=input_audio)
|
| 182 |
|
| 183 |
+
use_cookies.upload(fn=load_cookie, inputs=use_cookies)
|
| 184 |
|
| 185 |
CURRENT_LANG = "ru"
|
| 186 |
css = """
|