Skip to content

Commit

Permalink
Update whispers2t_batch_gui.py
Browse files Browse the repository at this point in the history
Make setting cuda-related paths more robust.
  • Loading branch information
BBC-Esq committed Sep 17, 2024
1 parent 8f4ec19 commit 67d8d61
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions whispers2t_batch_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,29 @@
from whispers2t_batch_transcriber import Worker

def set_cuda_paths():
try:
venv_base = Path(sys.executable).parent
nvidia_base_path = venv_base / 'Lib' / 'site-packages' / 'nvidia'
for env_var in ['CUDA_PATH', 'CUDA_PATH_V12_1', 'PATH']:
current_path = os.environ.get(env_var, '')
os.environ[env_var] = os.pathsep.join(filter(None, [str(nvidia_base_path), current_path]))
logging.info("CUDA paths set successfully")
except Exception as e:
logging.error(f"Error setting CUDA paths: {str(e)}")
logging.debug(traceback.format_exc())
venv_base = Path(sys.executable).parent.parent
nvidia_base_path = venv_base / 'Lib' / 'site-packages' / 'nvidia'
cuda_path = nvidia_base_path / 'cuda_runtime' / 'bin'
cublas_path = nvidia_base_path / 'cublas' / 'bin'
cudnn_path = nvidia_base_path / 'cudnn' / 'bin'
paths_to_add = [str(cuda_path), str(cublas_path), str(cudnn_path)]
env_vars = ['CUDA_PATH', 'CUDA_PATH_V12_1', 'PATH']

# print(f"Virtual environment base: {venv_base}")
# print(f"NVIDIA base path: {nvidia_base_path}")
# print(f"CUDA path: {cuda_path}")
# print(f"cuBLAS path: {cublas_path}")
# print(f"cuDNN path: {cudnn_path}")

for env_var in env_vars:
current_value = os.environ.get(env_var, '')
new_value = os.pathsep.join(paths_to_add + [current_value] if current_value else paths_to_add)
os.environ[env_var] = new_value
# print(f"\n{env_var} updated:")
# print(f" Old value: {current_value}")
# print(f" New value: {new_value}")

# print("\nCUDA paths have been set or updated in the environment variables.")

set_cuda_paths()

Expand Down Expand Up @@ -221,4 +234,4 @@ def workerFinished(self, message):
app.setStyle("Fusion")
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec())
sys.exit(app.exec())

0 comments on commit 67d8d61

Please sign in to comment.