zxsipola123456 commited on
Commit
ed0009e
1 Parent(s): a6c41ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -36
app.py CHANGED
@@ -16,23 +16,23 @@ 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')
@@ -70,20 +70,20 @@ def voice_change(audio_in, audio_ref):
70
  return output_path
71
 
72
 
73
- #验证中转api key是否有效
74
- def validate_api_key(api_proxy_key):
75
- try:
76
- client = OpenAI(api_key=api_proxy_key, base_url='https://lmzh.top/v1')
77
- # 测试调用一个简单的API来验证Key
78
- response = client.models.list()
79
- return True
80
- except Exception:
81
- return False
82
 
83
- # 更新Edge TTS标签页状态的函数
84
- def update_edge_tts_tab(api_proxy_key):
85
- is_valid = validate_api_key(api_proxy_key)
86
- return gr.update(interactive=is_valid)
87
 
88
 
89
  # 文字转语音(OpenAI)
@@ -187,7 +187,7 @@ with app:
187
  btn_text.click(tts1, [inp_text, model, voice, api_key], inp1)
188
  btn1.click(voice_change, [inp1, inp2], out1)
189
 
190
- with gr.Tab("TTS-AI变声",interactive=False) as edge_tts_tab:
191
  with gr.Row():
192
  with gr.Column():
193
  input_text = gr.Textbox(label="请填写您想生成的文本中英文皆可",placeholder="请输入ai生成的文案,不要超过300字,最好200字左右",lines=5)
@@ -207,11 +207,11 @@ with app:
207
  btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
208
  btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
209
  # 监听API Key输入框的变化并更新Edge TTS标签页的状态
210
- api_proxy_key.change(
211
- update_edge_tts_tab,
212
- inputs=[api_proxy_key],
213
- outputs=[edge_tts_tab]
214
- )
215
 
216
  gr.HTML('''
217
  <div class="footer">
 
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')
 
70
  return output_path
71
 
72
 
73
+ # #验证中转api key是否有效
74
+ # def validate_api_key(api_proxy_key):
75
+ # try:
76
+ # client = OpenAI(api_key=api_proxy_key, base_url='https://lmzh.top/v1')
77
+ # # 测试调用一个简单的API来验证Key
78
+ # response = client.models.list()
79
+ # return True
80
+ # except Exception:
81
+ # return False
82
 
83
+ # # 更新Edge TTS标签页状态的函数
84
+ # def update_edge_tts_tab(api_proxy_key):
85
+ # is_valid = validate_api_key(api_proxy_key)
86
+ # return gr.update(interactive=is_valid)
87
 
88
 
89
  # 文字转语音(OpenAI)
 
187
  btn_text.click(tts1, [inp_text, model, voice, api_key], inp1)
188
  btn1.click(voice_change, [inp1, inp2], out1)
189
 
190
+ with gr.Tab("TTS-AI变声") as edge_tts_tab:
191
  with gr.Row():
192
  with gr.Column():
193
  input_text = gr.Textbox(label="请填写您想生成的文本中英文皆可",placeholder="请输入ai生成的文案,不要超过300字,最好200字左右",lines=5)
 
207
  btn_edge.click(lambda text, lang: anyio.run(text_to_speech_edge, text, lang), [input_text, language], [output_text, output_audio])
208
  btn_vc.click(voice_change, [output_audio, inp_vc], out_vc)
209
  # 监听API Key输入框的变化并更新Edge TTS标签页的状态
210
+ # api_proxy_key.change(
211
+ # update_edge_tts_tab,
212
+ # inputs=[api_proxy_key],
213
+ # outputs=[edge_tts_tab]
214
+ # )
215
 
216
  gr.HTML('''
217
  <div class="footer">