Add files via upload
This commit is contained in:
1 parent
5d8d214e9b
commit
fb46b5e6a1
6 files changed
+129
-22
No files matched your search
+35
-1
@@ -22,7 +22,7 @@ import subprocess
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Generator
|
||||
from typing import Callable, Generator
|
||||
|
||||
import requests
|
||||
|
||||
@@ -184,6 +184,40 @@ def warmup_model(system_prompt: str | None = None) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def check_model_available(log: Callable | None = None) -> bool:
|
||||
"""
|
||||
Returns True if the configured model is already pulled in Ollama.
|
||||
Logs an actionable warning (to console + optional UI callback) if not.
|
||||
Always returns True for non-Ollama providers (cannot inspect their model list).
|
||||
"""
|
||||
if get_llm_provider() != "ollama":
|
||||
return True
|
||||
|
||||
url, model = get_llm_settings()
|
||||
try:
|
||||
resp = requests.get(f"{url}/api/tags", timeout=5)
|
||||
resp.raise_for_status()
|
||||
pulled = [m.get("name", "") for m in resp.json().get("models", [])]
|
||||
model_base = model.split(":")[0]
|
||||
found = any(
|
||||
m == model or m == model_base or m.startswith(model_base + ":")
|
||||
for m in pulled
|
||||
)
|
||||
if not found:
|
||||
available = ", ".join(pulled) if pulled else "none"
|
||||
warn = (
|
||||
f"WRN: Model '{model}' is not pulled in Ollama.\n"
|
||||
f" Available: {available}\n"
|
||||
f" Fix: ollama pull {model}"
|
||||
)
|
||||
print(warn)
|
||||
if log:
|
||||
log(f"WRN: '{model}' not found — run: ollama pull {model}")
|
||||
return found
|
||||
except Exception:
|
||||
return True # Ollama might still be starting up; non-blocking
|
||||
|
||||
|
||||
def get_llm_settings() -> tuple[str, str]:
|
||||
"""Returns (base_url, model_name)."""
|
||||
cfg = _load_config()
|
||||
|
||||
+17
-4
@@ -25,14 +25,27 @@ class WhisperSTT:
|
||||
try:
|
||||
self._model = WhisperModel(model_name, device=device, compute_type=compute)
|
||||
except Exception as _first_err:
|
||||
# Offline flag set but model not cached yet → download once, then offline forever
|
||||
# Offline flag set but model not cached yet → clear flags and download once.
|
||||
# Keywords cover multiple huggingface_hub error message variants across versions.
|
||||
_e = str(_first_err).lower()
|
||||
if any(k in _e for k in ("offline", "not found", "cache", "localentry", "does not exist")):
|
||||
print(f"[STT] '{model_name}' not cached — downloading (internet required for first run)…")
|
||||
_offline_keywords = (
|
||||
"offline", "not found", "cache", "localentry",
|
||||
"does not exist", "outgoing", "local_files_only",
|
||||
)
|
||||
if any(k in _e for k in _offline_keywords):
|
||||
print(f"[STT] Whisper '{model_name}' not in local cache — downloading (one-time, internet required)…")
|
||||
os.environ.pop("HF_HUB_OFFLINE", None)
|
||||
os.environ.pop("TRANSFORMERS_OFFLINE", None)
|
||||
os.environ.pop("HF_DATASETS_OFFLINE", None)
|
||||
self._model = WhisperModel(model_name, device=device, compute_type=compute)
|
||||
try:
|
||||
self._model = WhisperModel(model_name, device=device, compute_type=compute)
|
||||
except Exception as _dl_err:
|
||||
raise RuntimeError(
|
||||
f"Whisper '{model_name}' model download failed.\n"
|
||||
f"Internet access is required the first time to download the speech model (~75–290 MB).\n"
|
||||
f"After the first download it runs fully offline.\n"
|
||||
f"Details: {_dl_err}"
|
||||
) from _dl_err
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
+18
-4
@@ -273,14 +273,28 @@ class KokoroTTSEngine:
|
||||
try:
|
||||
self._pipeline = _create_pipeline()
|
||||
except Exception as _first_err:
|
||||
# Offline flag set but model not cached yet → download once
|
||||
# Offline flag set but model not cached yet → clear flags and download once.
|
||||
# Keywords cover multiple huggingface_hub error message variants across versions.
|
||||
_e = str(_first_err).lower()
|
||||
if any(k in _e for k in ("offline", "not found", "cache", "localentry", "does not exist")):
|
||||
print("[TTS] Kokoro model not cached — downloading (internet required for first run)…")
|
||||
_offline_keywords = (
|
||||
"offline", "not found", "cache", "localentry",
|
||||
"does not exist", "outgoing", "local_files_only",
|
||||
)
|
||||
if any(k in _e for k in _offline_keywords):
|
||||
print("[TTS] Kokoro model not in local cache — downloading (one-time, internet required)…")
|
||||
os.environ.pop("HF_HUB_OFFLINE", None)
|
||||
os.environ.pop("TRANSFORMERS_OFFLINE", None)
|
||||
os.environ.pop("HF_DATASETS_OFFLINE", None)
|
||||
self._pipeline = _create_pipeline()
|
||||
try:
|
||||
self._pipeline = _create_pipeline()
|
||||
except Exception as _dl_err:
|
||||
raise RuntimeError(
|
||||
f"Kokoro model download failed.\n"
|
||||
f"Internet access is required the first time to download the voice model (~330 MB).\n"
|
||||
f"After the first download it runs fully offline.\n"
|
||||
f"Tip: Switch to EdgeTTS (free, no download) in the Configure panel if offline.\n"
|
||||
f"Details: {_dl_err}"
|
||||
) from _dl_err
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
Reference in new issue
Block a user