Spaces:
Running
Running
Add version info display and environment details to UI
Browse filesIntroduce version_info.py to collect and display dependency, system, and Git commit information. Update app.py to show this info in the Gradio interface with custom styling. Add functions for CUDA resource management and environment introspection.
- app.py +12 -1
- modules/version_info.py +120 -0
- pre-requirements.txt +2 -2
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import open3d as o3d
|
|
| 7 |
import torch
|
| 8 |
from PIL import Image
|
| 9 |
from transformers import DPTForDepthEstimation, DPTImageProcessor
|
|
|
|
| 10 |
|
| 11 |
# Initialize the image processor and depth estimation model
|
| 12 |
image_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
|
|
@@ -165,6 +166,14 @@ description = (
|
|
| 165 |
"<a href='https://huggingface.co/spaces/nielsr/dpt-depth-estimation' target='_blank'>DPT Demo</a>. "
|
| 166 |
"It uses the DPT model to predict the depth of an image and then uses 3D Point Cloud to create a 3D object."
|
| 167 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
# Create Gradio sliders for resized_width and z_scale
|
| 169 |
resized_width_slider = gr.Slider(
|
| 170 |
minimum=256,
|
|
@@ -189,7 +198,7 @@ process_image.zerogpu = True
|
|
| 189 |
#gr.set_static_paths(paths=["models/","examples/"])
|
| 190 |
iface = gr.Interface(
|
| 191 |
fn=process_image,
|
| 192 |
-
|
| 193 |
gr.Image(type="filepath", label="Input Image"),
|
| 194 |
resized_width_slider,
|
| 195 |
z_scale_slider
|
|
@@ -201,6 +210,8 @@ iface = gr.Interface(
|
|
| 201 |
],
|
| 202 |
title=title,
|
| 203 |
description=description,
|
|
|
|
|
|
|
| 204 |
examples=examples,
|
| 205 |
examples_per_page=15,
|
| 206 |
flagging_mode=None,
|
|
|
|
| 7 |
import torch
|
| 8 |
from PIL import Image
|
| 9 |
from transformers import DPTForDepthEstimation, DPTImageProcessor
|
| 10 |
+
from modules.version_info import versions_html
|
| 11 |
|
| 12 |
# Initialize the image processor and depth estimation model
|
| 13 |
image_processor = DPTImageProcessor.from_pretrained("Intel/dpt-large")
|
|
|
|
| 166 |
"<a href='https://huggingface.co/spaces/nielsr/dpt-depth-estimation' target='_blank'>DPT Demo</a>. "
|
| 167 |
"It uses the DPT model to predict the depth of an image and then uses 3D Point Cloud to create a 3D object."
|
| 168 |
)
|
| 169 |
+
css = """
|
| 170 |
+
#versions {
|
| 171 |
+
margin-top: 1em;
|
| 172 |
+
width: 100%;
|
| 173 |
+
text-align: center;
|
| 174 |
+
}
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
# Create Gradio sliders for resized_width and z_scale
|
| 178 |
resized_width_slider = gr.Slider(
|
| 179 |
minimum=256,
|
|
|
|
| 198 |
#gr.set_static_paths(paths=["models/","examples/"])
|
| 199 |
iface = gr.Interface(
|
| 200 |
fn=process_image,
|
| 201 |
+
inputs=[
|
| 202 |
gr.Image(type="filepath", label="Input Image"),
|
| 203 |
resized_width_slider,
|
| 204 |
z_scale_slider
|
|
|
|
| 210 |
],
|
| 211 |
title=title,
|
| 212 |
description=description,
|
| 213 |
+
article=f'<div id="versions" class="version-info">{versions_html()}</div>',
|
| 214 |
+
css=css,
|
| 215 |
examples=examples,
|
| 216 |
examples_per_page=15,
|
| 217 |
flagging_mode=None,
|
modules/version_info.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# version_info.py
|
| 2 |
+
|
| 3 |
+
import subprocess
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import gc
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
git = os.environ.get('GIT', "git")
|
| 10 |
+
|
| 11 |
+
def commit_hash():
|
| 12 |
+
try:
|
| 13 |
+
return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip()
|
| 14 |
+
except Exception:
|
| 15 |
+
return "<none>"
|
| 16 |
+
|
| 17 |
+
def get_xformers_version():
|
| 18 |
+
try:
|
| 19 |
+
import xformers
|
| 20 |
+
return xformers.__version__
|
| 21 |
+
except Exception:
|
| 22 |
+
return "<none>"
|
| 23 |
+
def get_transformers_version():
|
| 24 |
+
try:
|
| 25 |
+
import transformers
|
| 26 |
+
return transformers.__version__
|
| 27 |
+
except Exception:
|
| 28 |
+
return "<none>"
|
| 29 |
+
|
| 30 |
+
def get_accelerate_version():
|
| 31 |
+
try:
|
| 32 |
+
import accelerate
|
| 33 |
+
return accelerate.__version__
|
| 34 |
+
except Exception:
|
| 35 |
+
return "<none>"
|
| 36 |
+
def get_safetensors_version():
|
| 37 |
+
try:
|
| 38 |
+
import safetensors
|
| 39 |
+
return safetensors.__version__
|
| 40 |
+
except Exception:
|
| 41 |
+
return "<none>"
|
| 42 |
+
def get_diffusers_version():
|
| 43 |
+
try:
|
| 44 |
+
import diffusers
|
| 45 |
+
return diffusers.__version__
|
| 46 |
+
except Exception:
|
| 47 |
+
return "<none>"
|
| 48 |
+
|
| 49 |
+
def get_torch_info():
|
| 50 |
+
from torch import __version__ as torch_version_, version, cuda, backends
|
| 51 |
+
device_type = initialize_cuda()
|
| 52 |
+
if device_type == "cuda":
|
| 53 |
+
try:
|
| 54 |
+
info = [torch_version_, f"CUDA Version:{version.cuda}", f"Available:{cuda.is_available()}", f"flash attention enabled: {backends.cuda.flash_sdp_enabled()}", f"Capabilities: {cuda.get_device_capability(0)}", f"Device Name: {cuda.get_device_name(0)}", f"Device Count: {cuda.device_count()}"]
|
| 55 |
+
del torch_version_, version, cuda, backends
|
| 56 |
+
return info
|
| 57 |
+
except Exception:
|
| 58 |
+
del torch_version_, version, cuda, backends
|
| 59 |
+
return "<none>"
|
| 60 |
+
else:
|
| 61 |
+
return "Not Recognized"
|
| 62 |
+
|
| 63 |
+
def release_torch_resources():
|
| 64 |
+
from torch import cuda
|
| 65 |
+
# Clear the CUDA cache
|
| 66 |
+
cuda.empty_cache()
|
| 67 |
+
cuda.ipc_collect()
|
| 68 |
+
# Delete any objects that are using GPU memory
|
| 69 |
+
#for obj in gc.get_objects():
|
| 70 |
+
# if is_tensor(obj) or (hasattr(obj, 'data') and is_tensor(obj.data)):
|
| 71 |
+
# del obj
|
| 72 |
+
# Run garbage collection
|
| 73 |
+
del cuda
|
| 74 |
+
gc.collect()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def initialize_cuda():
|
| 78 |
+
from torch import cuda, version
|
| 79 |
+
if cuda.is_available():
|
| 80 |
+
device = cuda.device("cuda")
|
| 81 |
+
print(f"CUDA is available. Using device: {cuda.get_device_name(0)} with CUDA version: {version.cuda}")
|
| 82 |
+
result = "cuda"
|
| 83 |
+
else:
|
| 84 |
+
print("CUDA is not available. Using CPU.")
|
| 85 |
+
result = "cpu"
|
| 86 |
+
return result
|
| 87 |
+
|
| 88 |
+
def versions_html():
|
| 89 |
+
from torch import __version__ as torch_version_
|
| 90 |
+
python_version = ".".join([str(x) for x in sys.version_info[0:3]])
|
| 91 |
+
commit = commit_hash()
|
| 92 |
+
|
| 93 |
+
# Define the Toggle Dark Mode link with JavaScript
|
| 94 |
+
toggle_dark_link = '''
|
| 95 |
+
<a href="#" onclick="document.body.classList.toggle('dark'); return false;" style="cursor: pointer; text-decoration: underline;">
|
| 96 |
+
Toggle Dark Mode
|
| 97 |
+
</a>
|
| 98 |
+
'''
|
| 99 |
+
|
| 100 |
+
v_html = f"""
|
| 101 |
+
version: <a href="https://huggingface.co/spaces/Surn/DPTDepth3D/commit/{"huggingface" if commit == "<none>" else commit}" target="_blank">{"huggingface" if commit == "<none>" else commit}</a>
|
| 102 |
+
 • 
|
| 103 |
+
python: <span title="{sys.version}">{python_version}</span>
|
| 104 |
+
 • 
|
| 105 |
+
torch: {torch_version_}
|
| 106 |
+
 • 
|
| 107 |
+
xformers: {get_xformers_version()}
|
| 108 |
+
 • 
|
| 109 |
+
transformers: {get_transformers_version()}
|
| 110 |
+
 • 
|
| 111 |
+
safetensors: {get_safetensors_version()}
|
| 112 |
+
 • 
|
| 113 |
+
gradio: {gr.__version__}
|
| 114 |
+
 • 
|
| 115 |
+
{toggle_dark_link}
|
| 116 |
+
<br>
|
| 117 |
+
Full GPU Info:{get_torch_info()}
|
| 118 |
+
"""
|
| 119 |
+
del torch_version_
|
| 120 |
+
return v_html
|
pre-requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
pip>=25.1.1
|
| 2 |
-
torch>=2.
|
| 3 |
-
torchvision>=0.
|
|
|
|
| 1 |
pip>=25.1.1
|
| 2 |
+
torch>=2.5.0
|
| 3 |
+
torchvision>=0.20.0
|