Spaces:
Running on Zero
Running on Zero
Update src/webui.py
Browse files- src/webui.py +28 -11
src/webui.py
CHANGED
|
@@ -25,6 +25,7 @@ def configure_logging_libs(debug=False):
|
|
| 25 |
configure_logging_libs()
|
| 26 |
|
| 27 |
from main import song_cover_pipeline, yt_download
|
|
|
|
| 28 |
|
| 29 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 30 |
IS_ZERO_GPU = os.getenv("SPACES_ZERO_GPU")
|
|
@@ -57,6 +58,8 @@ def load_public_models():
|
|
| 57 |
|
| 58 |
|
| 59 |
def extract_zip(extraction_folder, zip_name):
|
|
|
|
|
|
|
| 60 |
os.makedirs(extraction_folder)
|
| 61 |
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
|
| 62 |
zip_ref.extractall(extraction_folder)
|
|
@@ -70,6 +73,7 @@ def extract_zip(extraction_folder, zip_name):
|
|
| 70 |
|
| 71 |
if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
|
| 72 |
model_filepath = os.path.join(root, name)
|
|
|
|
| 73 |
|
| 74 |
if not model_filepath:
|
| 75 |
raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
|
|
@@ -96,9 +100,8 @@ def download_online_model(url, dir_name, progress=gr.Progress()):
|
|
| 96 |
if 'pixeldrain.com' in url:
|
| 97 |
url = f'https://pixeldrain.com/api/file/{zip_name}'
|
| 98 |
|
| 99 |
-
|
| 100 |
if "," in url:
|
| 101 |
-
urls = [u.strip() for u in url.split(",") if u.strip()]
|
| 102 |
os.makedirs(extraction_folder, exist_ok=True)
|
| 103 |
for u in urls:
|
| 104 |
u = u.replace("?download=true", "")
|
|
@@ -106,19 +109,26 @@ def download_online_model(url, dir_name, progress=gr.Progress()):
|
|
| 106 |
file_path = os.path.join(extraction_folder, file_name)
|
| 107 |
if not os.path.exists(file_path): # avoid re-downloading
|
| 108 |
urllib.request.urlretrieve(u, file_path)
|
|
|
|
| 109 |
else:
|
|
|
|
| 110 |
urllib.request.urlretrieve(url, zip_name)
|
| 111 |
|
| 112 |
progress(0.5, desc='[~] Extracting zip...')
|
| 113 |
extract_zip(extraction_folder, zip_name)
|
|
|
|
| 114 |
return f'[+] {dir_name} Model successfully downloaded!'
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
|
| 120 |
def upload_local_model(zip_path, dir_name, progress=gr.Progress()):
|
| 121 |
try:
|
|
|
|
|
|
|
| 122 |
extraction_folder = os.path.join(rvc_models_dir, dir_name)
|
| 123 |
if os.path.exists(extraction_folder):
|
| 124 |
raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
|
|
@@ -183,6 +193,10 @@ def show_hop_slider(pitch_detection_algo):
|
|
| 183 |
return gr.update(visible=False)
|
| 184 |
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
if __name__ == '__main__':
|
| 187 |
parser = ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
|
| 188 |
parser.add_argument("--share", action="store_true", dest="share_enabled", default=False, help="Enable sharing")
|
|
@@ -284,11 +298,12 @@ if __name__ == '__main__':
|
|
| 284 |
with gr.Row():
|
| 285 |
clear_btn = gr.ClearButton(value='Clear', components=[song_input, rvc_model, keep_files, local_file])
|
| 286 |
generate_btn = gr.Button("Generate", variant='primary')
|
| 287 |
-
ai_cover = (
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
)
|
|
|
|
| 292 |
gr.Markdown("- You can also try `AICoverGen❤️` in Colab’s free tier, which provides free GPU [link](https://github.com/R3gm/AICoverGen?tab=readme-ov-file#aicovergen).")
|
| 293 |
|
| 294 |
ref_btn.click(update_models_list, None, outputs=rvc_model)
|
|
@@ -298,7 +313,9 @@ if __name__ == '__main__':
|
|
| 298 |
inst_gain, index_rate, filter_radius, rms_mix_rate, f0_method, crepe_hop_length,
|
| 299 |
protect, pitch_all, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping,
|
| 300 |
output_format, extra_denoise, steps],
|
| 301 |
-
outputs=[ai_cover])
|
|
|
|
|
|
|
| 302 |
clear_btn.click(lambda: [0, 0, 0, 0, 0.5, 3, 0.25, 0.33, 'rmvpe+', 128, 0, 0.15, 0.2, 0.8, 0.7, 'mp3', None, True, 1],
|
| 303 |
outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
|
| 304 |
protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
|
|
@@ -387,4 +404,4 @@ if __name__ == '__main__':
|
|
| 387 |
server_name=None if not args.listen else (args.listen_host or '0.0.0.0'),
|
| 388 |
server_port=args.listen_port,
|
| 389 |
ssr_mode=args.ssr
|
| 390 |
-
)
|
|
|
|
| 25 |
configure_logging_libs()
|
| 26 |
|
| 27 |
from main import song_cover_pipeline, yt_download
|
| 28 |
+
from sec_utils import validate_url, check_model_safety
|
| 29 |
|
| 30 |
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 31 |
IS_ZERO_GPU = os.getenv("SPACES_ZERO_GPU")
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def extract_zip(extraction_folder, zip_name):
|
| 61 |
+
check_model_safety(zip_name)
|
| 62 |
+
|
| 63 |
os.makedirs(extraction_folder)
|
| 64 |
with zipfile.ZipFile(zip_name, 'r') as zip_ref:
|
| 65 |
zip_ref.extractall(extraction_folder)
|
|
|
|
| 73 |
|
| 74 |
if name.endswith('.pth') and os.stat(os.path.join(root, name)).st_size > 1024 * 1024 * 40:
|
| 75 |
model_filepath = os.path.join(root, name)
|
| 76 |
+
check_model_safety(model_filepath)
|
| 77 |
|
| 78 |
if not model_filepath:
|
| 79 |
raise gr.Error(f'No .pth model file was found in the extracted zip. Please check {extraction_folder}.')
|
|
|
|
| 100 |
if 'pixeldrain.com' in url:
|
| 101 |
url = f'https://pixeldrain.com/api/file/{zip_name}'
|
| 102 |
|
|
|
|
| 103 |
if "," in url:
|
| 104 |
+
urls = [validate_url(u.strip()) for u in url.split(",") if u.strip()]
|
| 105 |
os.makedirs(extraction_folder, exist_ok=True)
|
| 106 |
for u in urls:
|
| 107 |
u = u.replace("?download=true", "")
|
|
|
|
| 109 |
file_path = os.path.join(extraction_folder, file_name)
|
| 110 |
if not os.path.exists(file_path): # avoid re-downloading
|
| 111 |
urllib.request.urlretrieve(u, file_path)
|
| 112 |
+
check_model_safety(file_path)
|
| 113 |
else:
|
| 114 |
+
url = validate_url(url)
|
| 115 |
urllib.request.urlretrieve(url, zip_name)
|
| 116 |
|
| 117 |
progress(0.5, desc='[~] Extracting zip...')
|
| 118 |
extract_zip(extraction_folder, zip_name)
|
| 119 |
+
|
| 120 |
return f'[+] {dir_name} Model successfully downloaded!'
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
+
str_e = str(e)
|
| 124 |
+
if 'HTTP Error 401: Unauthorized' in str_e:
|
| 125 |
+
raise gr.Error(f'{str_e}: The file at the provided URL does not exist, is private, or has been deleted. Please verify the link.')
|
| 126 |
+
raise gr.Error(str_e)
|
| 127 |
|
| 128 |
def upload_local_model(zip_path, dir_name, progress=gr.Progress()):
|
| 129 |
try:
|
| 130 |
+
check_model_safety(zip_path)
|
| 131 |
+
|
| 132 |
extraction_folder = os.path.join(rvc_models_dir, dir_name)
|
| 133 |
if os.path.exists(extraction_folder):
|
| 134 |
raise gr.Error(f'Voice model directory {dir_name} already exists! Choose a different name for your voice model.')
|
|
|
|
| 193 |
return gr.update(visible=False)
|
| 194 |
|
| 195 |
|
| 196 |
+
def update_audio_player(is_player_active, audio_path):
|
| 197 |
+
return gr.update(value=audio_path if is_player_active else None, visible=True if is_player_active else False)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
if __name__ == '__main__':
|
| 201 |
parser = ArgumentParser(description='Generate a AI cover song in the song_output/id directory.', add_help=True)
|
| 202 |
parser.add_argument("--share", action="store_true", dest="share_enabled", default=False, help="Enable sharing")
|
|
|
|
| 298 |
with gr.Row():
|
| 299 |
clear_btn = gr.ClearButton(value='Clear', components=[song_input, rvc_model, keep_files, local_file])
|
| 300 |
generate_btn = gr.Button("Generate", variant='primary')
|
| 301 |
+
ai_cover = gr.File(label="AI Cover", interactive=False)
|
| 302 |
+
|
| 303 |
+
with gr.Row():
|
| 304 |
+
audio_player_checkbox = gr.Checkbox(label="Audio Player", value=False, container=False, scale=1)
|
| 305 |
+
ai_cover_audio = gr.Audio(label="AI Cover Player", value=None, visible=False, scale=4)
|
| 306 |
+
|
| 307 |
gr.Markdown("- You can also try `AICoverGen❤️` in Colab’s free tier, which provides free GPU [link](https://github.com/R3gm/AICoverGen?tab=readme-ov-file#aicovergen).")
|
| 308 |
|
| 309 |
ref_btn.click(update_models_list, None, outputs=rvc_model)
|
|
|
|
| 313 |
inst_gain, index_rate, filter_radius, rms_mix_rate, f0_method, crepe_hop_length,
|
| 314 |
protect, pitch_all, reverb_rm_size, reverb_wet, reverb_dry, reverb_damping,
|
| 315 |
output_format, extra_denoise, steps],
|
| 316 |
+
outputs=[ai_cover]).success(update_audio_player,
|
| 317 |
+
inputs=[audio_player_checkbox, ai_cover],
|
| 318 |
+
outputs=[ai_cover_audio])
|
| 319 |
clear_btn.click(lambda: [0, 0, 0, 0, 0.5, 3, 0.25, 0.33, 'rmvpe+', 128, 0, 0.15, 0.2, 0.8, 0.7, 'mp3', None, True, 1],
|
| 320 |
outputs=[pitch, main_gain, backup_gain, inst_gain, index_rate, filter_radius, rms_mix_rate,
|
| 321 |
protect, f0_method, crepe_hop_length, pitch_all, reverb_rm_size, reverb_wet,
|
|
|
|
| 404 |
server_name=None if not args.listen else (args.listen_host or '0.0.0.0'),
|
| 405 |
server_port=args.listen_port,
|
| 406 |
ssr_mode=args.ssr
|
| 407 |
+
)
|