Repository navigation
Expand file tree
/
Copy pathlaunch.py
More file actions
105 lines (92 loc) · 3.56 KB
/
Copy pathlaunch.py
File metadata and controls
105 lines (92 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""VideoLingo Enhanced Launcher - Pre-flight checks + logging."""
import subprocess, sys, os, shutil, socket
from pathlib import Path
from datetime import datetime
from runtime_libraries import configure_ffmpeg
SCRIPT_DIR = Path(__file__).resolve().parent
LOG_DIR = SCRIPT_DIR / "logs"
LOG_DIR.mkdir(exist_ok=True)
LOG_FILE = LOG_DIR / f"startup_{datetime.now():%Y%m%d_%H%M%S}.log"
def log(msg):
line = f"[{datetime.now():%H:%M:%S}] {msg}"
with open(LOG_FILE, "a", encoding="utf-8") as f:
f.write(line + "\n")
def check_package(name, import_name=None):
import_name = import_name or name
try:
mod = __import__(import_name)
return getattr(mod, "__version__", "ok")
except ImportError:
return None
def main():
errors = []
warnings = []
try:
configure_ffmpeg(required=True)
except RuntimeError as exc:
errors.append(str(exc))
# Python
log(f"Python: {sys.version.split()[0]} ({sys.executable})")
# Packages
for pkg, imp in [("streamlit", None), ("json_repair", "json_repair")]:
if not check_package(pkg, imp):
errors.append(f"{pkg} not installed. Run: python install.py")
# torch + CUDA
import platform
apple_silicon = platform.system() == "Darwin" and platform.machine() == "arm64"
torch_ver = check_package("torch")
if torch_ver:
import torch
if torch.cuda.is_available():
log(f"torch: {torch_ver}, cuda: {torch.version.cuda}, gpu: {torch.cuda.get_device_name(0)}")
elif apple_silicon:
# Local ASR runs on MLX here, not CUDA.
log(f"torch: {torch_ver} (Apple Silicon; local ASR uses MLX)")
elif shutil.which("nvidia-smi"):
warnings.append("NVIDIA GPU found but torch has no CUDA support. Reinstall: python installer.py")
log(f"torch: {torch_ver} (CPU only)")
else:
warnings.append("No NVIDIA GPU: local Qwen3-ASR runs on CPU and is slow (0.6B or ElevenLabs is faster).")
log(f"torch: {torch_ver} (CPU only)")
# Default local ASR is Qwen3-ASR (MLX on Apple Silicon). WhisperX is a separate manual install.
qwen = "mlx_audio" if apple_silicon else "qwen_asr"
if not check_package(qwen):
warnings.append(f"{qwen} not installed. Local Qwen ASR will fail. Run: python installer.py")
# Port
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
if s.connect_ex(("127.0.0.1", 8501)) == 0:
warnings.append("Port 8501 in use. Close other app or use --server.port 8502")
# Log everything
for w in warnings:
log(f"[WARN] {w}")
for e in errors:
log(f"[ERROR] {e}")
# Show problems if any, otherwise stay quiet
if errors:
print()
for e in errors:
print(f" [ERROR] {e}")
print(f"\n Fix errors above. Log: {LOG_FILE}\n")
sys.exit(1)
if warnings:
print()
for w in warnings:
print(f" [WARN] {w}")
print()
# Launch
log("Launching Streamlit...")
os.environ["PYTHONWARNINGS"] = "ignore"
try:
proc = subprocess.run(
[sys.executable, "-m", "streamlit", "run", "st.py",
"--logger.level", "error"],
cwd=str(SCRIPT_DIR),
)
if proc.returncode != 0:
log(f"Streamlit exited with code {proc.returncode}")
print(f"\n Streamlit crashed (code {proc.returncode}). See: {LOG_FILE}\n")
sys.exit(proc.returncode)
except KeyboardInterrupt:
log("Stopped by user")
if __name__ == "__main__":
main()