DeepLearning101 commited on
Commit
b9119d1
·
verified ·
1 Parent(s): 19940d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -36
app.py CHANGED
@@ -3,33 +3,15 @@
3
  @author:XuMing([email protected])
4
  @description: Re-train by TWMAN
5
  """
6
-
7
  import hashlib
8
  import os
9
  import ssl
10
  import subprocess
11
-
12
- import gradio as gr
13
  import torch
14
  from loguru import logger
15
  import nltk
16
-
17
- import torch.serialization
18
  from torch.serialization import add_safe_globals
19
 
20
- class DummyHParams:
21
- pass
22
-
23
- # ➕ 加入允許的類別進入 PyTorch 的安全清單中
24
- add_safe_globals([DummyHParams])
25
-
26
- # ✅ 繼續 monkey patch torch.load
27
- _original_torch_load = torch.load
28
- def patched_torch_load(*args, **kwargs):
29
- return _original_torch_load(*args, **kwargs)
30
-
31
- torch.load = patched_torch_load
32
-
33
  # 設定 HTTPS context 避免證書錯誤
34
  ssl._create_default_https_context = ssl._create_unverified_context
35
 
@@ -51,6 +33,20 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
51
  logger.info(f"device: {device}")
52
  half = True if device == "cuda" else False
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # 初始化 TTS 模型
55
  m = TextToSpeech(
56
  speaker_model_path="DeepLearning101/GPT-SoVITS_TWMAN",
@@ -98,24 +94,6 @@ with gr.Blocks(title="TTS WebUI") as app:
98
  - [基於機器閱讀理解和指令微調的統一信息抽取框架之診斷書醫囑資訊擷取分析](https://blog.twman.org/2023/07/HugIE.html)
99
  """)
100
 
101
- with gr.Group():
102
- gr.Markdown("🔤 請輸入要進行語音合成的文字:")
103
- with gr.Row():
104
- text = gr.Textbox(
105
- label="輸入文字(建議 100 字內)",
106
- value="床前明月光,疑是地上霜。舉頭望明月,低頭思故鄉。",
107
- placeholder="請輸入文字...",
108
- lines=3
109
- )
110
- inference_button = gr.Button("🎤 語音合成", variant="primary")
111
- output = gr.Audio(label="🔊 合成的語音")
112
-
113
- inference_button.click(
114
- do_tts_wav_predict,
115
- [text],
116
- [output],
117
- )
118
-
119
  # 啟動 Gradio App
120
  app.queue(max_size=10)
121
  app.launch(share=True, inbrowser=True)
 
3
  @author:XuMing([email protected])
4
  @description: Re-train by TWMAN
5
  """
 
6
  import hashlib
7
  import os
8
  import ssl
9
  import subprocess
 
 
10
  import torch
11
  from loguru import logger
12
  import nltk
 
 
13
  from torch.serialization import add_safe_globals
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  # 設定 HTTPS context 避免證書錯誤
16
  ssl._create_default_https_context = ssl._create_unverified_context
17
 
 
33
  logger.info(f"device: {device}")
34
  half = True if device == "cuda" else False
35
 
36
+ # 允許全局類別 HParams
37
+ class DummyHParams:
38
+ pass
39
+
40
+ add_safe_globals([DummyHParams])
41
+
42
+ # 啟用 patch,強制設置 weights_only=False
43
+ _original_torch_load = torch.load
44
+ def patched_torch_load(*args, **kwargs):
45
+ kwargs['weights_only'] = False # 強制設置 weights_only=False
46
+ return _original_torch_load(*args, **kwargs)
47
+
48
+ torch.load = patched_torch_load
49
+
50
  # 初始化 TTS 模型
51
  m = TextToSpeech(
52
  speaker_model_path="DeepLearning101/GPT-SoVITS_TWMAN",
 
94
  - [基於機器閱讀理解和指令微調的統一信息抽取框架之診斷書醫囑資訊擷取分析](https://blog.twman.org/2023/07/HugIE.html)
95
  """)
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  # 啟動 Gradio App
98
  app.queue(max_size=10)
99
  app.launch(share=True, inbrowser=True)