-
Notifications
You must be signed in to change notification settings - Fork 683
/
install.py
174 lines (154 loc) · 7.62 KB
/
install.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import os
import platform
import subprocess
import sys
import zipfile
import shutil
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
ascii_logo = """
__ ___ _ _ _
\ \ / (_) __| | ___ ___ | | (_)_ __ __ _ ___
\ \ / /| |/ _` |/ _ \/ _ \| | | | '_ \ / _` |/ _ \
\ V / | | (_| | __/ (_) | |___| | | | | (_| | (_) |
\_/ |_|\__,_|\___|\___/|_____|_|_| |_|\__, |\___/
|___/
"""
def install_package(*packages):
subprocess.check_call([sys.executable, "-m", "pip", "install", *packages])
def check_gpu():
try:
subprocess.run(['nvidia-smi'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
def main():
install_package("requests", "rich", "ruamel.yaml")
from rich.console import Console
from rich.panel import Panel
from rich.box import DOUBLE
console = Console()
width = max(len(line) for line in ascii_logo.splitlines()) + 4
welcome_panel = Panel(
ascii_logo,
width=width,
box=DOUBLE,
title="[bold green]🌏[/bold green]",
border_style="bright_blue"
)
console.print(welcome_panel)
console.print(Panel.fit("🚀 Starting Installation", style="bold magenta"))
# Configure mirrors
from core.pypi_autochoose import main as choose_mirror
choose_mirror()
# Detect system and GPU
if platform.system() == 'Darwin':
console.print(Panel("🍎 MacOS detected, installing CPU version of PyTorch... However, it would be extremely slow for transcription.", style="cyan"))
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.1.2", "torchaudio==2.1.2"])
else:
has_gpu = check_gpu()
if has_gpu:
console.print(Panel("🎮 NVIDIA GPU detected, installing CUDA version of PyTorch...", style="cyan"))
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.0.0", "torchaudio==2.0.0", "--index-url", "https://download.pytorch.org/whl/cu118"])
else:
console.print(Panel("💻 No NVIDIA GPU detected, installing CPU version of PyTorch... However, it would be extremely slow for transcription.", style="cyan"))
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.1.2", "torchaudio==2.1.2"])
# Install WhisperX
console.print(Panel("📦 Installing WhisperX...", style="cyan"))
current_dir = os.getcwd()
whisperx_dir = os.path.join(current_dir, "third_party", "whisperX")
os.chdir(whisperx_dir)
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])
os.chdir(current_dir)
def install_requirements():
try:
with open("requirements.txt", "r", encoding="utf-8") as file:
content = file.read()
with open("requirements.txt", "w", encoding="gbk") as file:
file.write(content)
except Exception as e:
print(f"Error converting requirements.txt: {str(e)}")
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
def download_and_extract_ffmpeg():
# VL requires both conda/system ffmpeg and ffmpeg.exe...
system = platform.system()
if system == "Linux":
# Linux: use apt or yum to install ffmpeg
try:
console.print(Panel("📦 Installing ffmpeg through apt...", style="cyan"))
subprocess.check_call(["sudo", "apt", "install", "-y", "ffmpeg"])
except subprocess.CalledProcessError:
try:
console.print(Panel("📦 Installing ffmpeg through yum...", style="cyan"))
subprocess.check_call(["sudo", "yum", "install", "-y", "ffmpeg"], shell=True)
except subprocess.CalledProcessError:
console.print(Panel("❌ Failed to install ffmpeg through package manager", style="red"))
else:
# Windows/MacOS: use conda to install ffmpeg
console.print(Panel("📦 Installing ffmpeg through conda...", style="cyan"))
subprocess.check_call(["conda", "install", "-y", "ffmpeg"], shell=True)
import requests
if system == "Windows":
ffmpeg_exe = "ffmpeg.exe"
url = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
elif system == "Darwin":
ffmpeg_exe = "ffmpeg"
url = "https://evermeet.cx/ffmpeg/getrelease/zip"
elif system == "Linux":
ffmpeg_exe = "ffmpeg"
url = "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz"
else:
return
if os.path.exists(ffmpeg_exe):
print(f"{ffmpeg_exe} already exists")
return
console.print(Panel("📦 Downloading FFmpeg...", style="cyan"))
response = requests.get(url)
if response.status_code == 200:
filename = "ffmpeg.zip" if system in ["Windows", "Darwin"] else "ffmpeg.tar.xz"
with open(filename, 'wb') as f:
f.write(response.content)
console.print(Panel(f"FFmpeg downloaded: {filename}", style="cyan"))
console.print(Panel("📦 Extracting FFmpeg...", style="cyan"))
if system == "Linux":
import tarfile
with tarfile.open(filename) as tar_ref:
for member in tar_ref.getmembers():
if member.name.endswith("ffmpeg"):
member.name = os.path.basename(member.name)
tar_ref.extract(member)
else:
with zipfile.ZipFile(filename, 'r') as zip_ref:
for file in zip_ref.namelist():
if file.endswith(ffmpeg_exe):
zip_ref.extract(file)
shutil.move(os.path.join(*file.split('/')[:-1], os.path.basename(file)), os.path.basename(file))
console.print(Panel("📦 Cleaning up...", style="cyan"))
os.remove(filename)
if system == "Windows":
for item in os.listdir():
if os.path.isdir(item) and "ffmpeg" in item.lower():
shutil.rmtree(item)
console.print(Panel("FFmpeg extraction completed", style="cyan"))
else:
console.print(Panel("❌ Failed to download FFmpeg", style="red"))
def install_noto_font():
if platform.system() == 'Linux':
try:
# Try apt-get first (Debian-based systems)
subprocess.run(['sudo', 'apt-get', 'install', '-y', 'fonts-noto'], check=True)
print("Noto fonts installed successfully using apt-get.")
except subprocess.CalledProcessError:
try:
# If apt-get fails, try yum (RPM-based systems)
subprocess.run(['sudo', 'yum', 'install', '-y', 'fonts-noto'], check=True)
print("Noto fonts installed successfully using yum.")
except subprocess.CalledProcessError:
print("Failed to install Noto fonts automatically. Please install them manually.")
install_noto_font()
install_requirements()
download_and_extract_ffmpeg()
console.print(Panel.fit("Installation completed", style="bold green"))
console.print("To start the application, run:")
console.print("[bold cyan]streamlit run st.py[/bold cyan]")
if __name__ == "__main__":
main()