b-aryan's picture
Update app.py
7b7c8b6 verified
raw
history blame contribute delete
911 Bytes
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()