Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
# Load or generate your images
|
| 5 |
+
image_paths = ["1.jpg", "2.jpg", "3.jpg"]
|
| 6 |
+
images = [Image.open(path) for path in image_paths]
|
| 7 |
+
N = len(images)
|
| 8 |
+
|
| 9 |
+
def show_image(index):
|
| 10 |
+
index = index % N
|
| 11 |
+
return images[index], index
|
| 12 |
+
|
| 13 |
+
def next_img(index):
|
| 14 |
+
return show_image(index + 1)
|
| 15 |
+
|
| 16 |
+
def prev_img(index):
|
| 17 |
+
return show_image(index - 1)
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
index_state = gr.State(0)
|
| 21 |
+
|
| 22 |
+
img_display = gr.Image(type="pil")
|
| 23 |
+
|
| 24 |
+
with gr.Row():
|
| 25 |
+
prev_btn = gr.Button("⬅️ Previous")
|
| 26 |
+
next_btn = gr.Button("Next ➡️")
|
| 27 |
+
|
| 28 |
+
prev_btn.click(fn=prev_img, inputs=index_state, outputs=[img_display, index_state])
|
| 29 |
+
next_btn.click(fn=next_img, inputs=index_state, outputs=[img_display, index_state])
|
| 30 |
+
|
| 31 |
+
# Load the first image
|
| 32 |
+
demo.load(fn=show_image, inputs=index_state, outputs=[img_display, index_state])
|
| 33 |
+
|
| 34 |
+
demo.launch()
|