import gradio as gr import requests from PIL import Image from io import BytesIO # A simple function to simulate different sets of images for each option def show_images(option): image_data = [ { "title": "Option 1", "caption": "Images for Option 1", "urls": [ "https://via.placeholder.com/150/1", "https://via.placeholder.com/150/2", "https://via.placeholder.com/150/3", "https://via.placeholder.com/150/4", "https://via.placeholder.com/150/5", ], }, { "title": "Option 2", "caption": "Images for Option 2", "urls": [ "https://via.placeholder.com/150/6", "https://via.placeholder.com/150/7", "https://via.placeholder.com/150/8", "https://via.placeholder.com/150/9", "https://via.placeholder.com/150/10", ], }, # Add more dictionaries for other options with their respective title, caption, and image URLs ] selected_option = image_data[int(option) - 1] images = [] for url in selected_option["urls"]: response = requests.get(url) img = Image.open(BytesIO(response.content)) images.append(img) return selected_option["title"], selected_option["caption"], images # Define the Gradio interface iface = gr.Interface( fn=show_images, inputs=gr.inputs.Radio(["1", "2"], label="Choose an option"), outputs=[ gr.outputs.Textbox(label="Title"), gr.outputs.Textbox(label="Caption"), gr.outputs.Image(type="pil", label="Images"), ], output_type="list", examples_per_option=None, ) # Launch the Gradio interface iface.launch()