Spaces:
Paused
Paused
zxsipola123456
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,29 @@ import torchaudio
|
|
10 |
import gradio as gr
|
11 |
from scipy.io import wavfile
|
12 |
from scipy.io.wavfile import write
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# 创建 KNN-VC 模型
|
15 |
knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
|
|
|
10 |
import gradio as gr
|
11 |
from scipy.io import wavfile
|
12 |
from scipy.io.wavfile import write
|
13 |
+
#新加内容
|
14 |
+
import asyncio
|
15 |
+
import threading
|
16 |
+
import requests
|
17 |
+
from aiohttp import ClientSession
|
18 |
+
|
19 |
+
# 异步函数进行预加载
|
20 |
+
async def fetch_link_content(url):
|
21 |
+
async with ClientSession() as session:
|
22 |
+
async with session.get(url) as response:
|
23 |
+
return await response.text()
|
24 |
+
|
25 |
+
# 后台任务确保不阻塞主线程
|
26 |
+
def fetch_link_in_background(url):
|
27 |
+
loop = asyncio.new_event_loop()
|
28 |
+
asyncio.set_event_loop(loop)
|
29 |
+
content = loop.run_until_complete(fetch_link_content(url))
|
30 |
+
# 将 content 缓存起来或者在全局状态中保存以供后续使用
|
31 |
+
print("预加载的内容:", content)
|
32 |
+
|
33 |
+
link_url = "https://huggingface.co/api/spaces/by-subdomain/zxsipola123456-tts"
|
34 |
+
background_thread = threading.Thread(target=fetch_link_in_background, args=(link_url,))
|
35 |
+
background_thread.start()
|
36 |
|
37 |
# 创建 KNN-VC 模型
|
38 |
knn_vc = torch.hub.load('bshall/knn-vc', 'knn_vc', prematched=True, trust_repo=True, pretrained=True, device='cpu')
|