Skip to content

Commit 252db2d

Browse files
committed
Fix model selector, voice dropdown width, and torchcodec dep
- All Dia 2 models always selectable in dropdown (never disabled) - Auto-install dia2 package via pip when user selects a Dia 2 model - Predefined voice dropdown capped at max-width 320px - Added torchcodec to requirements.txt (required by newer torchaudio)
1 parent 824dbee commit 252db2d

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

engine.py

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ def get_model_info() -> Dict[str, Any]:
227227

228228

229229
def 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+
383416
def 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()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ soundfile # Requires libsndfile system library (e.g., sudo apt-get install libsn
1212
huggingface_hub
1313
descript-audio-codec
1414
safetensors
15+
torchcodec
1516
openai-whisper
1617

1718
# Configuration & Utilities

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h2 class="card-header">Generate Speech with Dia</h2>
374374
<div id="predefined-voice-options" class="mb-6 hidden">
375375
<label for="predefined_voice_select" class="label-base">Select Predefined Voice (use
376376
voice pairs for dialogues):</label>
377-
<select id="predefined_voice_select" name="predefined_voice_select" class="select-base">
377+
<select id="predefined_voice_select" name="predefined_voice_select" class="select-base" style="max-width: 320px;">
378378
<option value="none">-- Select Voice --</option>
379379
{% for voice in predefined_voices %}
380380
<option value="{{ voice.filename }}" {% if

ui/script.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ document.addEventListener('DOMContentLoaded', function () {
413413
for (const [selector, info] of Object.entries(modelRegistry)) {
414414
const option = document.createElement('option');
415415
option.value = selector;
416-
option.textContent = info.display_name + (info.available === false ? ' (not installed)' : '');
417-
option.disabled = info.available === false;
416+
option.textContent = info.display_name;
418417
modelSelect.appendChild(option);
419418
}
420419
}

0 commit comments

Comments
 (0)