cavargas10 commited on
Commit
44a6155
·
verified ·
1 Parent(s): 2631107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -146,7 +146,7 @@ def image_to_3d(
146
  outputs = pipeline.run(
147
  image[1],
148
  seed=seed,
149
- formats=["gaussian", "mesh"],
150
  preprocess_image=False,
151
  sparse_structure_sampler_params={
152
  "steps": ss_sampling_steps,
@@ -157,9 +157,7 @@ def image_to_3d(
157
  "cfg_strength": slat_guidance_strength,
158
  },
159
  )
160
- video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
161
- video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
162
- video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
163
  video_path = os.path.join(user_dir, 'sample.mp4')
164
  imageio.mimsave(video_path, video, fps=15)
165
  state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
@@ -181,11 +179,15 @@ def extract_glb(
181
  torch.cuda.empty_cache()
182
  return glb_path, glb_path
183
 
 
 
 
184
  with gr.Blocks(delete_cache=(600, 600)) as demo:
185
  gr.Markdown("""
186
  ## Sketch to 3D with TRELLIS
187
  1. Fast sketch to image with SDXL Flash, using [@xinsir](https://huggingface.co/xinsir) [scribble sdxl controlnet](https://huggingface.co/xinsir/controlnet-scribble-sdxl-1.0) and [sdxl flash](https://huggingface.co/sd-community/sdxl-flash)
188
  2. Scalable and versatile image to 3D generation using [TRELLIS](https://trellis3d.github.io/)
 
189
  """)
190
  with gr.Row():
191
  with gr.Column():
@@ -238,14 +240,14 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
238
  with gr.Row():
239
  extract_glb_btn = gr.Button("Extract GLB", interactive=False)
240
  gr.Markdown("""
241
- *NOTE: Gaussian file can be very large (~50MB), it will take a while to display and download.*
242
  """)
243
  with gr.Column():
244
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
245
  image_prompt_processed = ImageSlider(label="processed sketch", interactive=False, type="pil", height=512)
246
  model_output = LitModel3D(label="Extracted GLB", exposure=10.0, height=300)
247
  with gr.Row():
248
- download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
249
 
250
  output_buf = gr.State()
251
  demo.load(start_session)
@@ -266,36 +268,31 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
266
  )
267
 
268
  generate_btn.click(
269
- get_seed,
270
- inputs=[randomize_seed, seed],
271
- outputs=[seed],
272
  ).then(
273
  image_to_3d,
274
  inputs=[image_prompt_processed, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
275
  outputs=[output_buf, video_output],
276
  ).then(
277
- # Cambiamos esto: ahora solo actualizamos el botón de GLB
278
- lambda: gr.Button.update(interactive=True),
279
  outputs=[extract_glb_btn],
280
  )
281
-
282
- # Corregimos también el evento de limpieza del video
283
  video_output.clear(
284
- lambda: gr.Button.update(interactive=False),
285
  outputs=[extract_glb_btn],
286
  )
287
-
288
  extract_glb_btn.click(
289
  extract_glb,
290
  inputs=[output_buf, mesh_simplify, texture_size],
291
  outputs=[model_output, download_glb],
292
  ).then(
293
- lambda: gr.Button.update(interactive=True),
294
  outputs=[download_glb],
295
  )
296
-
297
  model_output.clear(
298
- lambda: gr.Button.update(interactive=False),
299
  outputs=[download_glb],
300
  )
301
 
 
146
  outputs = pipeline.run(
147
  image[1],
148
  seed=seed,
149
+ formats=["mesh"],
150
  preprocess_image=False,
151
  sparse_structure_sampler_params={
152
  "steps": ss_sampling_steps,
 
157
  "cfg_strength": slat_guidance_strength,
158
  },
159
  )
160
+ video = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
 
 
161
  video_path = os.path.join(user_dir, 'sample.mp4')
162
  imageio.mimsave(video_path, video, fps=15)
163
  state = pack_state(outputs['gaussian'][0], outputs['mesh'][0])
 
179
  torch.cuda.empty_cache()
180
  return glb_path, glb_path
181
 
182
+ def reset_do_preprocess():
183
+ return True
184
+
185
  with gr.Blocks(delete_cache=(600, 600)) as demo:
186
  gr.Markdown("""
187
  ## Sketch to 3D with TRELLIS
188
  1. Fast sketch to image with SDXL Flash, using [@xinsir](https://huggingface.co/xinsir) [scribble sdxl controlnet](https://huggingface.co/xinsir/controlnet-scribble-sdxl-1.0) and [sdxl flash](https://huggingface.co/sd-community/sdxl-flash)
189
  2. Scalable and versatile image to 3D generation using [TRELLIS](https://trellis3d.github.io/)
190
+ ### ð ¨ð ï¸ draw or upload a sketch and click "Generate" to create a 3D asset â ¨
191
  """)
192
  with gr.Row():
193
  with gr.Column():
 
240
  with gr.Row():
241
  extract_glb_btn = gr.Button("Extract GLB", interactive=False)
242
  gr.Markdown("""
243
+ *NOTE: GLB file can be downloaded after extraction.*
244
  """)
245
  with gr.Column():
246
  video_output = gr.Video(label="Generated 3D Asset", autoplay=True, loop=True, height=300)
247
  image_prompt_processed = ImageSlider(label="processed sketch", interactive=False, type="pil", height=512)
248
  model_output = LitModel3D(label="Extracted GLB", exposure=10.0, height=300)
249
  with gr.Row():
250
+ download_glb = gr.DownloadButton(label="Download GLB", interactive=False)
251
 
252
  output_buf = gr.State()
253
  demo.load(start_session)
 
268
  )
269
 
270
  generate_btn.click(
271
+ get_seed,
272
+ inputs=[randomize_seed, seed],
273
+ outputs=[seed],
274
  ).then(
275
  image_to_3d,
276
  inputs=[image_prompt_processed, seed, ss_guidance_strength, ss_sampling_steps, slat_guidance_strength, slat_sampling_steps],
277
  outputs=[output_buf, video_output],
278
  ).then(
279
+ lambda: gr.Button(interactive=True),
 
280
  outputs=[extract_glb_btn],
281
  )
 
 
282
  video_output.clear(
283
+ lambda: gr.Button(interactive=False),
284
  outputs=[extract_glb_btn],
285
  )
 
286
  extract_glb_btn.click(
287
  extract_glb,
288
  inputs=[output_buf, mesh_simplify, texture_size],
289
  outputs=[model_output, download_glb],
290
  ).then(
291
+ lambda: gr.Button(interactive=True),
292
  outputs=[download_glb],
293
  )
 
294
  model_output.clear(
295
+ lambda: gr.Button(interactive=False),
296
  outputs=[download_glb],
297
  )
298