Ruining Li commited on
Commit
8ab3df9
·
1 Parent(s): e2cbdfe

Add image previews to example selection buttons in Gradio app

Browse files

Updates 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 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
- example_files.append(os.path.join(examples_dir, file))
257
- example_files.sort() # Sort for consistent ordering
 
 
 
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.Examples(
309
- examples=[[file] for file in example_files],
310
- inputs=[input_mesh],
311
- label="Example Models"
 
 
 
 
 
 
 
 
 
 
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

  • SHA256: 1e199d7839dc4d6bccb78f7dc54d711eb16efc09498a783dd41194f8fe9a67fa
  • Pointer size: 131 Bytes
  • Size of remote file: 164 kB
examples/eyeglasses.png ADDED

Git LFS Details

  • SHA256: d032d69769ed561a2c5207ad1c33a4e7b0d44a33fe14152fb9cbe0fef3275a45
  • Pointer size: 131 Bytes
  • Size of remote file: 110 kB
examples/foldingchair.png ADDED

Git LFS Details

  • SHA256: 31cf50e7819854ed4f222709f4b45607da543a97a954c95f21c2d3ac34b4e5b8
  • Pointer size: 131 Bytes
  • Size of remote file: 144 kB
examples/laptop.png ADDED

Git LFS Details

  • SHA256: 02c1bfa857b8ff81c9e8655d0a845967b2708498b6094a00cdf5f52d25839346
  • Pointer size: 131 Bytes
  • Size of remote file: 209 kB
examples/scissors.png ADDED

Git LFS Details

  • SHA256: 55582bab51c7ea606f45226c018c086651833ba29eaf4b3cc85f094a884a4fbf
  • Pointer size: 130 Bytes
  • Size of remote file: 88.1 kB
examples/toilet.png ADDED

Git LFS Details

  • SHA256: adad43f9416825d64b379a8c2c054e2e30a437c1d37606ac943319b517259b5e
  • Pointer size: 131 Bytes
  • Size of remote file: 138 kB
examples/trashcan.png ADDED

Git LFS Details

  • SHA256: 094b9ab892972efa7bf519e5c20fbe612daa6a7d55829ba2c6493e2b6e13ee1c
  • Pointer size: 131 Bytes
  • Size of remote file: 132 kB
examples/washingmachine.png ADDED

Git LFS Details

  • SHA256: cc4b28cfb66e923fdeb9814e928db7a315ce7e2637e3f05a10d6909e0a4bb38e
  • Pointer size: 131 Bytes
  • Size of remote file: 180 kB