Spaces:
Sleeping
Sleeping
File size: 2,102 Bytes
783e164 |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#!/usr/bin/env python
import pathlib
import gradio as gr
def set_example_image(example):
return [
gr.Image.update(value=example[0]),
gr.Image.update(value=example[1])
]
def set_example_video(example):
return [
gr.Video.update(value=example[0]),
gr.Video.update(value=example[1])
]
css = '''
div#image1 {
max-width: 300px;
max-height: 300px;
}
div#image2 {
max-width: 300px;
max-height: 300px;
}
div#video1 {
max-width: 300px;
max-height: 300px;
}
div#video2 {
max-width: 300px;
max-height: 300px;
}
'''
with gr.Blocks(css=css) as demo:
with gr.Row():
image1 = gr.Image(label='without gr.Group',
type='numpy',
elem_id='image1')
with gr.Group():
image2 = gr.Image(label='with gr.Group',
type='numpy',
elem_id='image2')
paths = sorted(pathlib.Path('images').rglob('*.jpg'))
example_images = gr.Dataset(components=[image1, image2],
samples=[[path.as_posix(),
path.as_posix()] for path in paths])
with gr.Row():
video1 = gr.Video(label='without gr.Group',
format='mp4',
elem_id='video1')
with gr.Group():
video2 = gr.Video(label='with gr.Group',
format='mp4',
elem_id='video2')
paths = sorted(pathlib.Path('videos').rglob('*.mp4'))
example_videos = gr.Dataset(components=[video1, video2],
samples=[[path.as_posix(),
path.as_posix()] for path in paths])
example_images.click(fn=set_example_image,
inputs=example_images,
outputs=example_images.components)
example_videos.click(fn=set_example_video,
inputs=example_videos,
outputs=example_videos.components)
demo.launch()
|