Spaces:
Sleeping
Sleeping
Update app.py
Browse files29 unmodified lines3031323334353334353637414243444546473839404142435244545545464748495051585253545556575859606162636465666768697071727374757629 unmodified linesrepo_id = "Praha-Labs/PrahaTTS-ML"
def load_model(): print(f"Loading base Chatterbox model on {device}...") model = ChatterboxTTS.from_pretrained(device=device) print("Downloading custom Indic tokenizer and config...") try: tokenizer_path = hf_hub_download(repo_id=repo_id, filename="tokenizer_indic.json") config_path = hf_hub_download(repo_id=repo_id, filename="config_indic.py") # 1. OVERRIDE THE TOKENIZER PROPERLY # Instead of 'load_from_file', we must instantiate the Chatterbox EnTokenizer class directly. model.tokenizer = EnTokenizer(tokenizer_path) print("Indic Tokenizer successfully injected.")
# 2. DYNAMICALLY LOAD THE CONFIG SCRIPT # This prevents the English text cleaner from stripping out Malayalam characters. # 1. DYNAMICALLY LOAD THE CONFIG SCRIPT FIRST! # This patches the Chatterbox character/symbol lists before the model initializes. spec = importlib.util.spec_from_file_location("config_indic", config_path) config_indic = importlib.util.module_from_spec(spec) spec.loader.exec_module(config_indic) # If the config script provides a specific override function, call it if hasattr(config_indic, 'apply_config'): config_indic.apply_config(model) print("Indic Configuration/Alphabet applied.") try: config_indic.apply_config() except TypeError: pass # Try again later if it requires the model object print("Indic Configuration applied. Vocabulary patched.") except Exception as e: print(f"Error during tokenizer/config load: {e}") print(f"Error during config load: {e}")
# 2. NOW LOAD THE BASE MODEL # It will now initialize its PyTorch embeddings using the NEW patched vocabulary size! print(f"Loading base Chatterbox model on {device}...") model = ChatterboxTTS.from_pretrained(device=device) # Run the override again if it specifically required the initialized model object if hasattr(config_indic, 'apply_config'): try: config_indic.apply_config(model) except TypeError: pass
# 3. APPLY TOKENIZER try: model.tokenizer = EnTokenizer(tokenizer_path) print("Indic Tokenizer successfully injected.") except Exception as e: print(f"Error during tokenizer inject: {e}")
# 4. LOAD LORA ADAPTER print("Loading LoRA adapter weights...") try: if hasattr(model, 't3'):app.py+28-14