ariG23498 HF staff commited on
Commit
df0d9bc
1 Parent(s): 7d9a730

using tabs

Browse files
Files changed (2) hide show
  1. app.py +28 -53
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,58 +1,33 @@
 
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"),
52
- ],
53
- output_type="list",
54
- examples_per_option=None,
55
- )
56
-
57
- # Launch the Gradio interface
58
- iface.launch()
 
1
+ import numpy as np
2
  import gradio as gr
 
 
 
3
 
4
+ urls = [
5
+ "https://via.placeholder.com/150/1",
6
+ "https://via.placeholder.com/150/2",
7
+ "https://via.placeholder.com/150/3",
8
+ "https://via.placeholder.com/150/4",
9
+ "https://via.placeholder.com/150/5",
10
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # Add your image files here
13
+ img1 = urls[0]
14
+ img2 = urls[1]
15
+ img3 = urls[2]
16
+ img4 = urls[3]
17
+ img5 = urls[4]
18
 
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("Select a tab to display a corresponding image.")
21
+ with gr.Tabs() as tabs:
22
+ with gr.Tab("Image 1"):
23
+ image1 = gr.Image(src=img1)
24
+ with gr.Tab("Image 2"):
25
+ image2 = gr.Image(src=img2)
26
+ with gr.Tab("Image 3"):
27
+ image3 = gr.Image(src=img3)
28
+ with gr.Tab("Image 4"):
29
+ image4 = gr.Image(src=img4)
30
+ with gr.Tab("Image 5"):
31
+ image5 = gr.Image(src=img5)
32
 
33
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  gradio
2
- Pillow
 
1
  gradio
2
+ numpy