jorgejungle commited on
Commit
ab43bd6
1 Parent(s): 0b6ff50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -98,7 +98,7 @@ bg_remover = rembg.new_session()
98
 
99
  # process function
100
  # @spaces.GPU
101
- def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_steps=30, input_seed=42):
102
 
103
  # seed
104
  kiui.seed_everything(input_seed)
@@ -193,7 +193,12 @@ def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_ste
193
  images = np.concatenate(images, axis=0)
194
  imageio.mimwrite(output_video_path, images, fps=30)
195
 
 
196
 
 
 
 
 
197
  # load a saved ply and convert to mesh
198
  opt.test_path = output_ply_path
199
  opt.force_cuda_rast = True # container compatability
@@ -203,9 +208,8 @@ def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_ste
203
  converter.fit_mesh()
204
  converter.fit_mesh_uv()
205
  converter.export_mesh(opt.test_path.replace('.ply', '.glb'))
206
-
207
- return mv_image_grid, output_video_path, output_glb_path
208
-
209
  # gradio UI
210
 
211
  _TITLE = '''LGM: Large Multi-View Gaussian Model for High-Resolution 3D Content Creation'''
@@ -247,7 +251,7 @@ with block:
247
 
248
 
249
  with gr.Column(scale=1):
250
- with gr.Tab("Video"):
251
  # final video results
252
  output_video = gr.Video(label="video")
253
  # ply file
@@ -255,9 +259,14 @@ with block:
255
  with gr.Tab("Multi-view Image"):
256
  # multi-view results
257
  output_image = gr.Image(interactive=False, show_label=False)
 
 
 
 
258
 
259
- button_gen.click(process, inputs=[input_image, input_text, input_neg_text, input_elevation, input_num_steps, input_seed], outputs=[output_image, output_video, output_file])
260
-
 
261
  gr.Examples(
262
  examples=[
263
  "data_test/frog_sweater.jpg",
@@ -269,7 +278,7 @@ with block:
269
  ],
270
  inputs=[input_image],
271
  outputs=[output_image, output_video, output_file],
272
- fn=lambda x: process(input_image=x, prompt=''),
273
  cache_examples=True,
274
  label='Image-to-3D Examples'
275
  )
@@ -286,7 +295,7 @@ with block:
286
  ],
287
  inputs=[input_text],
288
  outputs=[output_image, output_video, output_file],
289
- fn=lambda x: process(input_image=None, prompt=x),
290
  cache_examples=True,
291
  label='Text-to-3D Examples'
292
  )
 
98
 
99
  # process function
100
  # @spaces.GPU
101
+ def generate(input_image, prompt, prompt_neg='', input_elevation=0, input_num_steps=30, input_seed=42):
102
 
103
  # seed
104
  kiui.seed_everything(input_seed)
 
193
  images = np.concatenate(images, axis=0)
194
  imageio.mimwrite(output_video_path, images, fps=30)
195
 
196
+ return mv_image_grid, output_video_path, output_ply_path
197
 
198
+ def convert(output_ply_path):
199
+ if not os.path.exists(output_ply_path):
200
+ gr.Warning("PLY file not found please upload or generate 3D model")
201
+
202
  # load a saved ply and convert to mesh
203
  opt.test_path = output_ply_path
204
  opt.force_cuda_rast = True # container compatability
 
208
  converter.fit_mesh()
209
  converter.fit_mesh_uv()
210
  converter.export_mesh(opt.test_path.replace('.ply', '.glb'))
211
+ return output_glb_path
212
+
 
213
  # gradio UI
214
 
215
  _TITLE = '''LGM: Large Multi-View Gaussian Model for High-Resolution 3D Content Creation'''
 
251
 
252
 
253
  with gr.Column(scale=1):
254
+ with gr.Tab("Video and File"):
255
  # final video results
256
  output_video = gr.Video(label="video")
257
  # ply file
 
259
  with gr.Tab("Multi-view Image"):
260
  # multi-view results
261
  output_image = gr.Image(interactive=False, show_label=False)
262
+ with gr.Tab("Convert Format"):
263
+ # multi-view results
264
+ output_glb = gr.File(label="3D Mesh (glb format)")
265
+ convert_button = gr.Button("Convert to Mesh")
266
 
267
+ button_gen.click(generate, inputs=[input_image, input_text, input_neg_text, input_elevation, input_num_steps, input_seed], outputs=[output_image, output_video, output_file])
268
+ button_con.click(convert, inputs=output_file, outputs=output_glb)
269
+
270
  gr.Examples(
271
  examples=[
272
  "data_test/frog_sweater.jpg",
 
278
  ],
279
  inputs=[input_image],
280
  outputs=[output_image, output_video, output_file],
281
+ fn=lambda x: generate(input_image=x, prompt=''),
282
  cache_examples=True,
283
  label='Image-to-3D Examples'
284
  )
 
295
  ],
296
  inputs=[input_text],
297
  outputs=[output_image, output_video, output_file],
298
+ fn=lambda x: generate(input_image=None, prompt=x),
299
  cache_examples=True,
300
  label='Text-to-3D Examples'
301
  )