Jason Adrian commited on
Commit
6c52afe
·
1 Parent(s): ef3c636

multiple images

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -5,7 +5,8 @@ class_names = ['cat', 'dog']
5
 
6
  def update_dropdown(className):
7
  class_names.append(className)
8
- return gr.Dropdown(choices=class_names)
 
9
 
10
  def show_picked_class(className):
11
  return className
@@ -30,6 +31,8 @@ def image_classifier(inp):
30
  demo = gr.Blocks()
31
 
32
  with demo as app:
 
 
33
  with gr.Row():
34
  with gr.Column():
35
  inp_img = gr.Image()
@@ -57,5 +60,39 @@ with demo as app:
57
  inputs=None,
58
  outputs=[inp_img, out_txt])
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  demo.launch(debug=True)
 
5
 
6
  def update_dropdown(className):
7
  class_names.append(className)
8
+ updated_choices = gr.Dropdown(choices=class_names)
9
+ return updated_choices
10
 
11
  def show_picked_class(className):
12
  return className
 
31
  demo = gr.Blocks()
32
 
33
  with demo as app:
34
+ gr.Markdown("# Single Image")
35
+
36
  with gr.Row():
37
  with gr.Column():
38
  inp_img = gr.Image()
 
60
  inputs=None,
61
  outputs=[inp_img, out_txt])
62
 
63
+ gr.Markdown("# Multiple Images")
64
+
65
+ def show_to_gallery(images):
66
+ file_paths = [[file.name, class_names[0]] for file in images]
67
+ # print(file_paths)
68
+ return file_paths, file_paths
69
+
70
+ def get_select_index(evt: gr.SelectData):
71
+ # print("data",evt._data)
72
+ # print("value",evt.value)
73
+ return evt.index
74
+
75
+ with gr.Column():
76
+ imgs = gr.State()
77
+
78
+ multiple_inputs = gr.UploadButton(label="Upload multiple images file here.", file_count="multiple", file_types=["image"])
79
+ gallery = gr.Gallery()
80
+ selected = gr.Textbox(label="Image Gallery Index")
81
+
82
+ images_label = gr.Dropdown(class_names, label="Class Label", multiselect=False)
83
+ b3 = gr.Button("Save and change the label using dropdown")
84
+
85
+ multiple_inputs.upload(show_to_gallery, inputs=multiple_inputs, outputs=[gallery, imgs])
86
+
87
+ gallery.select(get_select_index, None, selected)
88
+
89
+ def change_labels(imgs, index, images_label):
90
+ index = int(index)
91
+ label_idx = class_names.index(images_label)
92
+ imgs[index][1] = class_names[label_idx]
93
+ return imgs, imgs
94
+
95
+ b3.click(change_labels, [imgs, selected, images_label], [imgs, gallery])
96
+
97
 
98
  demo.launch(debug=True)