Spaces:
Sleeping
Sleeping
File size: 911 Bytes
7a4f8fc 7b7c8b6 7a4f8fc | 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 | import gradio as gr
from PIL import Image
# Load or generate your images
image_paths = ["1.png", "2.png", "3.png", "4.png"]
images = [Image.open(path) for path in image_paths]
N = len(images)
def show_image(index):
index = index % N
return images[index], index
def next_img(index):
return show_image(index + 1)
def prev_img(index):
return show_image(index - 1)
with gr.Blocks() as demo:
index_state = gr.State(0)
img_display = gr.Image(type="pil")
with gr.Row():
prev_btn = gr.Button("⬅️ Previous")
next_btn = gr.Button("Next ➡️")
prev_btn.click(fn=prev_img, inputs=index_state, outputs=[img_display, index_state])
next_btn.click(fn=next_img, inputs=index_state, outputs=[img_display, index_state])
# Load the first image
demo.load(fn=show_image, inputs=index_state, outputs=[img_display, index_state])
demo.launch()
|