rodrigomasini commited on
Commit
57c54da
·
verified ·
1 Parent(s): 3f05e5b

Delete app_backup.py

Browse files
Files changed (1) hide show
  1. app_backup.py +0 -131
app_backup.py DELETED
@@ -1,131 +0,0 @@
1
- # Contact us:
2
- import platform
3
- import sys
4
- import shutil
5
- import os
6
- import datetime
7
- import subprocess
8
- import gradio as gr
9
- import spaces
10
-
11
- @spaces.GPU(duration=120)
12
- def check_python():
13
- supported_minors = [9, 10, 11]
14
- python_info = f"Python {platform.python_version()} on {platform.system()}"
15
- if not (
16
- int(sys.version_info.major) == 3
17
- and int(sys.version_info.minor) in supported_minors
18
- ):
19
- python_info += f"\nIncompatible Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} required 3.{supported_minors}"
20
- return python_info
21
-
22
- def check_torch():
23
- torch_info = ""
24
- if shutil.which('nvidia-smi') is not None or os.path.exists(
25
- os.path.join(
26
- os.environ.get('SystemRoot') or r'C:\Windows',
27
- 'System32',
28
- 'nvidia-smi.exe',
29
- )
30
- ):
31
- torch_info += 'NVIDIA toolkit detected\n'
32
- elif shutil.which('rocminfo') is not None or os.path.exists('/opt/rocm/bin/rocminfo'):
33
- torch_info += 'AMD toolkit detected\n'
34
- elif (shutil.which('sycl-ls') is not None
35
- or os.environ.get('ONEAPI_ROOT') is not None
36
- or os.path.exists('/opt/intel/oneapi')):
37
- torch_info += 'Intel OneAPI toolkit detected\n'
38
- else:
39
- torch_info += 'Using CPU-only Torch\n'
40
-
41
- try:
42
- import torch
43
- try:
44
- import intel_extension_for_pytorch as ipex
45
- if torch.xpu.is_available():
46
- from library.ipex import ipex_init
47
- ipex_init()
48
- os.environ.setdefault('NEOReadDebugKeys', '1')
49
- os.environ.setdefault('ClDeviceGlobalMemSizeAvailablePercent', '100')
50
- except Exception:
51
- pass
52
- torch_info += f'Torch {torch.__version__}\n'
53
-
54
- if not torch.cuda.is_available():
55
- torch_info += 'Torch reports CUDA not available\n'
56
- else:
57
- if torch.version.cuda:
58
- if hasattr(torch, "xpu") and torch.xpu.is_available():
59
- torch_info += f'Torch backend: Intel IPEX OneAPI {ipex.__version__}\n'
60
- else:
61
- torch_info += f'Torch backend: NVIDIA CUDA {torch.version.cuda} cuDNN {torch.backends.cudnn.version() if torch.backends.cudnn.is_available() else "N/A"}\n'
62
- elif torch.version.hip:
63
- torch_info += f'Torch backend: AMD ROCm HIP {torch.version.hip}\n'
64
- else:
65
- torch_info += 'Unknown Torch backend\n'
66
-
67
- for device in [torch.cuda.device(i) for i in range(torch.cuda.device_count())]:
68
- if hasattr(torch, "xpu") and torch.xpu.is_available():
69
- torch_info += f'Torch detected GPU: {torch.xpu.get_device_name(device)} VRAM {round(torch.xpu.get_device_properties(device).total_memory / 1024 / 1024)} Compute Units {torch.xpu.get_device_properties(device).max_compute_units}\n'
70
- else:
71
- torch_info += f'Torch detected GPU: {torch.cuda.get_device_name(device)} VRAM {round(torch.cuda.get_device_properties(device).total_memory / 1024 / 1024)} Arch {torch.cuda.get_device_capability(device)} Cores {torch.cuda.get_device_properties(device).multi_processor_count}\n'
72
- return torch_info
73
- except Exception as e:
74
- return f'Could not load torch: {e}'
75
-
76
- def get_installed_packages():
77
- pkgs_installed = subprocess.getoutput("pip freeze")
78
- output_lines = [line for line in pkgs_installed.splitlines() if "WARNING" not in line]
79
- packages = []
80
- for line in output_lines:
81
- if '==' in line:
82
- pkg_name, pkg_version = line.split('==')
83
- packages.append((pkg_name, pkg_version))
84
- packages.sort(key=lambda x: x[0].lower())
85
- return packages
86
-
87
- def get_installed_packages_version():
88
- pkgs_installed = subprocess.getoutput("pip freeze")
89
- output_lines = [line for line in pkgs_installed.splitlines() if "WARNING" not in line]
90
- packages_version = []
91
- for line in output_lines:
92
- if '==' in line:
93
- pkg_name, pkg_version = line.split('==')
94
- packages_version.append((pkg_name, pkg_version))
95
- return packages_version
96
-
97
- def match_packages_with_versions():
98
- #local = pathlib.Path(__file__).parent
99
- requirements_file = os.path.join(os.path.dirname(__file__),"requirements.txt")
100
- with open(requirements_file, 'r') as f:
101
- requirements = f.read().splitlines()
102
-
103
- requirements = [req.split('==')[0] for req in requirements if req and not req.startswith('#')]
104
- installed_packages = get_installed_packages_version()
105
- installed_dict = {pkg: version for pkg, version in installed_packages}
106
-
107
- matched_packages = []
108
- for req in requirements:
109
- if req in installed_dict:
110
- matched_packages.append((req, installed_dict[req]))
111
- else:
112
- matched_packages.append((req, "Not installed"))
113
-
114
- return matched_packages
115
-
116
-
117
- def display_info():
118
- current_datetime = datetime.datetime.now()
119
- current_datetime_str = current_datetime.strftime('%m/%d/%Y-%H:%M:%S')
120
- python_info = check_python()
121
- torch_info = check_torch()
122
- packages = get_installed_packages()
123
- versions = match_packages_with_versions()
124
- return f"Machine local date and time: {current_datetime_str}\n\n{python_info}\n\n{torch_info}\n\nInstalled packages:\n{packages}\n\nMatched packages with versions:\n{versions}"
125
-
126
- with gr.Blocks() as demo:
127
- output = gr.Textbox(lines=20, label="System Information")
128
- btn = gr.Button("Check System")
129
- btn.click(display_info, inputs=[], outputs=[output])
130
-
131
- demo.launch()