Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,10 @@ import requests
|
|
8 |
from dotenv import load_dotenv
|
9 |
from gradio_leaderboard import Leaderboard
|
10 |
from pandas import DataFrame
|
|
|
|
|
|
|
|
|
11 |
|
12 |
load_dotenv()
|
13 |
|
@@ -20,6 +24,24 @@ storage_url = os.getenv("STORAGE_URL")
|
|
20 |
tmp_dir = os.path.join(os.getcwd(), "tmp")
|
21 |
os.makedirs(tmp_dir, exist_ok=True)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def file_to_base64(file_path):
|
25 |
with open(file_path, "rb") as file:
|
@@ -164,6 +186,8 @@ def seed_change(evt: gr.SelectData, value=None):
|
|
164 |
|
165 |
# 获取 pt 文件
|
166 |
down_file = restore_pt_file(seed_id)
|
|
|
|
|
167 |
|
168 |
# 获取试听文件
|
169 |
wav_file = restore_wav_file(seed_id)
|
@@ -175,6 +199,7 @@ def seed_change(evt: gr.SelectData, value=None):
|
|
175 |
evt.index,
|
176 |
gr.DownloadButton(value=down_file, label=f"Download .pt File [{seed_id}]", visible=True),
|
177 |
gr.Audio(wav_file, visible=wav_file is not None),
|
|
|
178 |
]
|
179 |
|
180 |
|
@@ -239,10 +264,11 @@ params_infer_code = {
|
|
239 |
)
|
240 |
stats = gr.State(value=[1])
|
241 |
download_button = gr.DownloadButton("Download .pt File", visible=True)
|
|
|
242 |
test_audio = gr.Audio(visible=True)
|
243 |
gr.Markdown("选择 seed_id 才能下载 .pt 文件和试听音频。")
|
244 |
# download_button.click(download, inputs=[stats], outputs=[])
|
245 |
-
leaderboard.select(seed_change, inputs=[leaderboard], outputs=[stats, download_button, test_audio])
|
246 |
|
247 |
with gr.Tab(label="📊Details"):
|
248 |
gr.Markdown("""
|
|
|
8 |
from dotenv import load_dotenv
|
9 |
from gradio_leaderboard import Leaderboard
|
10 |
from pandas import DataFrame
|
11 |
+
import torch
|
12 |
+
import pybase16384 as b14
|
13 |
+
import numpy as np
|
14 |
+
import lzma
|
15 |
|
16 |
load_dotenv()
|
17 |
|
|
|
24 |
tmp_dir = os.path.join(os.getcwd(), "tmp")
|
25 |
os.makedirs(tmp_dir, exist_ok=True)
|
26 |
|
27 |
+
def _encode_spk_emb(spk_emb: torch.Tensor) -> str:
|
28 |
+
with torch.no_grad():
|
29 |
+
arr: np.ndarray = spk_emb.to(dtype=torch.float16, device="cpu").numpy()
|
30 |
+
s = b14.encode_to_string(
|
31 |
+
lzma.compress(
|
32 |
+
arr.tobytes(),
|
33 |
+
format=lzma.FORMAT_RAW,
|
34 |
+
filters=[
|
35 |
+
{"id": lzma.FILTER_LZMA2, "preset": 9 | lzma.PRESET_EXTREME}
|
36 |
+
],
|
37 |
+
),
|
38 |
+
)
|
39 |
+
del arr
|
40 |
+
return s
|
41 |
+
|
42 |
+
def pt2str(pt_path):
|
43 |
+
spk_emb = torch.load(pt_path, map_location="cpu")
|
44 |
+
return _encode_spk_emb(spk_emb)
|
45 |
|
46 |
def file_to_base64(file_path):
|
47 |
with open(file_path, "rb") as file:
|
|
|
186 |
|
187 |
# 获取 pt 文件
|
188 |
down_file = restore_pt_file(seed_id)
|
189 |
+
# spk_emb_str
|
190 |
+
spk_emb_str = pt2str(down_file)
|
191 |
|
192 |
# 获取试听文件
|
193 |
wav_file = restore_wav_file(seed_id)
|
|
|
199 |
evt.index,
|
200 |
gr.DownloadButton(value=down_file, label=f"Download .pt File [{seed_id}]", visible=True),
|
201 |
gr.Audio(wav_file, visible=wav_file is not None),
|
202 |
+
spk_emb_str,
|
203 |
]
|
204 |
|
205 |
|
|
|
264 |
)
|
265 |
stats = gr.State(value=[1])
|
266 |
download_button = gr.DownloadButton("Download .pt File", visible=True)
|
267 |
+
spk_emb_str = gr.Textbox("", label="音色码/speaker embedding", lines=5)
|
268 |
test_audio = gr.Audio(visible=True)
|
269 |
gr.Markdown("选择 seed_id 才能下载 .pt 文件和试听音频。")
|
270 |
# download_button.click(download, inputs=[stats], outputs=[])
|
271 |
+
leaderboard.select(seed_change, inputs=[leaderboard], outputs=[stats, download_button, test_audio, spk_emb_str])
|
272 |
|
273 |
with gr.Tab(label="📊Details"):
|
274 |
gr.Markdown("""
|