cavargas10 commited on
Commit
e9f9c58
·
verified ·
1 Parent(s): 4a9eda4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -70
app.py CHANGED
@@ -3,7 +3,7 @@ import spaces
3
  from gradio_litmodel3d import LitModel3D
4
  import os
5
  import shutil
6
- import igl
7
  os.environ['SPCONV_ALGO'] = 'native'
8
  from typing import *
9
  import torch
@@ -134,69 +134,6 @@ def extract_glb(
134
  torch.cuda.empty_cache()
135
  return glb_path, glb_path
136
 
137
- @spaces.GPU(duration=90)
138
- def extract_glb_with_remesh(
139
- state: dict,
140
- mesh_simplify: float,
141
- texture_size: int,
142
- remesh_type: str,
143
- target_count: int,
144
- req: gr.Request,
145
- ) -> Tuple[str, str]:
146
- user_dir = os.path.join(TMP_DIR, str(req.session_hash))
147
- gs, old_mesh = unpack_state(state)
148
-
149
- # Datos originales
150
- V_old = old_mesh.vertices.cpu().numpy()
151
- F_old = old_mesh.faces.cpu().numpy()
152
- uv_old = old_mesh.uv.cpu().numpy() if hasattr(old_mesh, 'uv') else None
153
- face_uv_old = old_mesh.face_uv.cpu().numpy() if hasattr(old_mesh, 'face_uv') else None
154
-
155
- if remesh_type != "none" and (TRIANGLE_REMESH_AVAILABLE or QUAD_REMESH_AVAILABLE):
156
- # Remeshing con libigl
157
- if remesh_type == "triangle":
158
- V_new, F_new = igl.triangulate(V_old, F_old)
159
- V_new, F_new = igl.decimate(V_new, F_new, target_count)
160
- elif remesh_type == "quad":
161
- V_new, F_new = igl.quad_remesh(V_old, F_old, target_count)
162
-
163
- # Transferencia de UV usando interpolación baricéntrica
164
- if uv_old is not None:
165
- barycoord, closest_faces = igl.barycentric_coordinates_tri(
166
- V_new,
167
- V_old[F_old[closest_faces,0]],
168
- V_old[F_old[closest_faces,1]],
169
- V_old[F_old[closest_faces,2]]
170
- )
171
-
172
- uv_new = np.zeros((V_new.shape[0], 2))
173
- for i in range(3):
174
- uv_new += barycoord[:,i].reshape(-1,1) * uv_old[face_uv_old[closest_faces,i]]
175
- else:
176
- uv_new = None
177
- face_uv_new = None
178
- else:
179
- # Sin remeshing
180
- V_new, F_new = V_old, F_old
181
- uv_new = uv_old
182
- face_uv_new = face_uv_old
183
-
184
- # Crear nueva malla
185
- new_mesh = edict(
186
- vertices=torch.tensor(V_new, device='cuda'),
187
- faces=torch.tensor(F_new, device='cuda'),
188
- uv=torch.tensor(uv_new, device='cuda') if uv_new is not None else None,
189
- face_uv=torch.tensor(face_uv_new, device='cuda') if face_uv_new is not None else None,
190
- )
191
-
192
- # Exportar a GLB
193
- glb = postprocessing_utils.to_glb(gs, new_mesh, simplify=mesh_simplify,
194
- texture_size=texture_size, verbose=False)
195
- glb_path = os.path.join(user_dir, 'sample.glb')
196
- glb.export(glb_path)
197
- torch.cuda.empty_cache()
198
- return glb_path, glb_path
199
-
200
  @spaces.GPU
201
  def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
202
 
@@ -248,10 +185,6 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
248
  with gr.Row():
249
  slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
250
  slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
251
-
252
- with gr.Accordion(label="Remeshing Settings", open=False):
253
- remesh_type = gr.Radio(choices=["none", "triangle", "quad"], label="Remesh Type", value="none")
254
- target_count = gr.Slider(1000, 100000, label="Target Vertex/Face Count", value=20000, step=1000)
255
 
256
  generate_btn = gr.Button("Generate")
257
 
@@ -305,8 +238,8 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
305
  )
306
 
307
  extract_glb_btn.click(
308
- extract_glb_with_remesh,
309
- inputs=[output_buf, mesh_simplify, texture_size, remesh_type, target_count],
310
  outputs=[model_output, download_glb],
311
  ).then(
312
  lambda: gr.Button(interactive=True),
 
3
  from gradio_litmodel3d import LitModel3D
4
  import os
5
  import shutil
6
+
7
  os.environ['SPCONV_ALGO'] = 'native'
8
  from typing import *
9
  import torch
 
134
  torch.cuda.empty_cache()
135
  return glb_path, glb_path
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  @spaces.GPU
138
  def extract_gaussian(state: dict, req: gr.Request) -> Tuple[str, str]:
139
 
 
185
  with gr.Row():
186
  slat_guidance_strength = gr.Slider(0.0, 10.0, label="Guidance Strength", value=3.0, step=0.1)
187
  slat_sampling_steps = gr.Slider(1, 50, label="Sampling Steps", value=12, step=1)
 
 
 
 
188
 
189
  generate_btn = gr.Button("Generate")
190
 
 
238
  )
239
 
240
  extract_glb_btn.click(
241
+ extract_glb,
242
+ inputs=[output_buf, mesh_simplify, texture_size],
243
  outputs=[model_output, download_glb],
244
  ).then(
245
  lambda: gr.Button(interactive=True),