@@ -227,14 +227,14 @@ def get_model_info() -> Dict[str, Any]:
227227
228228
229229def get_model_registry () -> Dict [str , Dict [str , Any ]]:
230- """Returns the full model registry for the UI dropdown, filtered by availability ."""
230+ """Returns the full model registry for the UI dropdown. All models are always selectable ."""
231231 result = {}
232232 for k , v in MODEL_REGISTRY .items ():
233- available = True
233+ installed = True
234234 if v ["model_type" ] == "dia1" and not DIA1_AVAILABLE :
235- available = False
235+ installed = False
236236 if v ["model_type" ] == "dia2" and not DIA2_AVAILABLE :
237- available = False
237+ installed = False
238238 result [k ] = {
239239 "display_name" : v ["display_name" ],
240240 "params" : v ["params" ],
@@ -243,7 +243,8 @@ def get_model_registry() -> Dict[str, Dict[str, Any]]:
243243 "default_voice" : v ["default_voice" ],
244244 "supports_cloning" : v ["supports_cloning" ],
245245 "cloning_method" : v ["cloning_method" ],
246- "available" : available ,
246+ "available" : True , # Always selectable — will download/install on demand
247+ "installed" : installed ,
247248 }
248249 return result
249250
@@ -380,6 +381,38 @@ def get_compute_dtype(device: torch.device, weights_filename: str) -> str:
380381 return ComputeDtype .FLOAT32 .value # Return string value "float32"
381382
382383
384+ def _auto_install_dia2 ():
385+ """Attempts to install the dia2 package via pip at runtime."""
386+ global DIA2_AVAILABLE , Dia2 , GenerationConfig , SamplingConfig , PrefixConfig , GenerationResult
387+ import subprocess
388+ import sys
389+
390+ try :
391+ _check_cancelled ()
392+ result = subprocess .run (
393+ [sys .executable , "-m" , "pip" , "install" , "dia2" ],
394+ capture_output = True , text = True , timeout = 600 ,
395+ )
396+ if result .returncode != 0 :
397+ raise RuntimeError (f"pip install dia2 failed:\n { result .stderr } " )
398+
399+ logger .info ("dia2 package installed successfully. Importing..." )
400+ from dia2 import Dia2 as _Dia2 , GenerationConfig as _GC , SamplingConfig as _SC , PrefixConfig as _PC , GenerationResult as _GR
401+ Dia2 = _Dia2
402+ GenerationConfig = _GC
403+ SamplingConfig = _SC
404+ PrefixConfig = _PC
405+ GenerationResult = _GR
406+ DIA2_AVAILABLE = True
407+ logger .info ("dia2 package imported successfully after auto-install." )
408+ except Exception as e :
409+ logger .error (f"Failed to auto-install dia2: { e } " , exc_info = True )
410+ raise ImportError (
411+ f"dia2 package could not be installed automatically: { e } . "
412+ "Please install it manually: pip install dia2"
413+ )
414+
415+
383416def load_model ():
384417 """
385418 Loads a TTS model based on the current config selector.
@@ -402,11 +435,17 @@ def load_model():
402435 model_type = reg ["model_type" ]
403436 repo_id = reg ["repo_id" ]
404437
405- # Check availability
438+ # Check availability — auto-install if missing
406439 if model_type == "dia1" and not DIA1_AVAILABLE :
407- raise ImportError ("Dia 1 (dia) package is not installed. Cannot load Dia 1.6B model." )
440+ raise ImportError (
441+ "Dia 1 (dia) package is not installed. "
442+ "The local 'dia/' directory with model code is required. "
443+ "Please check that the repository was cloned completely."
444+ )
408445 if model_type == "dia2" and not DIA2_AVAILABLE :
409- raise ImportError ("Dia 2 (dia2) package is not installed. Cannot load Dia 2 models." )
446+ logger .info ("dia2 package not found. Attempting to install it automatically..." )
447+ _update_download_status ("installing" , "Installing dia2 package (pip install dia2)..." , 5 )
448+ _auto_install_dia2 ()
410449
411450 cache_path = get_model_cache_path ()
412451 model_device = get_device ()
0 commit comments