tonyassi commited on
Commit
055ba4e
·
verified ·
1 Parent(s): d24bb6c

fix: monkey-patch torch.load to default weights_only=False (torch 2.6+ broke TTS checkpoint loading); drop invalid enable_queue arg

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,15 +1,25 @@
1
  import spaces
2
  import gradio as gr
3
  import torch
4
- from TTS.api import TTS
5
  import os
 
 
 
 
 
 
 
 
 
6
  os.environ["COQUI_TOS_AGREED"] = "1"
7
 
 
 
8
  device = "cuda"
9
 
10
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
11
 
12
- @spaces.GPU(enable_queue=True)
13
  def clone(text, audio):
14
  tts.tts_to_file(text=text, speaker_wav=audio, language="en", file_path="./output.wav")
15
  return "./output.wav"
@@ -38,4 +48,4 @@ iface = gr.Interface(fn=clone,
38
  ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.","./audio/Megan-Fox.mp3"],
39
  ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.","./audio/Jeff-Goldblum.mp3"],
40
  ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.","./audio/Heath-Ledger.mp3"],])
41
- iface.launch()
 
1
  import spaces
2
  import gradio as gr
3
  import torch
 
4
  import os
5
+
6
+ # torch >= 2.6 defaults torch.load(weights_only=True), which breaks TTS's
7
+ # pickle-based config loading. Restore the older behavior before TTS imports.
8
+ _orig_torch_load = torch.load
9
+ def _patched_torch_load(*args, **kwargs):
10
+ kwargs.setdefault("weights_only", False)
11
+ return _orig_torch_load(*args, **kwargs)
12
+ torch.load = _patched_torch_load
13
+
14
  os.environ["COQUI_TOS_AGREED"] = "1"
15
 
16
+ from TTS.api import TTS
17
+
18
  device = "cuda"
19
 
20
  tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to(device)
21
 
22
+ @spaces.GPU
23
  def clone(text, audio):
24
  tts.tts_to_file(text=text, speaker_wav=audio, language="en", file_path="./output.wav")
25
  return "./output.wav"
 
48
  ["Hey, it's me Megan Fox from Transformers. Type in whatever you'd like me to say.","./audio/Megan-Fox.mp3"],
49
  ["Hey there, it's me Jeff Goldblum. Type in whatever you'd like me to say.","./audio/Jeff-Goldblum.mp3"],
50
  ["Hey there, it's me Heath Ledger as the Joker. Type in whatever you'd like me to say.","./audio/Heath-Ledger.mp3"],])
51
+ iface.launch()