Fix bugs, N+1 queries, and wire settings in persian-tutor

- Replace inline __import__("datetime").timedelta hack with proper import
- Remove unused import random in anki_export.py
- Add error handling for Claude CLI subprocess failures in ai.py
- Fix hardcoded absolute path in stt.py with relative Path resolution
- Fix N+1 DB queries in vocab.get_flashcard_batch and dashboard.get_category_breakdown
  by adding db.get_all_word_progress() batch query
- Wire Ollama model and Whisper size settings to actually update config
  via ai.set_ollama_model() and stt.set_whisper_size()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dl92
2026-02-08 15:40:24 +00:00
parent 8b5eb8797f
commit 3a8705ece8
7 changed files with 57 additions and 12 deletions

View File

@@ -1,13 +1,17 @@
"""Persian speech-to-text wrapper using sttlib."""
import sys
from pathlib import Path
import numpy as np
sys.path.insert(0, "/home/ys/family-repo/Code/python/tool-speechtotext")
# sttlib lives in sibling project tool-speechtotext
_sttlib_path = str(Path(__file__).resolve().parent.parent / "tool-speechtotext")
sys.path.insert(0, _sttlib_path)
from sttlib import load_whisper_model, transcribe, is_hallucination
_model = None
_whisper_size = "medium"
# Common Whisper hallucinations in Persian/silence
PERSIAN_HALLUCINATIONS = [
@@ -18,11 +22,19 @@ PERSIAN_HALLUCINATIONS = [
]
def get_model(size="medium"):
def set_whisper_size(size):
"""Change the Whisper model size. Reloads on next transcription."""
global _whisper_size, _model
if size != _whisper_size:
_whisper_size = size
_model = None
def get_model():
"""Load Whisper model (cached singleton)."""
global _model
if _model is None:
_model = load_whisper_model(size)
_model = load_whisper_model(_whisper_size)
return _model