Replacing images at runtime

Hi Radames, Thanks for responding so quickly!

This is just for the slideshow player I mentioned:

import os
import gradio as gr
from gradio import State
import time
import threading

Directory containing images

image_directory = โ€œโ€

List all image files in the directory

image_files = [f for f in os.listdir(image_directory) if f.endswith((โ€œ.pngโ€, โ€œ.jpgโ€, โ€œ.jpegโ€))]

Initial image configuration

INITIAL_IMAGE = os.path.join(image_directory, image_files[0])
IMAGE_WIDTH = 768
IMAGE_HEIGHT = 768
image_state = State(INITIAL_IMAGE)

Set the image displayed in the Gradio interface

def set_image(image_path):
image_state.value = image_path

def update_image():
for image_file in image_files:
image_path = os.path.join(image_directory, image_file)
set_image(image_path)
time.sleep(1)

def start_slideshow():
thread = threading.Thread(target=update_image)
thread.start()

with gr.Blocks() as slideshow:
with gr.Row():
image = gr.Image(value=INITIAL_IMAGE).style(width=IMAGE_WIDTH, height=IMAGE_HEIGHT)

with gr.Row():
    update_button = gr.Button("Start Slideshow")

    update_button.click(start_slideshow)

if name == โ€œmainโ€:
slideshow.launch()