File size: 1,743 Bytes
e1c010e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
src/ui/examples.py — Demo image loader for the Gradio Examples component.

Reads demo images from the configured assets directory and pairs each
image with a contextually appropriate natural-language command.
"""

from pathlib import Path

from src.utils.config import DEMO_IMAGES_DIR


# Map each demo image filename to a curated command
_IMAGE_COMMANDS: dict[str, str] = {
    "assembly_line.jpg":     "Pick up the defective board and place it in the red bin",
    "construction_site.jpg": "Move the hard hat next to the gloves",
    "desk_scene.jpg":        "Pick up the bottle and place it in the box",
    "garage_tools.jpg":      "Place the wrench back into the toolbox",
    "grocery_shelf.jpg":     "Move the water bottle into the shopping basket",
    "kitchen_counter.jpg":   "Pick up the apple and place it in the bowl",
    "lab_equipment.jpg":     "Move the bottle next to the microscope",
    "medical_tray.jpg":      "Pick up the scissors and place them on the tray",
    "office_supplies.jpg":   "Move the phone next to the laptop",
    "warehouse_boxes.jpg":   "Move the closest box onto the hand truck",
}


def get_demo_examples() -> list[list]:
    """
    Return a list of ``[image_path, command]`` pairs for Gradio Examples.

    Returns:
        Sorted list of ``[str, str]`` pairs, one per demo image found on disk.
        Returns an empty list if the demo images directory does not exist.
    """
    demo_dir = Path(DEMO_IMAGES_DIR)
    if not demo_dir.exists():
        return []

    examples: list[list] = []
    for img_path in sorted(demo_dir.glob("*.jpg")):
        cmd = _IMAGE_COMMANDS.get(img_path.name, "Inspect the closest object")
        examples.append([str(img_path), cmd])

    return examples