fix: Improve Whisper model status verification and PyInstaller builds
- Add robust model cache verification (check model.bin + config.json) - Add new status messages: model_cached, incomplete_cache, model_error - Forward model status events to frontend for better UI feedback - Add clean_build_cache() to remove stale spec files before build - Add --clean flag to PyInstaller commands - Change sidecar from --onefile to --onedir for faster startup - Add missing hidden imports: onnxruntime, wave, huggingface_hub.utils 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,14 +10,40 @@ import os
|
||||
import shutil
|
||||
|
||||
|
||||
def clean_build_cache(script_dir):
|
||||
"""Clean old build artifacts that may cause stale spec file issues."""
|
||||
dirs_to_clean = [
|
||||
os.path.join(script_dir, "build"),
|
||||
os.path.join(script_dir, "__pycache__"),
|
||||
]
|
||||
files_to_clean = [
|
||||
os.path.join(script_dir, "build", "backend.spec"),
|
||||
]
|
||||
|
||||
for f in files_to_clean:
|
||||
if os.path.exists(f):
|
||||
print(f"Removing old spec file: {f}")
|
||||
os.remove(f)
|
||||
|
||||
for d in dirs_to_clean:
|
||||
pycache = os.path.join(d)
|
||||
if os.path.exists(pycache) and "__pycache__" in pycache:
|
||||
print(f"Removing cache: {pycache}")
|
||||
shutil.rmtree(pycache)
|
||||
|
||||
|
||||
def build():
|
||||
"""Build the backend executable."""
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
# Clean old build cache to avoid stale spec file issues
|
||||
clean_build_cache(script_dir)
|
||||
|
||||
# PyInstaller command with --onedir for faster startup
|
||||
cmd = [
|
||||
sys.executable, "-m", "PyInstaller",
|
||||
"--onedir",
|
||||
"--clean", # Clean PyInstaller cache before building
|
||||
"--name", "backend",
|
||||
"--distpath", "dist",
|
||||
"--workpath", "build",
|
||||
@@ -39,9 +65,11 @@ def build():
|
||||
"--hidden-import", "starlette",
|
||||
"--hidden-import", "pydantic",
|
||||
"--hidden-import", "pydantic_core",
|
||||
# Database
|
||||
# Database - MySQL
|
||||
"--hidden-import", "mysql.connector",
|
||||
"--hidden-import", "mysql.connector.pooling",
|
||||
# Database - SQLite (built-in, but ensure it's included)
|
||||
"--hidden-import", "sqlite3",
|
||||
# HTTP client
|
||||
"--hidden-import", "httpx",
|
||||
"--hidden-import", "httpcore",
|
||||
@@ -56,7 +84,9 @@ def build():
|
||||
"--hidden-import", "python_multipart",
|
||||
# Environment loading
|
||||
"--hidden-import", "dotenv",
|
||||
# Application modules
|
||||
# Timezone data
|
||||
"--hidden-import", "tzdata",
|
||||
# Application modules - only include modules that exist
|
||||
"--hidden-import", "app",
|
||||
"--hidden-import", "app.main",
|
||||
"--hidden-import", "app.config",
|
||||
|
||||
Reference in New Issue
Block a user