jadechoghari commited on
Commit
38028e5
1 Parent(s): d59c58c

support direct mesh visualizer

Browse files
Files changed (1) hide show
  1. app.py +24 -12
app.py CHANGED
@@ -113,17 +113,29 @@ def generate_mesh(image, source_size=512, render_size=384, mesh_size=512, export
113
  mesh.export(mesh_path, 'obj')
114
  return mesh_path
115
 
116
- # TODO: instead of outputting .obj file -> directly output a 3d model
117
- def gradio_interface(image):
118
- mesh_file = generate_mesh(image)
119
- print("Generated Mesh File Path:", mesh_file)
120
- return mesh_file
121
 
 
 
 
122
 
123
- gr.Interface(
124
- fn=gradio_interface,
125
- inputs=gr.Image(type="pil", label="Input Image"),
126
- outputs=gr.File(label="Awesome 3D Mesh (.obj)"),
127
- title="3D Mesh Generator by FacebookAI",
128
- description="Upload an image and generate a 3D mesh (.obj) file using VFusion3D by FacebookAI"
129
- ).launch()
 
 
 
 
 
 
 
 
 
 
 
113
  mesh.export(mesh_path, 'obj')
114
  return mesh_path
115
 
116
+ # we will convert image to mesh
117
+ def step_1_generate_obj(image):
118
+ mesh_path = generate_mesh(image)
119
+ return mesh_path
 
120
 
121
+ # we will convert mesh to 3d-image
122
+ def step_2_display_3d_model(mesh_file):
123
+ return mesh_file
124
 
125
+ with gr.Blocks() as demo:
126
+ with gr.Row():
127
+ with gr.Column():
128
+ img_input = gr.Image(type="pil", label="Input Image")
129
+ generate_button = gr.Button("Generate and Visualize 3D Model")
130
+ obj_file_output = gr.File(label="Download .obj File")
131
+
132
+ with gr.Column():
133
+ model_output = gr.Model3D(clear_color=[0.0, 0.0, 0.0, 0.0], label="3D Model Visualization")
134
+
135
+ def generate_and_visualize(image):
136
+ mesh_path = step_1_generate_obj(image)
137
+ return mesh_path, mesh_path
138
+
139
+ generate_button.click(generate_and_visualize, inputs=img_input, outputs=[obj_file_output, model_output])
140
+
141
+ demo.launch()