(pretrained_path, lora_path=None)
| 219 | |
| 220 | |
| 221 | def load_model(pretrained_path, lora_path=None): |
| 222 | global current_model |
| 223 | print(f"Loading model from {pretrained_path}...", file=sys.stderr) |
| 224 | |
| 225 | lora_config = None |
| 226 | lora_weights_path = None |
| 227 | |
| 228 | if lora_path: |
| 229 | full_lora_path = os.path.join("lora", lora_path) |
| 230 | if os.path.exists(full_lora_path): |
| 231 | lora_weights_path = full_lora_path |
| 232 | # Try to load LoRA config from lora_config.json |
| 233 | lora_config, _ = load_lora_config_from_checkpoint(full_lora_path) |
| 234 | if lora_config: |
| 235 | print(f"Loaded LoRA config from {full_lora_path}/lora_config.json", file=sys.stderr) |
| 236 | else: |
| 237 | # Fallback to default config for old checkpoints |
| 238 | lora_config = get_default_lora_config() |
| 239 | print("Using default LoRA config (lora_config.json not found)", file=sys.stderr) |
| 240 | |
| 241 | # Always init with a default LoRA config to allow hot-swapping later |
| 242 | if lora_config is None: |
| 243 | lora_config = get_default_lora_config() |
| 244 | |
| 245 | current_model = VoxCPM.from_pretrained( |
| 246 | hf_model_id=pretrained_path, |
| 247 | load_denoiser=False, |
| 248 | optimize=False, |
| 249 | lora_config=lora_config, |
| 250 | lora_weights_path=lora_weights_path, |
| 251 | ) |
| 252 | return "Model loaded successfully!" |
| 253 | |
| 254 | |
| 255 | def run_inference(text, prompt_wav, prompt_text, lora_selection, cfg_scale, steps, seed, pretrained_path=None): |
no test coverage detected
searching dependent graphs…