Spaces:
Running
on
Zero
Running
on
Zero
Ruining Li
commited on
Commit
·
8ab3df9
1
Parent(s):
e2cbdfe
Add image previews to example selection buttons in Gradio app
Browse filesUpdates the example selection UI to display PNG thumbnails for each example model instead of a generic list. Uses a gr.Dataset with image components to render the previews and handles selection via a click event to load the corresponding 3D model.
- app.py +22 -8
- examples/cabinet.png +3 -0
- examples/eyeglasses.png +3 -0
- examples/foldingchair.png +3 -0
- examples/laptop.png +3 -0
- examples/scissors.png +3 -0
- examples/toilet.png +3 -0
- examples/trashcan.png +3 -0
- examples/washingmachine.png +3 -0
app.py
CHANGED
|
@@ -250,11 +250,15 @@ def create_gradio_app(particulate_app):
|
|
| 250 |
# Get example files from examples folder
|
| 251 |
examples_dir = "examples"
|
| 252 |
example_files = []
|
|
|
|
| 253 |
if os.path.exists(examples_dir):
|
| 254 |
-
for file in os.listdir(examples_dir):
|
| 255 |
if file.lower().endswith(('.glb', '.obj')):
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
| 258 |
|
| 259 |
with gr.Blocks(title="Particulate Demo") as demo:
|
| 260 |
gr.HTML(
|
|
@@ -304,11 +308,21 @@ def create_gradio_app(particulate_app):
|
|
| 304 |
label="Upload 3D Model",
|
| 305 |
interactive=True
|
| 306 |
)
|
| 307 |
-
if example_files:
|
| 308 |
-
gr.
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
)
|
| 313 |
mesh_plot = gr.Plot(label="Mesh Preview")
|
| 314 |
|
|
|
|
| 250 |
# Get example files from examples folder
|
| 251 |
examples_dir = "examples"
|
| 252 |
example_files = []
|
| 253 |
+
example_images = []
|
| 254 |
if os.path.exists(examples_dir):
|
| 255 |
+
for file in sorted(os.listdir(examples_dir)):
|
| 256 |
if file.lower().endswith(('.glb', '.obj')):
|
| 257 |
+
base_name = os.path.splitext(file)[0]
|
| 258 |
+
png_path = os.path.join(examples_dir, base_name + ".png")
|
| 259 |
+
if os.path.exists(png_path):
|
| 260 |
+
example_files.append(os.path.join(examples_dir, file))
|
| 261 |
+
example_images.append(png_path)
|
| 262 |
|
| 263 |
with gr.Blocks(title="Particulate Demo") as demo:
|
| 264 |
gr.HTML(
|
|
|
|
| 308 |
label="Upload 3D Model",
|
| 309 |
interactive=True
|
| 310 |
)
|
| 311 |
+
if example_files and example_images:
|
| 312 |
+
example_dataset = gr.Dataset(
|
| 313 |
+
label="Example Models",
|
| 314 |
+
components=[gr.Image(visible=False)],
|
| 315 |
+
samples=[[img] for img in example_images],
|
| 316 |
+
type="index"
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
def load_example(index):
|
| 320 |
+
return example_files[index]
|
| 321 |
+
|
| 322 |
+
example_dataset.click(
|
| 323 |
+
fn=load_example,
|
| 324 |
+
inputs=[example_dataset],
|
| 325 |
+
outputs=[input_mesh]
|
| 326 |
)
|
| 327 |
mesh_plot = gr.Plot(label="Mesh Preview")
|
| 328 |
|
examples/cabinet.png
ADDED
|
Git LFS Details
|
examples/eyeglasses.png
ADDED
|
Git LFS Details
|
examples/foldingchair.png
ADDED
|
Git LFS Details
|
examples/laptop.png
ADDED
|
Git LFS Details
|
examples/scissors.png
ADDED
|
Git LFS Details
|
examples/toilet.png
ADDED
|
Git LFS Details
|
examples/trashcan.png
ADDED
|
Git LFS Details
|
examples/washingmachine.png
ADDED
|
Git LFS Details
|