Spaces:
Running on A100
Running on A100
Commit ·
b787e4e
0
Parent(s):
update space
Browse files- .gitattributes +37 -0
- .gitignore +2 -0
- README.md +15 -0
- app.py +466 -0
- examples/dog.ply +3 -0
- examples/dozer.ply +3 -0
- examples/fiscus.ply +3 -0
- examples/plant.ply +3 -0
- requirements.txt +21 -0
- wheels/diff_gaussian_rasterization-0.0.0-cp312-cp312-linux_x86_64.whl +3 -0
- wheels/utils3d-0.0.2-py3-none-any.whl +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.ply filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
*.whl filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv/
|
| 2 |
+
weights/
|
README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: VoMP
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
python_version: 3.12
|
| 8 |
+
sdk_version: 6.2.0
|
| 9 |
+
app_file: app.py
|
| 10 |
+
pinned: true
|
| 11 |
+
license: apache-2.0
|
| 12 |
+
short_description: Volumetric physics materials for interactive worlds
|
| 13 |
+
suggested_hardware: a100-large
|
| 14 |
+
suggested_storage: medium
|
| 15 |
+
---
|
app.py
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import tempfile
|
| 4 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import matplotlib
|
| 8 |
+
|
| 9 |
+
matplotlib.use("Agg")
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
import matplotlib.colors as mcolors
|
| 12 |
+
from matplotlib.colorbar import ColorbarBase
|
| 13 |
+
import numpy as np
|
| 14 |
+
import plotly.graph_objects as go
|
| 15 |
+
import spaces
|
| 16 |
+
import torch
|
| 17 |
+
from huggingface_hub import snapshot_download
|
| 18 |
+
|
| 19 |
+
from vomp.inference import Vomp
|
| 20 |
+
from vomp.inference.utils import LazyLoadDino, save_materials
|
| 21 |
+
|
| 22 |
+
NUM_VIEWS = 150
|
| 23 |
+
PROPERTY_NAMES = ["youngs_modulus", "poissons_ratio", "density"]
|
| 24 |
+
PROPERTY_DISPLAY_NAMES = {
|
| 25 |
+
"youngs_modulus": "Young's Modulus",
|
| 26 |
+
"poissons_ratio": "Poisson's Ratio",
|
| 27 |
+
"density": "Density",
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
BLENDER_LINK = (
|
| 31 |
+
"https://download.blender.org/release/Blender3.0/blender-3.0.1-linux-x64.tar.xz"
|
| 32 |
+
)
|
| 33 |
+
BLENDER_INSTALLATION_PATH = "/tmp"
|
| 34 |
+
BLENDER_PATH = f"{BLENDER_INSTALLATION_PATH}/blender-3.0.1-linux-x64/blender"
|
| 35 |
+
|
| 36 |
+
EXAMPLES_DIR = "examples"
|
| 37 |
+
|
| 38 |
+
model_id = "nvidia/PhysicalAI-Simulation-VoMP-Model"
|
| 39 |
+
base_path = snapshot_download(repo_id=model_id, local_dir="weights")
|
| 40 |
+
print(os.listdir(base_path))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _preload_dino(model: Vomp) -> None:
|
| 44 |
+
print("Preloading DINO model...")
|
| 45 |
+
dino = LazyLoadDino(
|
| 46 |
+
model_name="dinov2_vitl14_reg",
|
| 47 |
+
device=model.device,
|
| 48 |
+
use_trt=getattr(model, "use_trt", False),
|
| 49 |
+
)
|
| 50 |
+
_ = dino.get_model()
|
| 51 |
+
_ = dino.get_transform()
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _install_blender():
|
| 55 |
+
if not os.path.exists(BLENDER_PATH):
|
| 56 |
+
print("Installing Blender...")
|
| 57 |
+
os.system("sudo apt-get update")
|
| 58 |
+
os.system(
|
| 59 |
+
"sudo apt-get install -y libxrender1 libxi6 libxkbcommon-x11-0 libsm6"
|
| 60 |
+
)
|
| 61 |
+
os.system(f"wget {BLENDER_LINK} -P {BLENDER_INSTALLATION_PATH}")
|
| 62 |
+
os.system(
|
| 63 |
+
f"tar -xvf {BLENDER_INSTALLATION_PATH}/blender-3.0.1-linux-x64.tar.xz -C {BLENDER_INSTALLATION_PATH}"
|
| 64 |
+
)
|
| 65 |
+
print("Blender installed successfully!")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _is_gaussian_splat(file_path: str) -> bool:
|
| 69 |
+
if not file_path.lower().endswith(".ply"):
|
| 70 |
+
return False
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
with open(file_path, "rb") as f:
|
| 74 |
+
header = b""
|
| 75 |
+
while True:
|
| 76 |
+
line = f.readline()
|
| 77 |
+
header += line
|
| 78 |
+
if b"end_header" in line:
|
| 79 |
+
break
|
| 80 |
+
if len(header) > 10000:
|
| 81 |
+
break
|
| 82 |
+
|
| 83 |
+
header_str = header.decode("utf-8", errors="ignore").lower()
|
| 84 |
+
gaussian_indicators = ["f_dc", "opacity", "scale_0", "rot_0"]
|
| 85 |
+
return any(indicator in header_str for indicator in gaussian_indicators)
|
| 86 |
+
except Exception:
|
| 87 |
+
return False
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _setup_examples():
|
| 91 |
+
"""Ensure examples directory exists."""
|
| 92 |
+
os.makedirs(EXAMPLES_DIR, exist_ok=True)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
_setup_examples()
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
print("Loading VoMP model...")
|
| 99 |
+
model = Vomp.from_checkpoint(
|
| 100 |
+
config_path="weights/inference.json",
|
| 101 |
+
geometry_checkpoint_dir="weights/geometry_transformer.pt",
|
| 102 |
+
matvae_checkpoint_dir="weights/matvae.safetensors",
|
| 103 |
+
normalization_params_path="weights/normalization_params.json",
|
| 104 |
+
)
|
| 105 |
+
print("VoMP model loaded successfully!")
|
| 106 |
+
_preload_dino(model)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _create_colorbar(
|
| 110 |
+
data: np.ndarray, property_name: str, output_path: str, colormap: str = "viridis"
|
| 111 |
+
) -> str:
|
| 112 |
+
fig, ax = plt.subplots(figsize=(6, 0.8))
|
| 113 |
+
fig.subplots_adjust(bottom=0.5)
|
| 114 |
+
ax.remove()
|
| 115 |
+
|
| 116 |
+
cmap = plt.cm.get_cmap(colormap)
|
| 117 |
+
norm = mcolors.Normalize(vmin=np.min(data), vmax=np.max(data))
|
| 118 |
+
|
| 119 |
+
cbar_ax = fig.add_axes([0.1, 0.4, 0.8, 0.35])
|
| 120 |
+
cb = ColorbarBase(cbar_ax, cmap=cmap, norm=norm, orientation="horizontal")
|
| 121 |
+
cb.ax.set_xlabel(
|
| 122 |
+
f"{PROPERTY_DISPLAY_NAMES.get(property_name, property_name)}", fontsize=10
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
plt.savefig(
|
| 126 |
+
output_path, dpi=150, bbox_inches="tight", facecolor="white", transparent=False
|
| 127 |
+
)
|
| 128 |
+
plt.close()
|
| 129 |
+
return output_path
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def _create_pointcloud_plot(
|
| 133 |
+
coords: np.ndarray,
|
| 134 |
+
values: np.ndarray,
|
| 135 |
+
property_name: str,
|
| 136 |
+
colormap: str = "viridis",
|
| 137 |
+
) -> go.Figure:
|
| 138 |
+
"""Create an interactive 3D colored point cloud plot."""
|
| 139 |
+
coords = np.asarray(coords, dtype=np.float32)
|
| 140 |
+
values = np.asarray(values, dtype=np.float32).reshape(-1)
|
| 141 |
+
if coords.ndim != 2 or coords.shape[1] != 3:
|
| 142 |
+
raise ValueError(f"coords must be (N,3), got {coords.shape}")
|
| 143 |
+
if values.shape[0] != coords.shape[0]:
|
| 144 |
+
raise ValueError(
|
| 145 |
+
f"values must be (N,), got {values.shape} for coords {coords.shape}"
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
fig = go.Figure(
|
| 149 |
+
data=[
|
| 150 |
+
go.Scatter3d(
|
| 151 |
+
x=coords[:, 0],
|
| 152 |
+
y=coords[:, 1],
|
| 153 |
+
z=coords[:, 2],
|
| 154 |
+
mode="markers",
|
| 155 |
+
marker={
|
| 156 |
+
"size": 2,
|
| 157 |
+
"color": values,
|
| 158 |
+
"colorscale": colormap,
|
| 159 |
+
"showscale": False,
|
| 160 |
+
"opacity": 0.9,
|
| 161 |
+
},
|
| 162 |
+
)
|
| 163 |
+
]
|
| 164 |
+
)
|
| 165 |
+
fig.update_layout(
|
| 166 |
+
title=f"{PROPERTY_DISPLAY_NAMES.get(property_name, property_name)} Point Cloud",
|
| 167 |
+
margin=dict(l=0, r=0, t=35, b=0),
|
| 168 |
+
scene=dict(
|
| 169 |
+
xaxis=dict(visible=False),
|
| 170 |
+
yaxis=dict(visible=False),
|
| 171 |
+
zaxis=dict(visible=False),
|
| 172 |
+
aspectmode="data",
|
| 173 |
+
bgcolor="rgb(20,20,20)",
|
| 174 |
+
),
|
| 175 |
+
paper_bgcolor="rgb(20,20,20)",
|
| 176 |
+
plot_bgcolor="rgb(20,20,20)",
|
| 177 |
+
showlegend=False,
|
| 178 |
+
)
|
| 179 |
+
return fig
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _create_material_visualizations(
|
| 183 |
+
material_file: str, output_dir: str
|
| 184 |
+
) -> Dict[str, Tuple[Any, str]]:
|
| 185 |
+
result = {}
|
| 186 |
+
data = np.load(material_file, allow_pickle=True)
|
| 187 |
+
|
| 188 |
+
if "voxel_data" in data:
|
| 189 |
+
voxel_data = data["voxel_data"]
|
| 190 |
+
coords = np.column_stack([voxel_data["x"], voxel_data["y"], voxel_data["z"]])
|
| 191 |
+
properties = {
|
| 192 |
+
"youngs_modulus": voxel_data["youngs_modulus"],
|
| 193 |
+
"poissons_ratio": voxel_data["poissons_ratio"],
|
| 194 |
+
"density": voxel_data["density"],
|
| 195 |
+
}
|
| 196 |
+
else:
|
| 197 |
+
if "voxel_coords_world" in data:
|
| 198 |
+
coords = data["voxel_coords_world"]
|
| 199 |
+
elif "query_coords_world" in data:
|
| 200 |
+
coords = data["query_coords_world"]
|
| 201 |
+
elif "coords" in data:
|
| 202 |
+
coords = data["coords"]
|
| 203 |
+
else:
|
| 204 |
+
print(f"Warning: No coordinate data found in {material_file}")
|
| 205 |
+
return result
|
| 206 |
+
|
| 207 |
+
properties = {}
|
| 208 |
+
property_mapping = {
|
| 209 |
+
"youngs_modulus": ["youngs_modulus", "young_modulus"],
|
| 210 |
+
"poissons_ratio": ["poissons_ratio", "poisson_ratio"],
|
| 211 |
+
"density": ["density"],
|
| 212 |
+
}
|
| 213 |
+
for prop_name, possible_names in property_mapping.items():
|
| 214 |
+
for name in possible_names:
|
| 215 |
+
if name in data:
|
| 216 |
+
properties[prop_name] = data[name]
|
| 217 |
+
break
|
| 218 |
+
|
| 219 |
+
center = (np.min(coords, axis=0) + np.max(coords, axis=0)) / 2
|
| 220 |
+
max_range = np.max(np.max(coords, axis=0) - np.min(coords, axis=0))
|
| 221 |
+
if max_range > 1e-10:
|
| 222 |
+
coords_normalized = (coords - center) / max_range
|
| 223 |
+
else:
|
| 224 |
+
coords_normalized = coords - center
|
| 225 |
+
|
| 226 |
+
for prop_name, prop_data in properties.items():
|
| 227 |
+
if prop_data is not None:
|
| 228 |
+
plot = _create_pointcloud_plot(coords_normalized, prop_data, prop_name)
|
| 229 |
+
colorbar_path = os.path.join(output_dir, f"{prop_name}_colorbar.png")
|
| 230 |
+
_create_colorbar(prop_data, prop_name, colorbar_path)
|
| 231 |
+
result[prop_name] = (plot, colorbar_path)
|
| 232 |
+
print(f"Created point cloud plot for {prop_name}")
|
| 233 |
+
|
| 234 |
+
return result
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
@spaces.GPU(duration=60)
|
| 238 |
+
@torch.no_grad()
|
| 239 |
+
def process_3d_model(input_file):
|
| 240 |
+
empty_result = (
|
| 241 |
+
None, # youngs_cloud
|
| 242 |
+
None, # youngs_colorbar
|
| 243 |
+
None, # poissons_cloud
|
| 244 |
+
None, # poissons_colorbar
|
| 245 |
+
None, # density_cloud
|
| 246 |
+
None, # density_colorbar
|
| 247 |
+
None, # materials file
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
if input_file is None:
|
| 251 |
+
return empty_result
|
| 252 |
+
|
| 253 |
+
output_dir = tempfile.mkdtemp(prefix="vomp_")
|
| 254 |
+
material_file = os.path.join(output_dir, "materials.npz")
|
| 255 |
+
|
| 256 |
+
try:
|
| 257 |
+
if _is_gaussian_splat(input_file):
|
| 258 |
+
print(f"Processing as Gaussian splat: {input_file}")
|
| 259 |
+
results = model.get_splat_materials(
|
| 260 |
+
input_file,
|
| 261 |
+
voxel_method="kaolin",
|
| 262 |
+
query_points="voxel_centers",
|
| 263 |
+
output_dir=output_dir,
|
| 264 |
+
)
|
| 265 |
+
else:
|
| 266 |
+
print(f"Processing as mesh: {input_file}")
|
| 267 |
+
_install_blender()
|
| 268 |
+
results = model.get_mesh_materials(
|
| 269 |
+
input_file,
|
| 270 |
+
blender_path=BLENDER_PATH,
|
| 271 |
+
query_points="voxel_centers",
|
| 272 |
+
output_dir=output_dir,
|
| 273 |
+
return_original_scale=True,
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
save_materials(results, material_file)
|
| 277 |
+
print(f"Materials saved to: {material_file}")
|
| 278 |
+
|
| 279 |
+
visualizations = _create_material_visualizations(material_file, output_dir)
|
| 280 |
+
|
| 281 |
+
youngs_cloud = visualizations.get("youngs_modulus", (None, None))[0]
|
| 282 |
+
youngs_colorbar = visualizations.get("youngs_modulus", (None, None))[1]
|
| 283 |
+
|
| 284 |
+
poissons_cloud = visualizations.get("poissons_ratio", (None, None))[0]
|
| 285 |
+
poissons_colorbar = visualizations.get("poissons_ratio", (None, None))[1]
|
| 286 |
+
|
| 287 |
+
density_cloud = visualizations.get("density", (None, None))[0]
|
| 288 |
+
density_colorbar = visualizations.get("density", (None, None))[1]
|
| 289 |
+
|
| 290 |
+
return (
|
| 291 |
+
youngs_cloud,
|
| 292 |
+
youngs_colorbar,
|
| 293 |
+
poissons_cloud,
|
| 294 |
+
poissons_colorbar,
|
| 295 |
+
density_cloud,
|
| 296 |
+
density_colorbar,
|
| 297 |
+
material_file,
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
except Exception as e:
|
| 301 |
+
print(f"Error processing 3D model: {e}")
|
| 302 |
+
raise gr.Error(f"Failed to process 3D model: {str(e)}")
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
css = """
|
| 306 |
+
.gradio-container {
|
| 307 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
.title-container {
|
| 311 |
+
text-align: center;
|
| 312 |
+
padding: 20px 0;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.badge-container {
|
| 316 |
+
display: flex;
|
| 317 |
+
justify-content: center;
|
| 318 |
+
gap: 8px;
|
| 319 |
+
flex-wrap: wrap;
|
| 320 |
+
margin-bottom: 20px;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
.badge-container a img {
|
| 324 |
+
height: 22px;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
h1 {
|
| 328 |
+
text-align: center;
|
| 329 |
+
font-size: 2.5rem;
|
| 330 |
+
margin-bottom: 0.5rem;
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
.subtitle {
|
| 334 |
+
text-align: center;
|
| 335 |
+
color: #666;
|
| 336 |
+
font-size: 1.1rem;
|
| 337 |
+
margin-bottom: 1.5rem;
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.input-column, .output-column {
|
| 341 |
+
min-height: 400px;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
.output-column .row {
|
| 345 |
+
display: flex !important;
|
| 346 |
+
flex-wrap: nowrap !important;
|
| 347 |
+
gap: 16px;
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
.output-column .row > .column {
|
| 351 |
+
flex: 1 1 50% !important;
|
| 352 |
+
min-width: 0 !important;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
.main-content {
|
| 356 |
+
display: flex;
|
| 357 |
+
flex-direction: column-reverse;
|
| 358 |
+
gap: 16px;
|
| 359 |
+
}
|
| 360 |
+
"""
|
| 361 |
+
|
| 362 |
+
title_md = """
|
| 363 |
+
<div class="title-container">
|
| 364 |
+
<h1>VoMP: Predicting Volumetric Mechanical Properties</h1>
|
| 365 |
+
<p class="subtitle">Feed-forward, fine-grained, physically based volumetric material properties from Splats, Meshes, NeRFs, and more.</p>
|
| 366 |
+
<div class="badge-container">
|
| 367 |
+
<a href="https://arxiv.org/abs/2510.22975"><img src='https://img.shields.io/badge/arXiv-VoMP-red' alt='Paper PDF'></a>
|
| 368 |
+
<a href='https://research.nvidia.com/labs/sil/projects/vomp/'><img src='https://img.shields.io/badge/Project_Page-VoMP-green' alt='Project Page'></a>
|
| 369 |
+
<a href='https://huggingface.co/nvidia/PhysicalAI-Simulation-VoMP-Model'><img src='https://img.shields.io/badge/%F0%9F%A4%97%20-Models-yellow'></a>
|
| 370 |
+
<a href='https://huggingface.co/datasets/nvidia/PhysicalAI-Robotics-PhysicalAssets-VoMP'><img src='https://img.shields.io/badge/%F0%9F%A4%97%20-GVM%20Dataset-yellow'></a>
|
| 371 |
+
</div>
|
| 372 |
+
</div>
|
| 373 |
+
"""
|
| 374 |
+
|
| 375 |
+
description_md = """
|
| 376 |
+
Upload a Gaussian Splat (.ply) or Mesh (.obj, .glb, .stl, .gltf) to predict volumetric mechanical properties (Young's modulus, Poisson's ratio, density) for realistic physics simulation.
|
| 377 |
+
|
| 378 |
+
### Tips for Best Results
|
| 379 |
+
|
| 380 |
+
- Make sure the input asset has textures
|
| 381 |
+
- Make sure the input asset is oriented y-up for best results
|
| 382 |
+
- Download the `.npz` artifact to inspect the full-resolution outputs with the viewer we provide in the code release.
|
| 383 |
+
"""
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
with gr.Blocks(css=css, title="VoMP") as demo:
|
| 387 |
+
gr.HTML(title_md)
|
| 388 |
+
gr.Markdown(description_md)
|
| 389 |
+
|
| 390 |
+
with gr.Column(elem_classes="main-content"):
|
| 391 |
+
with gr.Row():
|
| 392 |
+
with gr.Column(scale=1, elem_classes="input-column"):
|
| 393 |
+
gr.Markdown("### 📤 Input")
|
| 394 |
+
input_model = gr.Model3D(
|
| 395 |
+
label="Upload 3D Model",
|
| 396 |
+
clear_color=[1.0, 1.0, 1.0, 1.0],
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
submit_btn = gr.Button(
|
| 400 |
+
"🚀 Generate Materials", variant="primary", size="lg"
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
with gr.Column(scale=1, elem_classes="output-column"):
|
| 404 |
+
gr.Markdown("### 📥 Output - Material Properties")
|
| 405 |
+
|
| 406 |
+
# Row 1: Young's Modulus and Poisson's Ratio
|
| 407 |
+
with gr.Row():
|
| 408 |
+
with gr.Column(scale=1, min_width=200):
|
| 409 |
+
youngs_cloud = gr.Plot()
|
| 410 |
+
youngs_colorbar = gr.Image(height=50, show_label=False)
|
| 411 |
+
|
| 412 |
+
with gr.Column(scale=1, min_width=200):
|
| 413 |
+
poissons_cloud = gr.Plot()
|
| 414 |
+
poissons_colorbar = gr.Image(height=50, show_label=False)
|
| 415 |
+
|
| 416 |
+
# Row 2: Density and Download
|
| 417 |
+
with gr.Row():
|
| 418 |
+
with gr.Column(scale=1, min_width=200):
|
| 419 |
+
density_cloud = gr.Plot()
|
| 420 |
+
density_colorbar = gr.Image(height=50, show_label=False)
|
| 421 |
+
|
| 422 |
+
with gr.Column(scale=1, min_width=200):
|
| 423 |
+
gr.Markdown("#### 💾 Download")
|
| 424 |
+
output_file = gr.File(
|
| 425 |
+
label="Download Materials (.npz)",
|
| 426 |
+
file_count="single",
|
| 427 |
+
)
|
| 428 |
+
|
| 429 |
+
gr.Examples(
|
| 430 |
+
examples=[
|
| 431 |
+
[os.path.join(EXAMPLES_DIR, "plant.ply")],
|
| 432 |
+
[os.path.join(EXAMPLES_DIR, "dog.ply")],
|
| 433 |
+
[os.path.join(EXAMPLES_DIR, "dozer.ply")],
|
| 434 |
+
[os.path.join(EXAMPLES_DIR, "fiscus.ply")],
|
| 435 |
+
],
|
| 436 |
+
inputs=[input_model],
|
| 437 |
+
outputs=[
|
| 438 |
+
youngs_cloud,
|
| 439 |
+
youngs_colorbar,
|
| 440 |
+
poissons_cloud,
|
| 441 |
+
poissons_colorbar,
|
| 442 |
+
density_cloud,
|
| 443 |
+
density_colorbar,
|
| 444 |
+
output_file,
|
| 445 |
+
],
|
| 446 |
+
fn=process_3d_model,
|
| 447 |
+
cache_examples=False,
|
| 448 |
+
)
|
| 449 |
+
|
| 450 |
+
# Event handlers
|
| 451 |
+
submit_btn.click(
|
| 452 |
+
fn=process_3d_model,
|
| 453 |
+
inputs=[input_model],
|
| 454 |
+
outputs=[
|
| 455 |
+
youngs_cloud,
|
| 456 |
+
youngs_colorbar,
|
| 457 |
+
poissons_cloud,
|
| 458 |
+
poissons_colorbar,
|
| 459 |
+
density_cloud,
|
| 460 |
+
density_colorbar,
|
| 461 |
+
output_file,
|
| 462 |
+
],
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
if __name__ == "__main__":
|
| 466 |
+
demo.launch()
|
examples/dog.ply
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1808d618588f67a083bca52848070297be63d24ba3ddf1e9dae7edd75d87c69e
|
| 3 |
+
size 2477313
|
examples/dozer.ply
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b44ab835c41c4b4e2ad4b55456de1173f38e8bcef005de4d5d9d2c27f7b3749e
|
| 3 |
+
size 84598795
|
examples/fiscus.ply
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7516d90f1ec0764ce653819057b1b69197a56bc31683b4a7fd4fdff247437f7e
|
| 3 |
+
size 74925059
|
examples/plant.ply
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3a659f85e78556a90cddb2f37fcf77e9bd452fda15de6f69f6db8c5803bf9fd5
|
| 3 |
+
size 12734620
|
requirements.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
polyscope==2.5.0
|
| 3 |
+
trimesh==4.8.1
|
| 4 |
+
Pillow==11.0.0
|
| 5 |
+
safetensors==0.6.2
|
| 6 |
+
easydict==1.13
|
| 7 |
+
scipy==1.14.1
|
| 8 |
+
pyparsing==3.2.3
|
| 9 |
+
opencv-python-headless==4.10.0.84
|
| 10 |
+
numpy==1.26.4
|
| 11 |
+
matplotlib==3.7.5
|
| 12 |
+
plotly
|
| 13 |
+
torch==2.4.0
|
| 14 |
+
torchvision==0.19.0
|
| 15 |
+
xformers==0.0.27.post2
|
| 16 |
+
spconv-cu121
|
| 17 |
+
https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-2.4.0_cu121/kaolin-0.18.0-cp312-cp312-linux_x86_64.whl
|
| 18 |
+
https://huggingface.co/spaces/nvidia/PhysicalAI-Robotics-VoMP-Demo/resolve/main/wheels/utils3d-0.0.2-py3-none-any.whl
|
| 19 |
+
https://huggingface.co/spaces/nvidia/PhysicalAI-Robotics-VoMP-Demo/resolve/main/wheels/diff_gaussian_rasterization-0.0.0-cp312-cp312-linux_x86_64.whl
|
| 20 |
+
git+https://github.com/nv-tlabs/vomp.git#egg=vomp
|
| 21 |
+
https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.0.post2/flash_attn-2.7.0.post2+cu12torch2.4cxx11abiFALSE-cp312-cp312-linux_x86_64.whl
|
wheels/diff_gaussian_rasterization-0.0.0-cp312-cp312-linux_x86_64.whl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b7166024db90f7878df26a50a5ec554a3a5efa421d2bc924a0fa1a99fb59b6c
|
| 3 |
+
size 459917
|
wheels/utils3d-0.0.2-py3-none-any.whl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4caaf6a3e6ddca59d824d1436f6a6139d7410d61a5d33af5c5e57e041d1d21c2
|
| 3 |
+
size 88958
|