Update tabs/voice_blender/voice_blender.py
Browse files
tabs/voice_blender/voice_blender.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
import os, sys
|
2 |
import gradio as gr
|
3 |
import shutil
|
|
|
|
|
|
|
4 |
|
5 |
now_dir = os.getcwd()
|
6 |
sys.path.append(now_dir)
|
@@ -10,10 +13,28 @@ from core import run_model_blender_script
|
|
10 |
|
11 |
i18n = I18nAuto()
|
12 |
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
|
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def voice_blender_tab():
|
19 |
gr.Markdown(i18n("## Voice Blender"))
|
@@ -33,26 +54,30 @@ def voice_blender_tab():
|
|
33 |
)
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
36 |
-
|
37 |
-
label=i18n("
|
38 |
-
)
|
39 |
-
model_fusion_a = gr.Textbox(
|
40 |
-
label=i18n("Path to Model"),
|
41 |
value="",
|
42 |
interactive=True,
|
43 |
-
placeholder=i18n("Enter
|
44 |
-
info=i18n("You can also use a custom path."),
|
45 |
)
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
)
|
50 |
-
|
51 |
-
|
|
|
52 |
value="",
|
53 |
interactive=True,
|
54 |
-
placeholder=i18n("Enter
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
56 |
)
|
57 |
alpha_a = gr.Slider(
|
58 |
minimum=0,
|
@@ -75,25 +100,19 @@ def voice_blender_tab():
|
|
75 |
label=i18n("Download Model"), type="filepath", interactive=False
|
76 |
)
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
model_fusion_button.click(
|
79 |
fn=run_model_blender_script,
|
80 |
inputs=[
|
81 |
model_fusion_name,
|
82 |
-
|
83 |
-
|
84 |
alpha_a,
|
85 |
],
|
86 |
outputs=[model_fusion_output_info, model_fusion_pth_output],
|
87 |
-
)
|
88 |
-
|
89 |
-
model_fusion_a_dropbox.upload(
|
90 |
-
fn=update_model_fusion,
|
91 |
-
inputs=model_fusion_a_dropbox,
|
92 |
-
outputs=[model_fusion_a, model_fusion_a_dropbox],
|
93 |
-
)
|
94 |
-
|
95 |
-
model_fusion_b_dropbox.upload(
|
96 |
-
fn=update_model_fusion,
|
97 |
-
inputs=model_fusion_b_dropbox,
|
98 |
-
outputs=[model_fusion_b, model_fusion_b_dropbox],
|
99 |
-
)
|
|
|
1 |
import os, sys
|
2 |
import gradio as gr
|
3 |
import shutil
|
4 |
+
import requests
|
5 |
+
from zipfile import ZipFile
|
6 |
+
from tempfile import TemporaryDirectory
|
7 |
|
8 |
now_dir = os.getcwd()
|
9 |
sys.path.append(now_dir)
|
|
|
13 |
|
14 |
i18n = I18nAuto()
|
15 |
|
16 |
+
def download_and_extract_model(url):
|
17 |
+
temp_dir = TemporaryDirectory()
|
18 |
+
zip_path = os.path.join(temp_dir.name, "model.zip")
|
19 |
|
20 |
+
with requests.get(url, stream=True) as r:
|
21 |
+
with open(zip_path, 'wb') as f:
|
22 |
+
shutil.copyfileobj(r.raw, f)
|
23 |
|
24 |
+
with ZipFile(zip_path, 'r') as zip_ref:
|
25 |
+
zip_ref.extractall(temp_dir.name)
|
26 |
+
|
27 |
+
pth_files = [os.path.join(temp_dir.name, f) for f in os.listdir(temp_dir.name) if f.endswith('.pth')]
|
28 |
+
|
29 |
+
if pth_files:
|
30 |
+
return pth_files[0]
|
31 |
+
else:
|
32 |
+
raise FileNotFoundError("No se encontr贸 un archivo .pth en el zip descargado.")
|
33 |
+
|
34 |
+
def download_and_set_paths(link_a, link_b):
|
35 |
+
path_a = download_and_extract_model(link_a)
|
36 |
+
path_b = download_and_extract_model(link_b)
|
37 |
+
return path_a, path_b
|
38 |
|
39 |
def voice_blender_tab():
|
40 |
gr.Markdown(i18n("## Voice Blender"))
|
|
|
54 |
)
|
55 |
with gr.Row():
|
56 |
with gr.Column():
|
57 |
+
model_fusion_a_link = gr.Textbox(
|
58 |
+
label=i18n("Hugging Face Link for Model A"),
|
|
|
|
|
|
|
59 |
value="",
|
60 |
interactive=True,
|
61 |
+
placeholder=i18n("Enter Hugging Face link for model A"),
|
|
|
62 |
)
|
63 |
+
model_fusion_a_path = gr.Textbox(
|
64 |
+
label=i18n("Path to Model A"),
|
65 |
+
value="",
|
66 |
+
interactive=False,
|
67 |
+
placeholder=i18n("Path will be set automatically after download"),
|
68 |
)
|
69 |
+
with gr.Column():
|
70 |
+
model_fusion_b_link = gr.Textbox(
|
71 |
+
label=i18n("Hugging Face Link for Model B"),
|
72 |
value="",
|
73 |
interactive=True,
|
74 |
+
placeholder=i18n("Enter Hugging Face link for model B"),
|
75 |
+
)
|
76 |
+
model_fusion_b_path = gr.Textbox(
|
77 |
+
label=i18n("Path to Model B"),
|
78 |
+
value="",
|
79 |
+
interactive=False,
|
80 |
+
placeholder=i18n("Path will be set automatically after download"),
|
81 |
)
|
82 |
alpha_a = gr.Slider(
|
83 |
minimum=0,
|
|
|
100 |
label=i18n("Download Model"), type="filepath", interactive=False
|
101 |
)
|
102 |
|
103 |
+
model_fusion_button.click(
|
104 |
+
fn=download_and_set_paths,
|
105 |
+
inputs=[model_fusion_a_link, model_fusion_b_link],
|
106 |
+
outputs=[model_fusion_a_path, model_fusion_b_path],
|
107 |
+
)
|
108 |
+
|
109 |
model_fusion_button.click(
|
110 |
fn=run_model_blender_script,
|
111 |
inputs=[
|
112 |
model_fusion_name,
|
113 |
+
model_fusion_a_path,
|
114 |
+
model_fusion_b_path,
|
115 |
alpha_a,
|
116 |
],
|
117 |
outputs=[model_fusion_output_info, model_fusion_pth_output],
|
118 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|