Spaces:
Sleeping
Sleeping
oceansweep
commited on
Commit
•
99313c7
1
Parent(s):
8904b33
Delete App_Function_Libraries/System_Checks_Lib.py
Browse files
App_Function_Libraries/System_Checks_Lib.py
DELETED
@@ -1,184 +0,0 @@
|
|
1 |
-
# System_Checks_Lib.py
|
2 |
-
#########################################
|
3 |
-
# System Checks Library
|
4 |
-
# This library is used to check the system for the necessary dependencies to run the script.
|
5 |
-
# It checks for the OS, the availability of the GPU, and the availability of the ffmpeg executable.
|
6 |
-
# If the GPU is available, it asks the user if they would like to use it for processing.
|
7 |
-
# If ffmpeg is not found, it asks the user if they would like to download it.
|
8 |
-
# The script will exit if the user chooses not to download ffmpeg.
|
9 |
-
####
|
10 |
-
|
11 |
-
####################
|
12 |
-
# Function List
|
13 |
-
#
|
14 |
-
# 1. platform_check()
|
15 |
-
# 2. cuda_check()
|
16 |
-
# 3. decide_cpugpu()
|
17 |
-
# 4. check_ffmpeg()
|
18 |
-
# 5. download_ffmpeg()
|
19 |
-
#
|
20 |
-
####################
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
# Import necessary libraries
|
26 |
-
import logging
|
27 |
-
import os
|
28 |
-
import platform
|
29 |
-
import requests
|
30 |
-
import shutil
|
31 |
-
import subprocess
|
32 |
-
import zipfile
|
33 |
-
# Import Local Libraries
|
34 |
-
#from App_Function_Libraries import
|
35 |
-
#
|
36 |
-
#######################################################################################################################
|
37 |
-
# Function Definitions
|
38 |
-
#
|
39 |
-
|
40 |
-
def platform_check():
|
41 |
-
global userOS
|
42 |
-
if platform.system() == "Linux":
|
43 |
-
print("Linux OS detected \n Running Linux appropriate commands")
|
44 |
-
userOS = "Linux"
|
45 |
-
elif platform.system() == "Windows":
|
46 |
-
print("Windows OS detected \n Running Windows appropriate commands")
|
47 |
-
userOS = "Windows"
|
48 |
-
else:
|
49 |
-
print("Other OS detected \n Maybe try running things manually?")
|
50 |
-
exit()
|
51 |
-
|
52 |
-
|
53 |
-
# Check for NVIDIA GPU and CUDA availability
|
54 |
-
def cuda_check():
|
55 |
-
global processing_choice
|
56 |
-
try:
|
57 |
-
# Run nvidia-smi to capture its output
|
58 |
-
nvidia_smi_output = subprocess.check_output("nvidia-smi", shell=True).decode()
|
59 |
-
|
60 |
-
# Look for CUDA version in the output
|
61 |
-
if "CUDA Version" in nvidia_smi_output:
|
62 |
-
cuda_version = next(
|
63 |
-
(line.split(":")[-1].strip() for line in nvidia_smi_output.splitlines() if "CUDA Version" in line),
|
64 |
-
"Not found")
|
65 |
-
print(f"NVIDIA GPU with CUDA Version {cuda_version} is available.")
|
66 |
-
processing_choice = "cuda"
|
67 |
-
else:
|
68 |
-
print("CUDA is not installed or configured correctly.")
|
69 |
-
processing_choice = "cpu"
|
70 |
-
|
71 |
-
except subprocess.CalledProcessError as e:
|
72 |
-
print(f"Failed to run 'nvidia-smi': {str(e)}")
|
73 |
-
processing_choice = "cpu"
|
74 |
-
except Exception as e:
|
75 |
-
print(f"An error occurred: {str(e)}")
|
76 |
-
processing_choice = "cpu"
|
77 |
-
|
78 |
-
# Optionally, check for the CUDA_VISIBLE_DEVICES env variable as an additional check
|
79 |
-
if "CUDA_VISIBLE_DEVICES" in os.environ:
|
80 |
-
print("CUDA_VISIBLE_DEVICES is set:", os.environ["CUDA_VISIBLE_DEVICES"])
|
81 |
-
else:
|
82 |
-
print("CUDA_VISIBLE_DEVICES not set.")
|
83 |
-
|
84 |
-
|
85 |
-
# Ask user if they would like to use either their GPU or their CPU for transcription
|
86 |
-
def decide_cpugpu():
|
87 |
-
global processing_choice
|
88 |
-
processing_input = input("Would you like to use your GPU or CPU for transcription? (1/cuda)GPU/(2/cpu)CPU): ")
|
89 |
-
if processing_choice == "cuda" and (processing_input.lower() == "cuda" or processing_input == "1"):
|
90 |
-
print("You've chosen to use the GPU.")
|
91 |
-
logging.debug("GPU is being used for processing")
|
92 |
-
processing_choice = "cuda"
|
93 |
-
elif processing_input.lower() == "cpu" or processing_input == "2":
|
94 |
-
print("You've chosen to use the CPU.")
|
95 |
-
logging.debug("CPU is being used for processing")
|
96 |
-
processing_choice = "cpu"
|
97 |
-
else:
|
98 |
-
print("Invalid choice. Please select either GPU or CPU.")
|
99 |
-
|
100 |
-
|
101 |
-
# check for existence of ffmpeg
|
102 |
-
def check_ffmpeg():
|
103 |
-
if shutil.which("ffmpeg") or (os.path.exists("Bin") and os.path.isfile(".\\Bin\\ffmpeg.exe")):
|
104 |
-
logging.debug("ffmpeg found installed on the local system, in the local PATH, or in the './Bin' folder")
|
105 |
-
pass
|
106 |
-
else:
|
107 |
-
logging.debug("ffmpeg not installed on the local system/in local PATH")
|
108 |
-
print(
|
109 |
-
"ffmpeg is not installed.\n\n You can either install it manually, or through your package manager of "
|
110 |
-
"choice.\n Windows users, builds are here: https://www.gyan.dev/ffmpeg/builds/")
|
111 |
-
if userOS == "Windows":
|
112 |
-
download_ffmpeg()
|
113 |
-
elif userOS == "Linux":
|
114 |
-
print(
|
115 |
-
"You should install ffmpeg using your platform's appropriate package manager, 'apt install ffmpeg',"
|
116 |
-
"'dnf install ffmpeg' or 'pacman', etc.")
|
117 |
-
else:
|
118 |
-
logging.debug("running an unsupported OS")
|
119 |
-
print("You're running an unspported/Un-tested OS")
|
120 |
-
exit_script = input("Let's exit the script, unless you're feeling lucky? (y/n)")
|
121 |
-
if exit_script == "y" or "yes" or "1":
|
122 |
-
exit()
|
123 |
-
|
124 |
-
|
125 |
-
# Download ffmpeg
|
126 |
-
def download_ffmpeg():
|
127 |
-
user_choice = input("Do you want to download ffmpeg? (y)Yes/(n)No: ")
|
128 |
-
if user_choice.lower() in ['yes', 'y', '1']:
|
129 |
-
print("Downloading ffmpeg")
|
130 |
-
url = "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip"
|
131 |
-
response = requests.get(url)
|
132 |
-
|
133 |
-
if response.status_code == 200:
|
134 |
-
print("Saving ffmpeg zip file")
|
135 |
-
logging.debug("Saving ffmpeg zip file")
|
136 |
-
zip_path = "ffmpeg-release-essentials.zip"
|
137 |
-
with open(zip_path, 'wb') as file:
|
138 |
-
file.write(response.content)
|
139 |
-
|
140 |
-
logging.debug("Extracting the 'ffmpeg.exe' file from the zip")
|
141 |
-
print("Extracting ffmpeg.exe from zip file to '/Bin' folder")
|
142 |
-
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
143 |
-
# Find the ffmpeg.exe file within the zip
|
144 |
-
ffmpeg_path = None
|
145 |
-
for file_info in zip_ref.infolist():
|
146 |
-
if file_info.filename.endswith("ffmpeg.exe"):
|
147 |
-
ffmpeg_path = file_info.filename
|
148 |
-
break
|
149 |
-
|
150 |
-
if ffmpeg_path is None:
|
151 |
-
logging.error("ffmpeg.exe not found in the zip file.")
|
152 |
-
print("ffmpeg.exe not found in the zip file.")
|
153 |
-
return
|
154 |
-
|
155 |
-
logging.debug("checking if the './Bin' folder exists, creating if not")
|
156 |
-
bin_folder = "Bin"
|
157 |
-
if not os.path.exists(bin_folder):
|
158 |
-
logging.debug("Creating a folder for './Bin', it didn't previously exist")
|
159 |
-
os.makedirs(bin_folder)
|
160 |
-
|
161 |
-
logging.debug("Extracting 'ffmpeg.exe' to the './Bin' folder")
|
162 |
-
zip_ref.extract(ffmpeg_path, path=bin_folder)
|
163 |
-
|
164 |
-
logging.debug("Moving 'ffmpeg.exe' to the './Bin' folder")
|
165 |
-
src_path = os.path.join(bin_folder, ffmpeg_path)
|
166 |
-
dst_path = os.path.join(bin_folder, "ffmpeg.exe")
|
167 |
-
shutil.move(src_path, dst_path)
|
168 |
-
|
169 |
-
logging.debug("Removing ffmpeg zip file")
|
170 |
-
print("Deleting zip file (we've already extracted ffmpeg.exe, no worries)")
|
171 |
-
os.remove(zip_path)
|
172 |
-
|
173 |
-
logging.debug("ffmpeg.exe has been downloaded and extracted to the './Bin' folder.")
|
174 |
-
print("ffmpeg.exe has been successfully downloaded and extracted to the './Bin' folder.")
|
175 |
-
else:
|
176 |
-
logging.error("Failed to download the zip file.")
|
177 |
-
print("Failed to download the zip file.")
|
178 |
-
else:
|
179 |
-
logging.debug("User chose to not download ffmpeg")
|
180 |
-
print("ffmpeg will not be downloaded.")
|
181 |
-
|
182 |
-
#
|
183 |
-
#
|
184 |
-
#######################################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|