Validate offline configuration and model disk requirements
This commit is contained in:
parent
dd92bf9f3e
commit
fd416feea8
3 changed files with 24 additions and 2 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from collections.abc import Callable, Iterator
|
from collections.abc import Callable, Iterator
|
||||||
|
|
@ -171,6 +172,8 @@ class ModelManager:
|
||||||
with self._lock(model_id):
|
with self._lock(model_id):
|
||||||
if self.is_installed(model_id):
|
if self.is_installed(model_id):
|
||||||
return path
|
return path
|
||||||
|
if shutil.disk_usage(self.models_dir).free < spec.size + 16 * 1024 * 1024:
|
||||||
|
raise ModelError("Недостаточно свободного места для скачивания модели")
|
||||||
partial = path.with_suffix(".bin.part")
|
partial = path.with_suffix(".bin.part")
|
||||||
if partial.is_symlink():
|
if partial.is_symlink():
|
||||||
raise ModelError("Временный путь модели не должен быть символической ссылкой")
|
raise ModelError("Временный путь модели не должен быть символической ссылкой")
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ def build_recognition_tab(
|
||||||
"""Build controls; all widget updates stay on the Tk main thread."""
|
"""Build controls; all widget updates stay on the Tk main thread."""
|
||||||
config = store.load()
|
config = store.load()
|
||||||
manager = ModelManager(paths.models_dir)
|
manager = ModelManager(paths.models_dir)
|
||||||
labels = {f"{m.name} — {m.size_bytes / 1048576:.0f} МБ": m.id for m in CATALOG}
|
labels = {m.name: m.id for m in CATALOG}
|
||||||
initial_label = next(
|
initial_label = next(
|
||||||
(k for k, v in labels.items() if v == config.local_model), next(iter(labels))
|
(k for k, v in labels.items() if v == config.local_model), next(iter(labels))
|
||||||
)
|
)
|
||||||
|
|
@ -42,7 +42,9 @@ def build_recognition_tab(
|
||||||
justify="left",
|
justify="left",
|
||||||
wraplength=620,
|
wraplength=620,
|
||||||
).pack(anchor="w", padx=12, pady=8)
|
).pack(anchor="w", padx=12, pady=8)
|
||||||
ctk.CTkLabel(parent, text="Локальная модель (Whisper):").pack(anchor="w", padx=12)
|
ctk.CTkLabel(
|
||||||
|
parent, text="Локальная модель (Whisper; только CPU/Metal, macOS arm64 beta):"
|
||||||
|
).pack(anchor="w", padx=12)
|
||||||
ctk.CTkOptionMenu(parent, values=list(labels), variable=selected, width=460).pack(
|
ctk.CTkOptionMenu(parent, values=list(labels), variable=selected, width=460).pack(
|
||||||
anchor="w", padx=12, pady=6
|
anchor="w", padx=12, pady=6
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -145,3 +145,20 @@ def test_local_long_wav_splits_without_ffmpeg(tmp_paths):
|
||||||
with wave.open(str(chunk.path), "rb") as audio:
|
with wave.open(str(chunk.path), "rb") as audio:
|
||||||
assert audio.getnframes() / audio.getframerate() <= 60.001
|
assert audio.getnframes() / audio.getframerate() <= 60.001
|
||||||
orchestrator.shutdown()
|
orchestrator.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
def test_checkpoint_model_change_is_rejected(tmp_paths):
|
||||||
|
from voice_dictation.core.models import RecordingResult
|
||||||
|
|
||||||
|
engine = FakeTranscriber()
|
||||||
|
config = Config(transcription_backend="local", paste_delay_ms=0)
|
||||||
|
orchestrator = _make_orchestrator(tmp_paths, transcriber=engine, config=config)
|
||||||
|
source = orchestrator._session_store.create()
|
||||||
|
source.write_bytes(b"audio")
|
||||||
|
recording = RecordingResult(source, 2)
|
||||||
|
orchestrator._transcribe_session(recording, config)
|
||||||
|
with pytest.raises(TranscriptionError, match="изменились"):
|
||||||
|
orchestrator._transcribe_session(
|
||||||
|
recording, Config(transcription_backend="local", local_model="whisper-small")
|
||||||
|
)
|
||||||
|
orchestrator.shutdown()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue