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:
@@ -1,29 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Build script for creating standalone transcriber executable using PyInstaller.
|
||||
Uses --onedir mode for faster startup compared to --onefile.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
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", "transcriber.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 transcriber executable."""
|
||||
# PyInstaller command
|
||||
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",
|
||||
"--onefile",
|
||||
"--onedir",
|
||||
"--clean", # Clean PyInstaller cache before building
|
||||
"--name", "transcriber",
|
||||
"--distpath", "dist",
|
||||
"--workpath", "build",
|
||||
"--specpath", "build",
|
||||
# Core dependencies
|
||||
"--hidden-import", "faster_whisper",
|
||||
"--hidden-import", "opencc",
|
||||
"--hidden-import", "numpy",
|
||||
"--hidden-import", "ctranslate2",
|
||||
"--hidden-import", "huggingface_hub",
|
||||
"--hidden-import", "huggingface_hub.utils",
|
||||
"--hidden-import", "tokenizers",
|
||||
# ONNX Runtime for VAD
|
||||
"--hidden-import", "onnxruntime",
|
||||
# Audio processing
|
||||
"--hidden-import", "wave",
|
||||
# Collect data files
|
||||
"--collect-data", "faster_whisper",
|
||||
"--collect-data", "opencc",
|
||||
"transcriber.py"
|
||||
@@ -32,10 +69,12 @@ def build():
|
||||
print("Building transcriber executable...")
|
||||
print(f"Command: {' '.join(cmd)}")
|
||||
|
||||
result = subprocess.run(cmd, cwd=os.path.dirname(os.path.abspath(__file__)))
|
||||
result = subprocess.run(cmd, cwd=script_dir)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("\nBuild successful! Executable created at: dist/transcriber")
|
||||
print("\nBuild successful!")
|
||||
print("Executable created at: dist/transcriber/transcriber.exe (Windows) or dist/transcriber/transcriber (Linux)")
|
||||
print("\nNote: The Whisper model will be downloaded on first run if not cached.")
|
||||
else:
|
||||
print("\nBuild failed!")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user