cronos3k commited on
Commit
c33a25b
·
verified ·
1 Parent(s): abd8161

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -97,7 +97,7 @@ def image_to_3d(
97
  slat_guidance_strength: float,
98
  slat_sampling_steps: int,
99
  req: gr.Request,
100
- ) -> Tuple[dict, str, str]:
101
  """
102
  Convert an image to a 3D model.
103
  """
@@ -123,14 +123,14 @@ def image_to_3d(
123
  video_path = os.path.join(user_dir, f"{trial_id}.mp4")
124
  imageio.mimsave(video_path, video, fps=15)
125
 
126
- # Save full quality GLB
127
  glb = postprocessing_utils.to_glb(
128
  outputs['gaussian'][0],
129
  outputs['mesh'][0],
130
  simplify=0.0, # No simplification
131
  fill_holes=True,
132
  fill_holes_max_size=0.04,
133
- texture_size=2048, # Maximum texture size
134
  verbose=False
135
  )
136
  full_glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
@@ -150,25 +150,16 @@ def extract_glb(
150
  """
151
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
152
  gs, mesh, trial_id = unpack_state(state)
153
- glb = postprocessing_utils.to_glb(
154
- gs, mesh,
155
- simplify=mesh_simplify,
156
- fill_holes=True,
157
- fill_holes_max_size=0.04,
158
- texture_size=texture_size,
159
- verbose=False
160
- )
161
- glb_path = os.path.join(user_dir, f"{trial_id}_reduced.glb")
162
  glb.export(glb_path)
163
  return glb_path, glb_path
164
 
165
  with gr.Blocks(delete_cache=(600, 600)) as demo:
166
  gr.Markdown("""
167
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
168
- * Upload an image and click "Generate" to create a 3D asset
169
- * After generation:
170
- * Download the full quality GLB immediately
171
- * Or create a reduced size version with the extraction settings below
172
  """)
173
 
174
  with gr.Row():
@@ -193,7 +184,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
193
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
194
  texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
195
 
196
- extract_glb_btn = gr.Button("Extract Reduced GLB", interactive=False)
197
 
198
  with gr.Column():
199
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
 
97
  slat_guidance_strength: float,
98
  slat_sampling_steps: int,
99
  req: gr.Request,
100
+ ) -> Tuple[dict, str, str, str]:
101
  """
102
  Convert an image to a 3D model.
103
  """
 
123
  video_path = os.path.join(user_dir, f"{trial_id}.mp4")
124
  imageio.mimsave(video_path, video, fps=15)
125
 
126
+ # Generate full quality GLB
127
  glb = postprocessing_utils.to_glb(
128
  outputs['gaussian'][0],
129
  outputs['mesh'][0],
130
  simplify=0.0, # No simplification
131
  fill_holes=True,
132
  fill_holes_max_size=0.04,
133
+ texture_size=2048, # Maximum texture resolution
134
  verbose=False
135
  )
136
  full_glb_path = os.path.join(user_dir, f"{trial_id}_full.glb")
 
150
  """
151
  user_dir = os.path.join(TMP_DIR, str(req.session_hash))
152
  gs, mesh, trial_id = unpack_state(state)
153
+ glb = postprocessing_utils.to_glb(gs, mesh, simplify=mesh_simplify, texture_size=texture_size, verbose=False)
154
+ glb_path = os.path.join(user_dir, f"{trial_id}.glb")
 
 
 
 
 
 
 
155
  glb.export(glb_path)
156
  return glb_path, glb_path
157
 
158
  with gr.Blocks(delete_cache=(600, 600)) as demo:
159
  gr.Markdown("""
160
  ## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
161
+ * Upload an image and click "Generate" to create a 3D asset. If the image has alpha channel, it be used as the mask. Otherwise, we use `rembg` to remove the background.
162
+ * If you find the generated 3D asset satisfactory, click "Extract GLB" to extract the GLB file and download it.
 
 
163
  """)
164
 
165
  with gr.Row():
 
184
  mesh_simplify = gr.Slider(0.0, 0.98, label="Simplify", value=0.95, step=0.01)
185
  texture_size = gr.Slider(512, 2048, label="Texture Size", value=1024, step=512)
186
 
187
+ extract_glb_btn = gr.Button("Extract GLB", interactive=False)
188
 
189
  with gr.Column():
190
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)