File size: 897 Bytes
868a700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

pins = []

def pin_image(image, caption):
    pins.append((image, caption))
    return update_gallery()

def update_gallery():
    gallery = [(img, cap) for img, cap in pins]
    return gallery

def clear_gallery():
    pins.clear()
    return []

with gr.Blocks() as demo:
    gr.Markdown("# ⚡ Beautiful Pins\nCreate your personal pinboard")

    with gr.Row():
        image_input = gr.Image(type="pil", label="Upload an Image")
        caption_input = gr.Textbox(placeholder="Add a caption...", label="Caption")

    with gr.Row():
        pin_btn = gr.Button("📌 Pin it")
        clear_btn = gr.Button("🧹 Clear All")

    gallery = gr.Gallery(label="📌 Your Pins", show_label=True, columns=3, height=400)

    pin_btn.click(fn=pin_image, inputs=[image_input, caption_input], outputs=gallery)
    clear_btn.click(fn=clear_gallery, outputs=gallery)

demo.launch()