taesiri commited on
Commit
654b942
1 Parent(s): c1a6c5e
Files changed (2) hide show
  1. app.py +37 -27
  2. requirements.txt +2 -1
app.py CHANGED
@@ -16,6 +16,15 @@ all_origins = set()
16
  all_labels = set()
17
  dataset_df = None
18
 
 
 
 
 
 
 
 
 
 
19
 
20
  def process_image(i):
21
  global all_origins
@@ -61,6 +70,26 @@ else:
61
  dataset_df.to_pickle("dataset.pkl")
62
 
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  def get_slice(origin, label):
65
  global dataset_df
66
 
@@ -74,20 +103,11 @@ def get_slice(origin, label):
74
 
75
  max_value = len(filtered_df) // 16
76
 
77
- returned_values = []
78
-
79
  start_index = 0
80
  end_index = start_index + 16
81
 
82
  slice_df = filtered_df.iloc[start_index:end_index]
83
-
84
- for row in slice_df.itertuples():
85
- returned_values.append(gr.update(value=row.preview))
86
- returned_values.append(gr.update(value=row.origin))
87
- returned_values.append(gr.update(value=row.labels))
88
-
89
- if len(returned_values) < 48:
90
- returned_values.extend([None] * (48 - len(returned_values)))
91
 
92
  filtered_df = gr.Dataframe(filtered_df, datatype="markdown")
93
  return filtered_df, gr.update(maximum=max_value, value=0), *returned_values
@@ -105,32 +125,22 @@ def make_grid(grid_size):
105
  with gr.Column():
106
  for col_counter in range(grid_size[1]):
107
  item_image = gr.Image()
108
- with gr.Accordion("Click for details", open=False):
109
- item_source = gr.Textbox(label="Source Dataset")
110
- item_labels = gr.Textbox(label="Labels")
111
 
112
  list_of_components.append(item_image)
113
- list_of_components.append(item_source)
114
- list_of_components.append(item_labels)
115
 
116
  return list_of_components
117
 
118
 
119
  def slider_upadte(slider, df):
120
- returned_values = []
121
-
122
  start_index = (slider) * 16
123
  end_index = start_index + 16
124
 
125
  slice_df = df.iloc[start_index:end_index]
126
-
127
- for row in slice_df.itertuples():
128
- returned_values.append(gr.update(value=row.preview))
129
- returned_values.append(gr.update(value=row.origin))
130
- returned_values.append(gr.update(value=row.labels))
131
-
132
- if len(returned_values) < 48:
133
- returned_values.extend([None] * (48 - len(returned_values)))
134
 
135
  return returned_values
136
 
@@ -153,12 +163,12 @@ with gr.Blocks() as demo:
153
 
154
  with gr.Row():
155
  origin_dropdown = gr.Dropdown(all_origins, label="Origin")
156
- label_dropdown = gr.Dropdown(all_labels, label="Label")
157
  with gr.Row():
158
  show_btn = gr.Button("Show")
159
  reset_filters = gr.Button("Reset Filters")
160
 
161
- preview_dataframe = gr.Dataframe(height=500, visible=False)
162
 
163
  gr.Markdown("## Preview")
164
 
 
16
  all_labels = set()
17
  dataset_df = None
18
 
19
+ beautiful_dataset_names = {
20
+ "imagenet": "ImageNet",
21
+ "imagenet_a": "ImageNet-A",
22
+ "imagenet_r": "ImageNet-R",
23
+ "imagenet_sketch": "ImageNet-Sketch",
24
+ "objectnet": "ObjectNet",
25
+ "imagenet_v2": "ImageNet-V2",
26
+ }
27
+
28
 
29
  def process_image(i):
30
  global all_origins
 
70
  dataset_df.to_pickle("dataset.pkl")
71
 
72
 
73
+ def get_values_for_the_slice(slice_df):
74
+ returned_values = []
75
+ for row in slice_df.itertuples():
76
+ # returned_values.append(gr.update(value=row.preview))
77
+ labels = ", ".join(row.labels)
78
+ # replace _ with space
79
+ labels = labels.replace("_", " ")
80
+
81
+ dataset_name = beautiful_dataset_names[row.origin]
82
+
83
+ label_string = f"{labels} - ({dataset_name})"
84
+ returned_values.append(gr.update(label=label_string, value=row.preview))
85
+ # returned_values.append(gr.update(value=beautiful_dataset_names[row.origin]))
86
+
87
+ if len(returned_values) < 16:
88
+ returned_values.extend([None] * (16 - len(returned_values)))
89
+
90
+ return returned_values
91
+
92
+
93
  def get_slice(origin, label):
94
  global dataset_df
95
 
 
103
 
104
  max_value = len(filtered_df) // 16
105
 
 
 
106
  start_index = 0
107
  end_index = start_index + 16
108
 
109
  slice_df = filtered_df.iloc[start_index:end_index]
110
+ returned_values = get_values_for_the_slice(slice_df)
 
 
 
 
 
 
 
111
 
112
  filtered_df = gr.Dataframe(filtered_df, datatype="markdown")
113
  return filtered_df, gr.update(maximum=max_value, value=0), *returned_values
 
125
  with gr.Column():
126
  for col_counter in range(grid_size[1]):
127
  item_image = gr.Image()
128
+ # with gr.Accordion("Click for details", open=False):
129
+ # item_source = gr.Textbox(label="Source Dataset")
 
130
 
131
  list_of_components.append(item_image)
132
+ # list_of_components.append(item_source)
133
+ # list_of_components.append(item_labels)
134
 
135
  return list_of_components
136
 
137
 
138
  def slider_upadte(slider, df):
 
 
139
  start_index = (slider) * 16
140
  end_index = start_index + 16
141
 
142
  slice_df = df.iloc[start_index:end_index]
143
+ returned_values = get_values_for_the_slice(slice_df)
 
 
 
 
 
 
 
144
 
145
  return returned_values
146
 
 
163
 
164
  with gr.Row():
165
  origin_dropdown = gr.Dropdown(all_origins, label="Origin")
166
+ label_dropdown = gr.Dropdown(all_labels, label="Category")
167
  with gr.Row():
168
  show_btn = gr.Button("Show")
169
  reset_filters = gr.Button("Reset Filters")
170
 
171
+ preview_dataframe = gr.Dataframe(visible=False)
172
 
173
  gr.Markdown("## Preview")
174
 
requirements.txt CHANGED
@@ -2,4 +2,5 @@ transformers
2
  datasets
3
  tqdm
4
  numpy
5
- pandas
 
 
2
  datasets
3
  tqdm
4
  numpy
5
+ pandas
6
+ tqdm