Spaces:
Running on Zero
Running on Zero
Avoid duplicate mesh registration updates
Browse files
app.py
CHANGED
|
@@ -3815,11 +3815,13 @@ class InstructParticulateApp:
|
|
| 3815 |
def register_mesh(
|
| 3816 |
self,
|
| 3817 |
mesh_value: Any,
|
|
|
|
| 3818 |
):
|
| 3819 |
empty_orientation_previews = [None] * len(UP_DIR_CHOICES)
|
| 3820 |
default_tree_json = _tree_to_pretty_json(DEFAULT_KINEMATIC_TREE)
|
| 3821 |
default_point_prompt_json = '{"prompts":[]}'
|
| 3822 |
hidden_mesh_face_warning = ""
|
|
|
|
| 3823 |
mesh_path = _extract_gradio_path(mesh_value)
|
| 3824 |
if mesh_path is None:
|
| 3825 |
yield (
|
|
@@ -3839,6 +3841,27 @@ class InstructParticulateApp:
|
|
| 3839 |
early_face_count = _obj_face_count_from_path(mesh_path)
|
| 3840 |
try:
|
| 3841 |
mesh_hash = _mesh_file_sha256(mesh_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3842 |
mesh = load_trimesh(mesh_path)
|
| 3843 |
except Exception:
|
| 3844 |
yield (
|
|
@@ -3865,37 +3888,11 @@ class InstructParticulateApp:
|
|
| 3865 |
if cached_upright_previews is not None
|
| 3866 |
else _upright_rendering_preview_paths()
|
| 3867 |
)
|
| 3868 |
-
yield (
|
| 3869 |
-
str(mesh_path),
|
| 3870 |
-
mesh_hash,
|
| 3871 |
-
mesh_face_warning,
|
| 3872 |
-
default_tree_json,
|
| 3873 |
-
default_point_prompt_json,
|
| 3874 |
-
"",
|
| 3875 |
-
*rendering_orientation_previews,
|
| 3876 |
-
"",
|
| 3877 |
-
None,
|
| 3878 |
-
gr.update(interactive=False),
|
| 3879 |
-
gr.update(value=None, interactive=False),
|
| 3880 |
-
)
|
| 3881 |
|
| 3882 |
try:
|
| 3883 |
prompt_mesh_data = _prompt_mesh_payload(mesh)
|
| 3884 |
except Exception:
|
| 3885 |
-
|
| 3886 |
-
str(mesh_path),
|
| 3887 |
-
mesh_hash,
|
| 3888 |
-
mesh_face_warning,
|
| 3889 |
-
default_tree_json,
|
| 3890 |
-
default_point_prompt_json,
|
| 3891 |
-
"",
|
| 3892 |
-
*rendering_orientation_previews,
|
| 3893 |
-
"",
|
| 3894 |
-
None,
|
| 3895 |
-
gr.update(interactive=False),
|
| 3896 |
-
gr.update(value=None, interactive=False),
|
| 3897 |
-
)
|
| 3898 |
-
return
|
| 3899 |
|
| 3900 |
yield (
|
| 3901 |
str(mesh_path),
|
|
@@ -3910,20 +3907,8 @@ class InstructParticulateApp:
|
|
| 3910 |
gr.update(interactive=False),
|
| 3911 |
gr.update(value=None, interactive=False),
|
| 3912 |
)
|
|
|
|
| 3913 |
if cached_upright_previews is not None:
|
| 3914 |
-
yield (
|
| 3915 |
-
str(mesh_path),
|
| 3916 |
-
mesh_hash,
|
| 3917 |
-
mesh_face_warning,
|
| 3918 |
-
default_tree_json,
|
| 3919 |
-
default_point_prompt_json,
|
| 3920 |
-
prompt_mesh_data,
|
| 3921 |
-
*_upright_preview_paths(cached_upright_previews),
|
| 3922 |
-
"",
|
| 3923 |
-
None,
|
| 3924 |
-
gr.update(interactive=False),
|
| 3925 |
-
gr.update(value=None, interactive=False),
|
| 3926 |
-
)
|
| 3927 |
return
|
| 3928 |
|
| 3929 |
try:
|
|
@@ -3942,10 +3927,10 @@ class InstructParticulateApp:
|
|
| 3942 |
default_point_prompt_json,
|
| 3943 |
prompt_mesh_data,
|
| 3944 |
*empty_orientation_previews,
|
| 3945 |
-
|
| 3946 |
-
|
| 3947 |
-
gr.
|
| 3948 |
-
gr.
|
| 3949 |
)
|
| 3950 |
return
|
| 3951 |
|
|
@@ -3957,10 +3942,10 @@ class InstructParticulateApp:
|
|
| 3957 |
default_point_prompt_json,
|
| 3958 |
prompt_mesh_data,
|
| 3959 |
*_upright_preview_paths(upright_previews),
|
| 3960 |
-
|
| 3961 |
-
|
| 3962 |
-
gr.
|
| 3963 |
-
gr.
|
| 3964 |
)
|
| 3965 |
|
| 3966 |
def select_example_mesh(self, selected_index_value: Any):
|
|
@@ -5223,7 +5208,7 @@ def create_gradio_app(app: InstructParticulateApp) -> gr.Blocks:
|
|
| 5223 |
|
| 5224 |
input_mesh.change(
|
| 5225 |
fn=app.register_mesh,
|
| 5226 |
-
inputs=[input_mesh],
|
| 5227 |
outputs=[
|
| 5228 |
loaded_mesh_path,
|
| 5229 |
loaded_mesh_hash,
|
|
|
|
| 3815 |
def register_mesh(
|
| 3816 |
self,
|
| 3817 |
mesh_value: Any,
|
| 3818 |
+
current_mesh_hash: Any = None,
|
| 3819 |
):
|
| 3820 |
empty_orientation_previews = [None] * len(UP_DIR_CHOICES)
|
| 3821 |
default_tree_json = _tree_to_pretty_json(DEFAULT_KINEMATIC_TREE)
|
| 3822 |
default_point_prompt_json = '{"prompts":[]}'
|
| 3823 |
hidden_mesh_face_warning = ""
|
| 3824 |
+
skip_outputs = tuple(gr.skip() for _ in range(16))
|
| 3825 |
mesh_path = _extract_gradio_path(mesh_value)
|
| 3826 |
if mesh_path is None:
|
| 3827 |
yield (
|
|
|
|
| 3841 |
early_face_count = _obj_face_count_from_path(mesh_path)
|
| 3842 |
try:
|
| 3843 |
mesh_hash = _mesh_file_sha256(mesh_path)
|
| 3844 |
+
except Exception:
|
| 3845 |
+
yield (
|
| 3846 |
+
None,
|
| 3847 |
+
None,
|
| 3848 |
+
hidden_mesh_face_warning,
|
| 3849 |
+
default_tree_json,
|
| 3850 |
+
default_point_prompt_json,
|
| 3851 |
+
"",
|
| 3852 |
+
*empty_orientation_previews,
|
| 3853 |
+
"",
|
| 3854 |
+
None,
|
| 3855 |
+
gr.update(interactive=False),
|
| 3856 |
+
gr.update(value=None, interactive=False),
|
| 3857 |
+
)
|
| 3858 |
+
return
|
| 3859 |
+
|
| 3860 |
+
if str(current_mesh_hash or "").strip() == mesh_hash:
|
| 3861 |
+
yield skip_outputs
|
| 3862 |
+
return
|
| 3863 |
+
|
| 3864 |
+
try:
|
| 3865 |
mesh = load_trimesh(mesh_path)
|
| 3866 |
except Exception:
|
| 3867 |
yield (
|
|
|
|
| 3888 |
if cached_upright_previews is not None
|
| 3889 |
else _upright_rendering_preview_paths()
|
| 3890 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3891 |
|
| 3892 |
try:
|
| 3893 |
prompt_mesh_data = _prompt_mesh_payload(mesh)
|
| 3894 |
except Exception:
|
| 3895 |
+
prompt_mesh_data = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3896 |
|
| 3897 |
yield (
|
| 3898 |
str(mesh_path),
|
|
|
|
| 3907 |
gr.update(interactive=False),
|
| 3908 |
gr.update(value=None, interactive=False),
|
| 3909 |
)
|
| 3910 |
+
|
| 3911 |
if cached_upright_previews is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3912 |
return
|
| 3913 |
|
| 3914 |
try:
|
|
|
|
| 3927 |
default_point_prompt_json,
|
| 3928 |
prompt_mesh_data,
|
| 3929 |
*empty_orientation_previews,
|
| 3930 |
+
gr.skip(),
|
| 3931 |
+
gr.skip(),
|
| 3932 |
+
gr.skip(),
|
| 3933 |
+
gr.skip(),
|
| 3934 |
)
|
| 3935 |
return
|
| 3936 |
|
|
|
|
| 3942 |
default_point_prompt_json,
|
| 3943 |
prompt_mesh_data,
|
| 3944 |
*_upright_preview_paths(upright_previews),
|
| 3945 |
+
gr.skip(),
|
| 3946 |
+
gr.skip(),
|
| 3947 |
+
gr.skip(),
|
| 3948 |
+
gr.skip(),
|
| 3949 |
)
|
| 3950 |
|
| 3951 |
def select_example_mesh(self, selected_index_value: Any):
|
|
|
|
| 5208 |
|
| 5209 |
input_mesh.change(
|
| 5210 |
fn=app.register_mesh,
|
| 5211 |
+
inputs=[input_mesh, loaded_mesh_hash],
|
| 5212 |
outputs=[
|
| 5213 |
loaded_mesh_path,
|
| 5214 |
loaded_mesh_hash,
|