Spaces:
Sleeping
Sleeping
| 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() | |