cavargas10 commited on
Commit
539bc94
verified
1 Parent(s): 1ccf97b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -31
app.py CHANGED
@@ -22,7 +22,7 @@ from tqdm import tqdm
22
  from src.utils.camera_util import (FOV_to_intrinsics, get_circular_camera_poses,
23
  get_zero123plus_input_cameras)
24
  from src.utils.infer_util import (remove_background, resize_foreground)
25
- from src.utils.mesh_util import save_glb, save_obj, save_obj_with_mtl
26
  from src.utils.train_util import instantiate_from_config
27
 
28
  zero = torch.Tensor([0]).cuda()
@@ -118,36 +118,21 @@ def make3d(images):
118
  mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
119
  mesh_dirname = os.path.dirname(mesh_fpath)
120
  mesh_glb_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.glb")
121
- texmap_fpath = os.path.join(mesh_dirname, f"{mesh_basename}_tex.png")
122
 
123
  with torch.no_grad():
124
  planes = model.forward_planes(images, input_cameras)
125
-
126
- # Extraer el mesh y la textura
127
  mesh_out = model.extract_mesh(
128
- planes,
129
- use_texture_map=True, # Habilitar la generaci贸n de texturas
130
- **infer_config,
131
- )
132
-
133
- # Guardar el mesh con o sin textura
134
- if len(mesh_out) == 5: # Si se genera una textura
135
- vertices, faces, uvs, mesh_tex_idx, tex_map = mesh_out
136
- save_obj_with_mtl(
137
- vertices.data.cpu().numpy(),
138
- uvs.data.cpu().numpy(),
139
- faces.data.cpu().numpy(),
140
- mesh_tex_idx.data.cpu().numpy(),
141
- tex_map.permute(1, 2, 0).data.cpu().numpy(),
142
- mesh_fpath,
143
- )
144
- else:
145
- vertices, faces, vertex_colors = mesh_out
146
- save_obj(vertices, faces, vertex_colors, mesh_fpath)
147
 
148
  print(f"Mesh saved to {mesh_fpath}")
149
 
150
- return mesh_fpath, mesh_glb_fpath, texmap_fpath if len(mesh_out) == 5 else None
151
 
152
 
153
  @spaces.GPU
@@ -263,12 +248,6 @@ with gr.Blocks() as demo:
263
  label="(Formato GLB)",
264
  interactive=False,
265
  )
266
- with gr.Tab("Textura"):
267
- output_texture = gr.Image(
268
- label="Textura Generada",
269
- type="pil",
270
- interactive=False
271
- )
272
 
273
  mv_images = gr.State()
274
 
@@ -283,7 +262,7 @@ with gr.Blocks() as demo:
283
  ).success(
284
  fn=make3d,
285
  inputs=[mv_images],
286
- outputs=[output_model_obj, output_model_glb, output_texture]
287
  )
288
 
289
  demo.launch()
 
22
  from src.utils.camera_util import (FOV_to_intrinsics, get_circular_camera_poses,
23
  get_zero123plus_input_cameras)
24
  from src.utils.infer_util import (remove_background, resize_foreground)
25
+ from src.utils.mesh_util import save_glb, save_obj
26
  from src.utils.train_util import instantiate_from_config
27
 
28
  zero = torch.Tensor([0]).cuda()
 
118
  mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
119
  mesh_dirname = os.path.dirname(mesh_fpath)
120
  mesh_glb_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.glb")
 
121
 
122
  with torch.no_grad():
123
  planes = model.forward_planes(images, input_cameras)
 
 
124
  mesh_out = model.extract_mesh(
125
+ planes, use_texture_map=False, **infer_config)
126
+
127
+ vertices, faces, vertex_colors = mesh_out
128
+ vertices = vertices[:, [1, 2, 0]]
129
+
130
+ save_glb(vertices, faces, vertex_colors, mesh_glb_fpath)
131
+ save_obj(vertices, faces, vertex_colors, mesh_fpath)
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  print(f"Mesh saved to {mesh_fpath}")
134
 
135
+ return mesh_fpath, mesh_glb_fpath
136
 
137
 
138
  @spaces.GPU
 
248
  label="(Formato GLB)",
249
  interactive=False,
250
  )
 
 
 
 
 
 
251
 
252
  mv_images = gr.State()
253
 
 
262
  ).success(
263
  fn=make3d,
264
  inputs=[mv_images],
265
+ outputs=[output_model_obj, output_model_glb]
266
  )
267
 
268
  demo.launch()