Spaces:
Runtime error
Runtime error
File size: 1,213 Bytes
e8d1963 3255474 e8d1963 3255474 e8d1963 3255474 e8d1963 3255474 e8d1963 3255474 e8d1963 3255474 |
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 |
import gradio as gr
import os
# Get all images in the folder, sorted by filename
image_dir = "/tmp/video/frames"
image_paths = sorted([
os.path.join(image_dir, f)
for f in os.listdir(image_dir)
if f.endswith(".jpg")
])
def get_image(index):
# Make sure the index is within bounds
if 0 <= index < len(image_paths):
return image_paths[index], index
return None, index # No change if out of bounds
def next_image(current_index):
next_index = current_index + 1
return get_image(next_index)
def previous_image(current_index):
prev_index = current_index - 1
return get_image(prev_index)
# with gr.Blocks() as demo:
# gr.Markdown("### Browse Keyframes")
# image = gr.Image()
# index_state = gr.State(0) # Track current index
# with gr.Row():
# prev_btn = gr.Button("Previous")
# next_btn = gr.Button("Next")
# next_btn.click(fn=next_image, inputs=index_state, outputs=[image, index_state])
# prev_btn.click(fn=previous_image, inputs=index_state, outputs=[image, index_state])
# # Initialize with first image
# demo.load(fn=get_image, inputs=index_state, outputs=[image, index_state])
# demo.launch()
|