rayli commited on
Commit
907c169
·
verified ·
1 Parent(s): ec5608f

Make large mesh warning text visible and keep full prompt mesh

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -197,6 +197,7 @@ DEMO_CSS = """
197
  .kinematic-json-sync {
198
  display: none !important;
199
  }
 
200
  .mesh-face-warning {
201
  display: block !important;
202
  margin: 8px 0 12px !important;
@@ -207,6 +208,8 @@ DEMO_CSS = """
207
  color: var(--demo-warning-text) !important;
208
  box-shadow: 0 1px 3px var(--demo-control-shadow) !important;
209
  }
 
 
210
  .mesh-face-warning *,
211
  .mesh-face-warning p {
212
  margin: 0 !important;
@@ -2828,7 +2831,7 @@ def _compact_json(value: dict[str, Any]) -> str:
2828
  return json.dumps(value, separators=(",", ":"))
2829
 
2830
 
2831
- def _prompt_mesh_payload(mesh: Any, *, max_faces: int = 12000) -> str:
2832
  vertices = np.asarray(mesh.vertices, dtype=np.float32)
2833
  faces = np.asarray(mesh.faces, dtype=np.int64)
2834
  if vertices.ndim != 2 or vertices.shape[1] != 3 or len(vertices) == 0:
@@ -2837,11 +2840,6 @@ def _prompt_mesh_payload(mesh: Any, *, max_faces: int = 12000) -> str:
2837
  raise ValueError("Prompt picker requires a triangular mesh.")
2838
 
2839
  face_count = int(faces.shape[0])
2840
- sampled = False
2841
- if face_count > max_faces:
2842
- face_ids = np.linspace(0, face_count - 1, int(max_faces), dtype=np.int64)
2843
- faces = faces[face_ids]
2844
- sampled = True
2845
 
2846
  used_vertex_ids = np.unique(faces.reshape(-1))
2847
  remap = np.full((vertices.shape[0],), -1, dtype=np.int64)
@@ -2876,7 +2874,7 @@ def _prompt_mesh_payload(mesh: Any, *, max_faces: int = 12000) -> str:
2876
  "radius": radius,
2877
  "source_faces": face_count,
2878
  "display_faces": int(compact_faces.shape[0]),
2879
- "sampled": sampled,
2880
  }
2881
  return _compact_json(payload)
2882
 
@@ -3548,10 +3546,15 @@ def _mesh_face_warning_update(mesh: Any):
3548
  return gr.update(value="", visible=False)
3549
  return gr.update(
3550
  value=(
3551
- f"<p><strong>Large mesh warning:</strong> this mesh has {face_count:,} faces. "
 
 
 
 
 
3552
  "Very dense meshes can exhaust the Space's CPU resources during "
3553
  "post-processing; for reliable runs, use a mesh with fewer than "
3554
- f"{HIGH_FACE_COUNT_WARNING_THRESHOLD:,} faces.</p>"
3555
  ),
3556
  visible=True,
3557
  )
@@ -4739,6 +4742,7 @@ def create_gradio_app(app: InstructParticulateApp) -> gr.Blocks:
4739
  mesh_face_warning = gr.HTML(
4740
  value="",
4741
  visible=False,
 
4742
  elem_classes=["mesh-face-warning"],
4743
  container=False,
4744
  )
 
197
  .kinematic-json-sync {
198
  display: none !important;
199
  }
200
+ #mesh-face-warning,
201
  .mesh-face-warning {
202
  display: block !important;
203
  margin: 8px 0 12px !important;
 
208
  color: var(--demo-warning-text) !important;
209
  box-shadow: 0 1px 3px var(--demo-control-shadow) !important;
210
  }
211
+ #mesh-face-warning *,
212
+ #mesh-face-warning p,
213
  .mesh-face-warning *,
214
  .mesh-face-warning p {
215
  margin: 0 !important;
 
2831
  return json.dumps(value, separators=(",", ":"))
2832
 
2833
 
2834
+ def _prompt_mesh_payload(mesh: Any) -> str:
2835
  vertices = np.asarray(mesh.vertices, dtype=np.float32)
2836
  faces = np.asarray(mesh.faces, dtype=np.int64)
2837
  if vertices.ndim != 2 or vertices.shape[1] != 3 or len(vertices) == 0:
 
2840
  raise ValueError("Prompt picker requires a triangular mesh.")
2841
 
2842
  face_count = int(faces.shape[0])
 
 
 
 
 
2843
 
2844
  used_vertex_ids = np.unique(faces.reshape(-1))
2845
  remap = np.full((vertices.shape[0],), -1, dtype=np.int64)
 
2874
  "radius": radius,
2875
  "source_faces": face_count,
2876
  "display_faces": int(compact_faces.shape[0]),
2877
+ "sampled": False,
2878
  }
2879
  return _compact_json(payload)
2880
 
 
3546
  return gr.update(value="", visible=False)
3547
  return gr.update(
3548
  value=(
3549
+ '<div class="mesh-face-warning-content" '
3550
+ 'style="display:block!important;margin:0!important;'
3551
+ 'color:var(--demo-warning-text,#78350f)!important;'
3552
+ 'font-size:14px!important;line-height:1.35!important;">'
3553
+ '<strong style="color:var(--demo-warning-text,#78350f)!important;">'
3554
+ f"Large mesh warning:</strong> this mesh has {face_count:,} faces. "
3555
  "Very dense meshes can exhaust the Space's CPU resources during "
3556
  "post-processing; for reliable runs, use a mesh with fewer than "
3557
+ f"{HIGH_FACE_COUNT_WARNING_THRESHOLD:,} faces.</div>"
3558
  ),
3559
  visible=True,
3560
  )
 
4742
  mesh_face_warning = gr.HTML(
4743
  value="",
4744
  visible=False,
4745
+ elem_id="mesh-face-warning",
4746
  elem_classes=["mesh-face-warning"],
4747
  container=False,
4748
  )