cavargas10 commited on
Commit
44fcbfd
·
verified ·
1 Parent(s): a6809ac

Prueba generar Textura

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -21,7 +21,7 @@ from tqdm import tqdm
21
 
22
  from src.utils.camera_util import (FOV_to_intrinsics, get_circular_camera_poses, get_zero123plus_input_cameras)
23
  from src.utils.infer_util import (remove_background, resize_foreground)
24
- from src.utils.mesh_util import save_glb, save_obj
25
  from src.utils.train_util import instantiate_from_config
26
 
27
  # Inicializa un tensor en CUDA y verifica el dispositivo.
@@ -87,7 +87,7 @@ def generate_mvs(input_image, sample_steps, sample_seed):
87
 
88
  return z123_image, show_image
89
 
90
- # Convierte imágenes en modelos 3D.
91
  @spaces.GPU
92
  def make3d(images):
93
 
@@ -113,20 +113,22 @@ def make3d(images):
113
  mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
114
  mesh_dirname = os.path.dirname(mesh_fpath)
115
  mesh_glb_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.glb")
 
116
 
117
  with torch.no_grad():
118
  planes = model.forward_planes(images, input_cameras)
119
- mesh_out = model.extract_mesh(planes, use_texture_map=False, **infer_config)
120
 
121
- vertices, faces, vertex_colors = mesh_out
122
  vertices = vertices[:, [1, 2, 0]]
123
 
124
- save_glb(vertices, faces, vertex_colors, mesh_glb_fpath)
125
- save_obj(vertices, faces, vertex_colors, mesh_fpath)
 
126
 
127
- print(f"Mesh saved to {mesh_fpath}")
128
 
129
- return mesh_fpath, mesh_glb_fpath
130
 
131
  # Procesa la imagen generada a partir de un prompt de texto.
132
  @spaces.GPU
@@ -240,6 +242,12 @@ with gr.Blocks() as demo:
240
  label="(Formato GLB)",
241
  interactive=False,
242
  )
 
 
 
 
 
 
243
 
244
  mv_images = gr.State()
245
 
@@ -254,7 +262,7 @@ with gr.Blocks() as demo:
254
  ).success(
255
  fn=make3d,
256
  inputs=[mv_images],
257
- outputs=[output_model_obj, output_model_glb]
258
  )
259
 
260
  demo.launch()
 
21
 
22
  from src.utils.camera_util import (FOV_to_intrinsics, get_circular_camera_poses, get_zero123plus_input_cameras)
23
  from src.utils.infer_util import (remove_background, resize_foreground)
24
+ from src.utils.mesh_util import save_glb, save_obj, save_texmap
25
  from src.utils.train_util import instantiate_from_config
26
 
27
  # Inicializa un tensor en CUDA y verifica el dispositivo.
 
87
 
88
  return z123_image, show_image
89
 
90
+ # Convierte imágenes en modelos 3D y genera texturas.
91
  @spaces.GPU
92
  def make3d(images):
93
 
 
113
  mesh_basename = os.path.basename(mesh_fpath).split('.')[0]
114
  mesh_dirname = os.path.dirname(mesh_fpath)
115
  mesh_glb_fpath = os.path.join(mesh_dirname, f"{mesh_basename}.glb")
116
+ texmap_fpath = os.path.join(mesh_dirname, f"{mesh_basename}_tex.png")
117
 
118
  with torch.no_grad():
119
  planes = model.forward_planes(images, input_cameras)
120
+ mesh_out = model.extract_mesh(planes, use_texture_map=True, **infer_config)
121
 
122
+ vertices, faces, vertex_colors, texture_map = mesh_out
123
  vertices = vertices[:, [1, 2, 0]]
124
 
125
+ save_glb(vertices, faces, vertex_colors, texture_map, mesh_glb_fpath)
126
+ save_obj(vertices, faces, vertex_colors, texture_map, mesh_fpath)
127
+ save_texmap(texture_map, texmap_fpath)
128
 
129
+ print(f"Mesh and texture saved to {mesh_fpath} and {texmap_fpath}")
130
 
131
+ return mesh_fpath, mesh_glb_fpath, texmap_fpath
132
 
133
  # Procesa la imagen generada a partir de un prompt de texto.
134
  @spaces.GPU
 
242
  label="(Formato GLB)",
243
  interactive=False,
244
  )
245
+ with gr.Tab("Textura"):
246
+ output_texture = gr.Image(
247
+ label="Textura Generada",
248
+ type="pil",
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, output_texture]
266
  )
267
 
268
  demo.launch()