rayli commited on
Commit
f43c521
·
verified ·
1 Parent(s): f0fc8c8

Warn but continue for large meshes

Browse files
Files changed (1) hide show
  1. app.py +10 -42
app.py CHANGED
@@ -109,7 +109,7 @@ AUTO_KINEMATICS_REASONING_EFFORT = "medium"
109
  AUTO_KINEMATICS_CACHE_VERSION = 3
110
  INFERENCE_NO_POINT_PROMPT = True
111
  INFERENCE_EXPORT_URDF_DURING_WRITE = False
112
- HIGH_FACE_COUNT_WARNING_THRESHOLD = 500_000
113
 
114
  DEFAULT_KINEMATIC_TREE = {
115
  "links": [
@@ -3699,10 +3699,11 @@ def _mesh_face_warning_update_from_face_count(face_count: int):
3699
  'font-size:14px!important;line-height:1.35!important;">'
3700
  '<strong style="color:var(--demo-warning-text,#78350f)!important;">'
3701
  f"Large mesh warning:</strong> this mesh has {face_count:,} faces. "
3702
- "That is too dense for this Space and can exhaust CPU resources. "
3703
- "Please upload a simplified mesh with fewer than "
3704
- f"{HIGH_FACE_COUNT_WARNING_THRESHOLD:,} faces; this upload will not be "
3705
- "rendered or sent to the point prompt picker.</div>"
 
3706
  ),
3707
  visible=True,
3708
  )
@@ -3844,24 +3845,6 @@ class InstructParticulateApp:
3844
  )
3845
  return
3846
  early_face_count = _obj_face_count_from_path(mesh_path)
3847
- if (
3848
- early_face_count is not None
3849
- and early_face_count > HIGH_FACE_COUNT_WARNING_THRESHOLD
3850
- ):
3851
- yield (
3852
- None,
3853
- None,
3854
- _mesh_face_warning_update_from_face_count(early_face_count),
3855
- default_tree_json,
3856
- default_point_prompt_json,
3857
- "",
3858
- *empty_orientation_previews,
3859
- "",
3860
- None,
3861
- gr.update(interactive=False),
3862
- gr.update(value=None, interactive=False),
3863
- )
3864
- return
3865
  try:
3866
  mesh_hash = _mesh_file_sha256(mesh_path)
3867
  mesh = load_trimesh(mesh_path)
@@ -3881,24 +3864,9 @@ class InstructParticulateApp:
3881
  )
3882
  return
3883
 
3884
- face_count = len(getattr(mesh, "faces", []))
3885
- if face_count > HIGH_FACE_COUNT_WARNING_THRESHOLD:
3886
- yield (
3887
- None,
3888
- None,
3889
- _mesh_face_warning_update_from_face_count(face_count),
3890
- default_tree_json,
3891
- default_point_prompt_json,
3892
- "",
3893
- *empty_orientation_previews,
3894
- "",
3895
- None,
3896
- gr.update(interactive=False),
3897
- gr.update(value=None, interactive=False),
3898
- )
3899
- return
3900
-
3901
- mesh_face_warning = _mesh_face_warning_update_from_face_count(face_count)
3902
  cached_upright_previews = _cached_upright_preview_items(mesh_hash)
3903
  rendering_orientation_previews = (
3904
  _upright_preview_paths(cached_upright_previews)
@@ -5054,7 +5022,7 @@ def create_gradio_app(app: InstructParticulateApp) -> gr.Blocks:
5054
  <p>Upload one object mesh and provide or extract a kinematic tree. The demo predicts part segmentation and joint parameters, then exports animated GLB and URDF assets.</p>
5055
  <h3>How to use the demo:</h3>
5056
  <ol>
5057
- <li><strong>Upload a mesh:</strong> use the Input Mesh panel or select an example. For reliable runs, use a simplified mesh with fewer than 500,000 faces.</li>
5058
  <li><strong>Choose the upright orientation:</strong> click the preview where the object is upright. This orientation is used for both auto-kinematic extraction and inference.</li>
5059
  <li><strong>Define the kinematic tree:</strong> edit links and joints manually, or click Extract Kinematic Structure to infer a starting tree and point prompts.</li>
5060
  <li><strong>Add optional point prompts:</strong> select a link in the Kinematic Tree Editor, then click the mesh in the Point Prompt Picker to mark a representative point for that link.</li>
 
109
  AUTO_KINEMATICS_CACHE_VERSION = 3
110
  INFERENCE_NO_POINT_PROMPT = True
111
  INFERENCE_EXPORT_URDF_DURING_WRITE = False
112
+ HIGH_FACE_COUNT_WARNING_THRESHOLD = 100_000
113
 
114
  DEFAULT_KINEMATIC_TREE = {
115
  "links": [
 
3699
  'font-size:14px!important;line-height:1.35!important;">'
3700
  '<strong style="color:var(--demo-warning-text,#78350f)!important;">'
3701
  f"Large mesh warning:</strong> this mesh has {face_count:,} faces. "
3702
+ "Meshes above "
3703
+ f"{HIGH_FACE_COUNT_WARNING_THRESHOLD:,} faces may exhaust this Space's "
3704
+ "CPU resources during rendering or post-processing. The app will "
3705
+ "continue, but a simplified mesh is recommended if the run becomes "
3706
+ "slow or fails.</div>"
3707
  ),
3708
  visible=True,
3709
  )
 
3845
  )
3846
  return
3847
  early_face_count = _obj_face_count_from_path(mesh_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3848
  try:
3849
  mesh_hash = _mesh_file_sha256(mesh_path)
3850
  mesh = load_trimesh(mesh_path)
 
3864
  )
3865
  return
3866
 
3867
+ face_count = int(len(getattr(mesh, "faces", [])))
3868
+ warning_face_count = max(face_count, int(early_face_count or 0))
3869
+ mesh_face_warning = _mesh_face_warning_update_from_face_count(warning_face_count)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3870
  cached_upright_previews = _cached_upright_preview_items(mesh_hash)
3871
  rendering_orientation_previews = (
3872
  _upright_preview_paths(cached_upright_previews)
 
5022
  <p>Upload one object mesh and provide or extract a kinematic tree. The demo predicts part segmentation and joint parameters, then exports animated GLB and URDF assets.</p>
5023
  <h3>How to use the demo:</h3>
5024
  <ol>
5025
+ <li><strong>Upload a mesh:</strong> use the Input Mesh panel or select an example. For reliable runs, use a simplified mesh with fewer than 100,000 faces.</li>
5026
  <li><strong>Choose the upright orientation:</strong> click the preview where the object is upright. This orientation is used for both auto-kinematic extraction and inference.</li>
5027
  <li><strong>Define the kinematic tree:</strong> edit links and joints manually, or click Extract Kinematic Structure to infer a starting tree and point prompts.</li>
5028
  <li><strong>Add optional point prompts:</strong> select a link in the Kinematic Tree Editor, then click the mesh in the Point Prompt Picker to mark a representative point for that link.</li>