Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
from PIL import Image
|
| 5 |
import tempfile
|
| 6 |
|
|
|
|
| 7 |
def visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):
|
| 8 |
# Load the original mesh
|
| 9 |
mesh = trimesh.load('train.glb', force='mesh')
|
|
@@ -41,7 +42,7 @@ def visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_
|
|
| 41 |
temp_file.close()
|
| 42 |
return temp_file.name
|
| 43 |
|
| 44 |
-
# Load
|
| 45 |
train_model = trimesh.load('train.glb', force='mesh')
|
| 46 |
train_bounds = train_model.bounds
|
| 47 |
|
|
@@ -50,13 +51,14 @@ x_min_range, x_max_range = train_bounds[0][0], train_bounds[1][0]
|
|
| 50 |
y_min_range, y_max_range = train_bounds[0][1], train_bounds[1][1]
|
| 51 |
z_min_range, z_max_range = train_bounds[0][2], train_bounds[1][2]
|
| 52 |
|
| 53 |
-
# Gradio UI
|
| 54 |
with gr.Blocks() as app:
|
| 55 |
-
gr.Markdown("### 3D Model Texture Application with
|
| 56 |
original_model = gr.Model3D('train.glb', label="Original Model")
|
| 57 |
-
modified_model = gr.Model3D(label="
|
| 58 |
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
# Custom sliders for the bounding box selection
|
| 62 |
with gr.Row(visible=True) as custom_controls:
|
|
@@ -75,11 +77,13 @@ with gr.Blocks() as app:
|
|
| 75 |
|
| 76 |
section_dropdown.change(fn=toggle_custom_controls, inputs=section_dropdown, outputs=custom_controls)
|
| 77 |
|
| 78 |
-
# Update
|
| 79 |
def update_model(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):
|
| 80 |
return visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max)
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
app.launch()
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
+
# Function to visualize texture based on selection criteria
|
| 8 |
def visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):
|
| 9 |
# Load the original mesh
|
| 10 |
mesh = trimesh.load('train.glb', force='mesh')
|
|
|
|
| 42 |
temp_file.close()
|
| 43 |
return temp_file.name
|
| 44 |
|
| 45 |
+
# Load train model to establish bounding box ranges
|
| 46 |
train_model = trimesh.load('train.glb', force='mesh')
|
| 47 |
train_bounds = train_model.bounds
|
| 48 |
|
|
|
|
| 51 |
y_min_range, y_max_range = train_bounds[0][1], train_bounds[1][1]
|
| 52 |
z_min_range, z_max_range = train_bounds[0][2], train_bounds[1][2]
|
| 53 |
|
| 54 |
+
# Gradio UI with a single window, dynamic updates, and real-time changes
|
| 55 |
with gr.Blocks() as app:
|
| 56 |
+
gr.Markdown("### 3D Model Texture Application with Predefined and Custom Sections")
|
| 57 |
original_model = gr.Model3D('train.glb', label="Original Model")
|
| 58 |
+
modified_model = gr.Model3D(label="Model with Applied Texture")
|
| 59 |
|
| 60 |
+
# Dropdown for predefined and custom selection
|
| 61 |
+
section_dropdown = gr.Radio(choices=['right compartments', 'left compartments', 'freight_body', 'custom'], label="Select Section", value='custom')
|
| 62 |
|
| 63 |
# Custom sliders for the bounding box selection
|
| 64 |
with gr.Row(visible=True) as custom_controls:
|
|
|
|
| 77 |
|
| 78 |
section_dropdown.change(fn=toggle_custom_controls, inputs=section_dropdown, outputs=custom_controls)
|
| 79 |
|
| 80 |
+
# Update model dynamically
|
| 81 |
def update_model(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):
|
| 82 |
return visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max)
|
| 83 |
|
| 84 |
+
# Add event listeners for real-time updates when sliders or dropdown change
|
| 85 |
+
inputs = [section_dropdown, x_min_slider, x_max_slider, y_min_slider, y_max_slider, z_min_slider, z_max_slider]
|
| 86 |
+
for input_component in inputs:
|
| 87 |
+
input_component.change(fn=update_model, inputs=inputs, outputs=modified_model)
|
| 88 |
|
| 89 |
app.launch()
|