Spaces:
Runtime error
Runtime error
Update app.py
Browse files3 unmodified lines45678931 unmodified lines414243444546472 unmodified lines5051525354555657585960616212 unmodified lines75767778798081828384853 unmodified linesfrom PIL import Imageimport tempfiledef visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):# Load the original meshmesh = trimesh.load('train.glb', force='mesh')31 unmodified linestemp_file.close()return temp_file.name# Load the train model to get its boundstrain_model = trimesh.load('train.glb', force='mesh')train_bounds = train_model.bounds2 unmodified linesy_min_range, y_max_range = train_bounds[0][1], train_bounds[1][1]z_min_range, z_max_range = train_bounds[0][2], train_bounds[1][2]# Gradio UI for selection and dynamic visualization with live modewith gr.Blocks() as app:gr.Markdown("### 3D Model Texture Application with Live Selection")original_model = gr.Model3D('train.glb', label="Original Model")modified_model = gr.Model3D(label="Textured Model")section_dropdown = gr.Dropdown(choices=['right compartments', 'left compartments', 'freight_body', 'custom'], label="Select Section", value='custom')# Custom sliders for the bounding box selectionwith gr.Row(visible=True) as custom_controls:12 unmodified linessection_dropdown.change(fn=toggle_custom_controls, inputs=section_dropdown, outputs=custom_controls)# Update the model dynamicallydef update_model(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):return visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max)# Set live mode changes for each inputsection_dropdown.change(fn=update_model, inputs=[section_dropdown, x_min_slider, x_max_slider, y_min_slider, y_max_slider, z_min_slider, z_max_slider], outputs=modified_model)app.launch()3 unmodified lines4567891031 unmodified lines424344454647482 unmodified lines515253545556575859606162636412 unmodified lines777879808182838485868788893 unmodified linesfrom PIL import Imageimport tempfile# Function to visualize texture based on selection criteriadef visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):# Load the original meshmesh = trimesh.load('train.glb', force='mesh')31 unmodified linestemp_file.close()return temp_file.name# Load train model to establish bounding box rangestrain_model = trimesh.load('train.glb', force='mesh')train_bounds = train_model.bounds2 unmodified linesy_min_range, y_max_range = train_bounds[0][1], train_bounds[1][1]z_min_range, z_max_range = train_bounds[0][2], train_bounds[1][2]# Gradio UI with a single window, dynamic updates, and real-time changeswith gr.Blocks() as app:gr.Markdown("### 3D Model Texture Application with Predefined and Custom Sections")original_model = gr.Model3D('train.glb', label="Original Model")modified_model = gr.Model3D(label="Model with Applied Texture")# Dropdown for predefined and custom selectionsection_dropdown = gr.Radio(choices=['right compartments', 'left compartments', 'freight_body', 'custom'], label="Select Section", value='custom')# Custom sliders for the bounding box selectionwith gr.Row(visible=True) as custom_controls:12 unmodified linessection_dropdown.change(fn=toggle_custom_controls, inputs=section_dropdown, outputs=custom_controls)# Update model dynamicallydef update_model(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max):return visualize_dynamic_texture(predefined_section, x_min, x_max, y_min, y_max, z_min, z_max)# Add event listeners for real-time updates when sliders or dropdown changeinputs = [section_dropdown, x_min_slider, x_max_slider, y_min_slider, y_max_slider, z_min_slider, z_max_slider]for input_component in inputs:input_component.change(fn=update_model, inputs=inputs, outputs=modified_model)app.launch()
app.py+12-8