File size: 632 Bytes
936b659 71a7b83 936b659 71a7b83 936b659 71a7b83 936b659 | 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 | #!/usr/bin/env python
import pathlib
import gradio as gr
paths = [
path.as_posix() for path in sorted(pathlib.Path('images').rglob('*.jpg'))
]
def fn(data: gr.SelectData) -> int:
return data.index
with gr.Blocks() as demo:
gallery = gr.Gallery(value=paths,
allow_preview=False,
columns=2,
rows=2,
height='600px',
object_fit='scale-down')
selected_index = gr.Number(label='selected index', precision=0, value=-1)
gallery.select(fn=fn, outputs=selected_index)
demo.queue().launch()
|