crazydev919 commited on
Commit
0147335
Β·
verified Β·
1 Parent(s): 930ab0c

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -1,6 +1,6 @@
1
 
2
  import gradio as gr
3
- import torch, yaml, os, sys, glob
4
  import librosa
5
  import soundfile as sf
6
  import torchaudio
@@ -12,6 +12,37 @@ nltk.download("punkt_tab", quiet=True)
12
 
13
  # ── Clone StyleTTS2 ────────────────────────────────────────
14
  os.system("git clone https://github.com/yl4579/StyleTTS2 /app/StyleTTS2 2>/dev/null || true")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  sys.path.insert(0, "/app/StyleTTS2")
16
  os.chdir("/app/StyleTTS2")
17
 
 
1
 
2
  import gradio as gr
3
+ import torch, yaml, os, sys, glob, re
4
  import librosa
5
  import soundfile as sf
6
  import torchaudio
 
12
 
13
  # ── Clone StyleTTS2 ────────────────────────────────────────
14
  os.system("git clone https://github.com/yl4579/StyleTTS2 /app/StyleTTS2 2>/dev/null || true")
15
+
16
+ # ── Patch models.py for PyTorch 2.6 weights_only ──────────
17
+ models_path = "/app/StyleTTS2/models.py"
18
+ with open(models_path) as f:
19
+ code = f.read()
20
+
21
+ patched = re.sub(
22
+ r'torch\.load\(([^)]+)\)',
23
+ lambda m: m.group(0) if 'weights_only' in m.group(1)
24
+ else f'torch.load({m.group(1)}, weights_only=False)',
25
+ code
26
+ )
27
+ with open(models_path, "w") as f:
28
+ f.write(patched)
29
+
30
+ # Also patch utils.py
31
+ utils_path = "/app/StyleTTS2/utils.py"
32
+ with open(utils_path) as f:
33
+ code2 = f.read()
34
+
35
+ patched2 = re.sub(
36
+ r'torch\.load\(([^)]+)\)',
37
+ lambda m: m.group(0) if 'weights_only' in m.group(1)
38
+ else f'torch.load({m.group(1)}, weights_only=False)',
39
+ code2
40
+ )
41
+ with open(utils_path, "w") as f:
42
+ f.write(patched2)
43
+
44
+ print("βœ… Patched torch.load calls")
45
+
46
  sys.path.insert(0, "/app/StyleTTS2")
47
  os.chdir("/app/StyleTTS2")
48