Spaces:
Running
Running
init
Browse files- app.py +57 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from PIL import Image
|
4 |
+
from io import BytesIO
|
5 |
+
|
6 |
+
# A simple function to simulate different sets of images for each option
|
7 |
+
def show_images(option):
|
8 |
+
image_data = [
|
9 |
+
{
|
10 |
+
"title": "Option 1",
|
11 |
+
"caption": "Images for Option 1",
|
12 |
+
"urls": [
|
13 |
+
"https://via.placeholder.com/150/1",
|
14 |
+
"https://via.placeholder.com/150/2",
|
15 |
+
"https://via.placeholder.com/150/3",
|
16 |
+
"https://via.placeholder.com/150/4",
|
17 |
+
"https://via.placeholder.com/150/5",
|
18 |
+
],
|
19 |
+
},
|
20 |
+
{
|
21 |
+
"title": "Option 2",
|
22 |
+
"caption": "Images for Option 2",
|
23 |
+
"urls": [
|
24 |
+
"https://via.placeholder.com/150/6",
|
25 |
+
"https://via.placeholder.com/150/7",
|
26 |
+
"https://via.placeholder.com/150/8",
|
27 |
+
"https://via.placeholder.com/150/9",
|
28 |
+
"https://via.placeholder.com/150/10",
|
29 |
+
],
|
30 |
+
},
|
31 |
+
# Add more dictionaries for other options with their respective title, caption, and image URLs
|
32 |
+
]
|
33 |
+
|
34 |
+
selected_option = image_data[int(option) - 1]
|
35 |
+
|
36 |
+
images = []
|
37 |
+
for url in selected_option["urls"]:
|
38 |
+
response = requests.get(url)
|
39 |
+
img = Image.open(BytesIO(response.content))
|
40 |
+
images.append(img)
|
41 |
+
|
42 |
+
return selected_option["title"], selected_option["caption"], images
|
43 |
+
|
44 |
+
# Define the Gradio interface
|
45 |
+
iface = gr.Interface(
|
46 |
+
fn=show_images,
|
47 |
+
inputs=gr.inputs.Radio(["1", "2"], label="Choose an option"),
|
48 |
+
outputs=[
|
49 |
+
gr.outputs.Textbox(label="Title"),
|
50 |
+
gr.outputs.Textbox(label="Caption"),
|
51 |
+
gr.outputs.Image(type="pil", label="Images", num_outputs=5),
|
52 |
+
],
|
53 |
+
examples_per_option=None,
|
54 |
+
)
|
55 |
+
|
56 |
+
# Launch the Gradio interface
|
57 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
Pillow
|