Add files via upload

This commit is contained in:
FatihMakes authored and GitHub committed 2026-06-14 17:04:27 +03:00
1 parent 5d8d214e9b
commit fb46b5e6a1
6 files changed
+129 -22

No files matched your search

+24 -7
View File
@@ -11,13 +11,22 @@ import threading
from pathlib import Path
from typing import Optional
from playwright.async_api import (
async_playwright,
BrowserContext,
Page,
Playwright,
TimeoutError as PlaywrightTimeout,
)
try:
from playwright.async_api import (
async_playwright,
BrowserContext,
Page,
Playwright,
TimeoutError as PlaywrightTimeout,
)
_PLAYWRIGHT_OK = True
except ImportError:
_PLAYWRIGHT_OK = False
async_playwright = None # type: ignore[assignment]
BrowserContext = None # type: ignore[assignment]
Page = None # type: ignore[assignment]
Playwright = None # type: ignore[assignment]
PlaywrightTimeout = Exception # type: ignore[assignment,misc]
_OS = platform.system() # "Windows" | "Darwin" | "Linux"
def _normalize_url(url: str) -> str:
@@ -807,6 +816,14 @@ def browser_control(
player=None,
session_memory=None,
) -> str:
if not _PLAYWRIGHT_OK:
msg = (
"Playwright is not installed.\n"
"Fix: pip install playwright && python -m playwright install chromium"
)
_log(player, msg)
return msg
params = parameters or {}
action = params.get("action", "").lower().strip()
browser = params.get("browser", "").lower().strip() or None
-3
View File
@@ -9,9 +9,6 @@ from pathlib import Path
from datetime import datetime
from urllib.parse import quote_plus
import pyautogui
import numpy as np
try:
import requests
_REQUESTS_OK = True
+35 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
+35 -3
View File
@@ -1138,6 +1138,11 @@ class JarvisLocal:
except Exception as e:
print(f"[STT-Whisper] Mic error: {e}")
traceback.print_exc()
self.ui.write_log(
f"ERR: Microphone — {e}\n"
" Check: microphone plugged in, OS privacy permissions granted, "
"correct audio device selected in system settings."
)
def _listen_vosk(self) -> None:
"""Mic → Vosk streaming → LLM loop."""
@@ -1172,6 +1177,11 @@ class JarvisLocal:
except Exception as e:
print(f"[STT-Vosk] Mic error: {e}")
traceback.print_exc()
self.ui.write_log(
f"ERR: Microphone — {e}\n"
" Check: microphone plugged in, OS privacy permissions granted, "
"correct audio device selected in system settings."
)
# ------------------------------------------------------------------
# Text command loop (UI input box)
@@ -1203,10 +1213,11 @@ class JarvisLocal:
self.ui.on_reconfigure = self.reconfigure
# ── Ollama ────────────────────────────────────────────────────
from core.llm_client import ensure_ollama_running, warmup_model
from core.llm_client import ensure_ollama_running, warmup_model, check_model_available
self.ui.write_log("SYS: Checking Ollama…")
if ensure_ollama_running():
self.ui.write_log("SYS: Ollama OK.")
check_model_available(log=self.ui.write_log)
else:
self.ui.write_log("ERR: Ollama unavailable — run: ollama serve")
@@ -1230,8 +1241,29 @@ class JarvisLocal:
# static prefix → Ollama reuses cached KV → first token <1 s
# instead of the ~17 s it takes to re-evaluate 300+ tokens cold.
static_prompt = _load_system_prompt()
warmup_model(system_prompt=static_prompt)
self.ui.write_log("SYS: LLM ready.")
ok = warmup_model(system_prompt=static_prompt)
if ok:
self.ui.write_log("SYS: LLM ready.")
else:
# warmup() returned False — check if model is missing
from core.llm_client import check_model_available
if not check_model_available(log=self.ui.write_log):
pass # warning already written by check_model_available
else:
self.ui.write_log("WRN: LLM warmup failed — is Ollama running?")
# GPU usage tip (cross-platform, non-blocking)
try:
import torch
if torch.cuda.is_available():
self.ui.write_log(f"SYS: GPU detected — {torch.cuda.get_device_name(0)}")
else:
self.ui.write_log(
"WRN: CUDA not detected — LLM running on CPU (slow). "
"For GPU speed install CUDA PyTorch: "
"pip install torch --index-url https://download.pytorch.org/whl/cu118"
)
except Exception:
pass # torch not installed or not applicable
self.ui.mark_startup_ready("llm")
except Exception as e:
self.ui.write_log(f"ERR: LLM warmup — {e}")