Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -112,79 +112,87 @@ if chatterbox_available:
|
|
112 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
113 |
print(f"Using device: {device}")
|
114 |
|
115 |
-
#
|
|
|
|
|
|
|
116 |
try:
|
117 |
-
# Method 1:
|
118 |
-
model = ChatterboxTTS.from_local(LOCAL_MODEL_PATH)
|
119 |
print("Chatterbox model loaded successfully using from_local method.")
|
120 |
except Exception as e1:
|
121 |
print(f"from_local attempt failed: {e1}")
|
122 |
try:
|
123 |
-
# Method 2:
|
124 |
-
model = ChatterboxTTS.from_pretrained(
|
125 |
print("Chatterbox model loaded successfully with from_pretrained.")
|
126 |
except Exception as e2:
|
127 |
print(f"from_pretrained failed: {e2}")
|
128 |
try:
|
129 |
-
# Method 3:
|
|
|
130 |
import pathlib
|
|
|
|
|
131 |
model_path = pathlib.Path(LOCAL_MODEL_PATH)
|
132 |
|
133 |
-
|
|
|
|
|
134 |
s3gen_path = model_path / "s3gen.pt"
|
135 |
ve_path = model_path / "ve.pt"
|
136 |
tokenizer_path = model_path / "tokenizer.json"
|
137 |
t3_cfg_path = model_path / "t3_cfg.pt"
|
138 |
|
139 |
-
print(f"Loading
|
140 |
-
print(f" s3gen: {s3gen_path}")
|
141 |
-
print(f" ve: {ve_path}")
|
142 |
-
print(f" tokenizer: {tokenizer_path}")
|
143 |
-
print(f" t3_cfg: {t3_cfg_path}")
|
144 |
-
|
145 |
-
# Load components with CPU mapping
|
146 |
s3gen = torch.load(s3gen_path, map_location=torch.device('cpu'))
|
|
|
|
|
147 |
ve = torch.load(ve_path, map_location=torch.device('cpu'))
|
|
|
|
|
148 |
t3_cfg = torch.load(t3_cfg_path, map_location=torch.device('cpu'))
|
149 |
|
150 |
-
|
151 |
-
import json
|
152 |
with open(tokenizer_path, 'r') as f:
|
153 |
-
|
154 |
-
|
155 |
-
print("Components loaded, creating ChatterboxTTS instance...")
|
156 |
|
157 |
-
#
|
|
|
158 |
try:
|
159 |
-
|
160 |
-
|
161 |
-
print("
|
162 |
-
except Exception as
|
163 |
-
print(f"
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
torch.load = patched_load
|
179 |
-
try:
|
180 |
-
model = ChatterboxTTS.from_local(LOCAL_MODEL_PATH)
|
181 |
-
print("Chatterbox model loaded with patched torch.load.")
|
182 |
-
finally:
|
183 |
-
torch.load = original_load
|
184 |
|
185 |
except Exception as e3:
|
186 |
print(f"Manual loading failed: {e3}")
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
except Exception as e:
|
190 |
print(f"ERROR: Failed to load Chatterbox model from local directory: {e}")
|
|
|
112 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
113 |
print(f"Using device: {device}")
|
114 |
|
115 |
+
# Based on API inspection:
|
116 |
+
# ChatterboxTTS.from_local signature: (ckpt_dir, device) -> 'ChatterboxTTS'
|
117 |
+
# ChatterboxTTS.from_pretrained signature: (device) -> 'ChatterboxTTS'
|
118 |
+
|
119 |
try:
|
120 |
+
# Method 1: Use from_local with correct signature (ckpt_dir, device)
|
121 |
+
model = ChatterboxTTS.from_local(LOCAL_MODEL_PATH, device)
|
122 |
print("Chatterbox model loaded successfully using from_local method.")
|
123 |
except Exception as e1:
|
124 |
print(f"from_local attempt failed: {e1}")
|
125 |
try:
|
126 |
+
# Method 2: Use from_pretrained with device only
|
127 |
+
model = ChatterboxTTS.from_pretrained(device)
|
128 |
print("Chatterbox model loaded successfully with from_pretrained.")
|
129 |
except Exception as e2:
|
130 |
print(f"from_pretrained failed: {e2}")
|
131 |
try:
|
132 |
+
# Method 3: Manual loading with correct constructor signature
|
133 |
+
# ChatterboxTTS.__init__ signature: (self, t3, s3gen, ve, tokenizer, device, conds=None)
|
134 |
import pathlib
|
135 |
+
import json
|
136 |
+
|
137 |
model_path = pathlib.Path(LOCAL_MODEL_PATH)
|
138 |
|
139 |
+
print(f"Manual loading with correct constructor signature...")
|
140 |
+
|
141 |
+
# Load all components
|
142 |
s3gen_path = model_path / "s3gen.pt"
|
143 |
ve_path = model_path / "ve.pt"
|
144 |
tokenizer_path = model_path / "tokenizer.json"
|
145 |
t3_cfg_path = model_path / "t3_cfg.pt"
|
146 |
|
147 |
+
print(f" Loading s3gen from: {s3gen_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
s3gen = torch.load(s3gen_path, map_location=torch.device('cpu'))
|
149 |
+
|
150 |
+
print(f" Loading ve from: {ve_path}")
|
151 |
ve = torch.load(ve_path, map_location=torch.device('cpu'))
|
152 |
+
|
153 |
+
print(f" Loading t3_cfg from: {t3_cfg_path}")
|
154 |
t3_cfg = torch.load(t3_cfg_path, map_location=torch.device('cpu'))
|
155 |
|
156 |
+
print(f" Loading tokenizer from: {tokenizer_path}")
|
|
|
157 |
with open(tokenizer_path, 'r') as f:
|
158 |
+
tokenizer_data = json.load(f)
|
|
|
|
|
159 |
|
160 |
+
# The tokenizer might need to be instantiated as a proper object
|
161 |
+
# Let's try to use the ChatterboxTTS internal tokenizer class
|
162 |
try:
|
163 |
+
from chatterbox.models.tokenizers.tokenizer import EnTokenizer
|
164 |
+
tokenizer = EnTokenizer.from_dict(tokenizer_data)
|
165 |
+
print(" Created EnTokenizer from JSON data")
|
166 |
+
except Exception as tok_error:
|
167 |
+
print(f" Could not create EnTokenizer: {tok_error}")
|
168 |
+
tokenizer = tokenizer_data # Use raw data as fallback
|
169 |
+
|
170 |
+
print(" Creating ChatterboxTTS instance with correct signature...")
|
171 |
+
|
172 |
+
# Constructor signature: (self, t3, s3gen, ve, tokenizer, device, conds=None)
|
173 |
+
model = ChatterboxTTS(
|
174 |
+
t3=t3_cfg,
|
175 |
+
s3gen=s3gen,
|
176 |
+
ve=ve,
|
177 |
+
tokenizer=tokenizer,
|
178 |
+
device=device
|
179 |
+
)
|
180 |
+
print("Chatterbox model loaded successfully with manual constructor.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
except Exception as e3:
|
183 |
print(f"Manual loading failed: {e3}")
|
184 |
+
print(f"Detailed error: {str(e3)}")
|
185 |
+
|
186 |
+
# Last resort: try with different parameter orders
|
187 |
+
try:
|
188 |
+
print("Trying alternative parameter order...")
|
189 |
+
model = ChatterboxTTS(
|
190 |
+
s3gen, ve, tokenizer, t3_cfg, device
|
191 |
+
)
|
192 |
+
print("Chatterbox model loaded with alternative parameter order.")
|
193 |
+
except Exception as e4:
|
194 |
+
print(f"Alternative parameter order failed: {e4}")
|
195 |
+
raise e3
|
196 |
|
197 |
except Exception as e:
|
198 |
print(f"ERROR: Failed to load Chatterbox model from local directory: {e}")
|