Spaces:
Runtime error
Runtime error
Add conditioning, row filtering, fix ranking, markdown header
Browse files
app.py
CHANGED
@@ -27,6 +27,7 @@ EXPECTED_KEY_TO_COLNAME = OrderedDict(
|
|
27 |
("rank", "Rank"), # Just for columns order
|
28 |
("model", "Model"), # Just for columns order
|
29 |
("model_size", "Model Size (Million)"), # Just for columns order
|
|
|
30 |
("embedding_dim", "Embedding Dimension"),
|
31 |
]
|
32 |
+ [
|
@@ -95,11 +96,13 @@ def get_data_from_hub():
|
|
95 |
return pd.DataFrame(df_list, columns=EXPECTED_KEY_TO_COLNAME.values())
|
96 |
|
97 |
|
98 |
-
def
|
|
|
99 |
# Fixed column positions
|
100 |
selected_columns = [
|
101 |
EXPECTED_KEY_TO_COLNAME["rank"],
|
102 |
EXPECTED_KEY_TO_COLNAME["model"],
|
|
|
103 |
EXPECTED_KEY_TO_COLNAME["model_size"],
|
104 |
EXPECTED_KEY_TO_COLNAME["embedding_dim"],
|
105 |
]
|
@@ -124,12 +127,20 @@ def filter_columns(df, k_filter, d_filter):
|
|
124 |
selected_columns.append(EXPECTED_KEY_TO_COLNAME["n_dists"])
|
125 |
datatypes.append("number")
|
126 |
|
|
|
|
|
|
|
|
|
|
|
127 |
return df[selected_columns], datatypes
|
128 |
|
129 |
|
130 |
def add_rank(df):
|
131 |
main_metrics = df["R@1 +1M Dist."].str.split("±").str[0].astype(float)
|
132 |
-
|
|
|
|
|
|
|
133 |
return df
|
134 |
|
135 |
|
@@ -141,14 +152,16 @@ def save_current_leaderboard(df):
|
|
141 |
return filename
|
142 |
|
143 |
|
144 |
-
def load_lrvsf_models(k_filter, d_filter, csv_file):
|
145 |
# Remove previous tmpfile
|
146 |
if csv_file:
|
147 |
os.remove(csv_file)
|
148 |
|
149 |
df = get_data_from_hub()
|
150 |
df = add_rank(df)
|
151 |
-
df, datatypes =
|
|
|
|
|
152 |
filename = save_current_leaderboard(df)
|
153 |
|
154 |
outputs = [
|
@@ -163,7 +176,11 @@ if __name__ == "__main__":
|
|
163 |
with gr.Blocks() as demo:
|
164 |
gr.Markdown(
|
165 |
"""
|
166 |
-
# LAION - Referred Visual Search - Fashion
|
|
|
|
|
|
|
|
|
167 |
"""
|
168 |
)
|
169 |
with gr.Row():
|
@@ -175,6 +192,11 @@ if __name__ == "__main__":
|
|
175 |
value=DIST_EVALUATIONS,
|
176 |
label="Number of Distractors",
|
177 |
)
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
df_table = gr.Dataframe(type="pandas", interactive=False)
|
180 |
csv_file = gr.File(interactive=False)
|
@@ -183,12 +205,12 @@ if __name__ == "__main__":
|
|
183 |
# Actions
|
184 |
refresh.click(
|
185 |
load_lrvsf_models,
|
186 |
-
inputs=[k_filter, d_filter, csv_file],
|
187 |
outputs=[df_table, csv_file],
|
188 |
)
|
189 |
demo.load(
|
190 |
load_lrvsf_models,
|
191 |
-
inputs=[k_filter, d_filter, csv_file],
|
192 |
outputs=[df_table, csv_file],
|
193 |
)
|
194 |
|
|
|
27 |
("rank", "Rank"), # Just for columns order
|
28 |
("model", "Model"), # Just for columns order
|
29 |
("model_size", "Model Size (Million)"), # Just for columns order
|
30 |
+
("conditioning", "Conditioning"),
|
31 |
("embedding_dim", "Embedding Dimension"),
|
32 |
]
|
33 |
+ [
|
|
|
96 |
return pd.DataFrame(df_list, columns=EXPECTED_KEY_TO_COLNAME.values())
|
97 |
|
98 |
|
99 |
+
def filter_dataframe(df, k_filter, d_filter, c_filter):
|
100 |
+
# ===== FILTER COLUMNS
|
101 |
# Fixed column positions
|
102 |
selected_columns = [
|
103 |
EXPECTED_KEY_TO_COLNAME["rank"],
|
104 |
EXPECTED_KEY_TO_COLNAME["model"],
|
105 |
+
EXPECTED_KEY_TO_COLNAME["conditioning"],
|
106 |
EXPECTED_KEY_TO_COLNAME["model_size"],
|
107 |
EXPECTED_KEY_TO_COLNAME["embedding_dim"],
|
108 |
]
|
|
|
127 |
selected_columns.append(EXPECTED_KEY_TO_COLNAME["n_dists"])
|
128 |
datatypes.append("number")
|
129 |
|
130 |
+
df = df[selected_columns]
|
131 |
+
|
132 |
+
# ===== FILTER ROWS
|
133 |
+
df = df[df[EXPECTED_KEY_TO_COLNAME["conditioning"]].isin(c_filter)]
|
134 |
+
|
135 |
return df[selected_columns], datatypes
|
136 |
|
137 |
|
138 |
def add_rank(df):
|
139 |
main_metrics = df["R@1 +1M Dist."].str.split("±").str[0].astype(float)
|
140 |
+
|
141 |
+
# Argsort is smallest to largest so we reverse it
|
142 |
+
# We add 1 to start the rank at 1 instead of 0
|
143 |
+
df["Rank"] = main_metrics.argsort().values[::-1] + 1
|
144 |
return df
|
145 |
|
146 |
|
|
|
152 |
return filename
|
153 |
|
154 |
|
155 |
+
def load_lrvsf_models(k_filter, d_filter, c_filter, csv_file):
|
156 |
# Remove previous tmpfile
|
157 |
if csv_file:
|
158 |
os.remove(csv_file)
|
159 |
|
160 |
df = get_data_from_hub()
|
161 |
df = add_rank(df)
|
162 |
+
df, datatypes = filter_dataframe(df, k_filter, d_filter, c_filter)
|
163 |
+
df = df.sort_values(by="Rank")
|
164 |
+
|
165 |
filename = save_current_leaderboard(df)
|
166 |
|
167 |
outputs = [
|
|
|
176 |
with gr.Blocks() as demo:
|
177 |
gr.Markdown(
|
178 |
"""
|
179 |
+
# LAION - Referred Visual Search - Fashion 👗 Leaderboard
|
180 |
+
|
181 |
+
- To submit, refer to the [LAION-RVS-Fashion Benchmark repository](https://github.com/Simon-Lepage/LRVSF-Benchmark).
|
182 |
+
- For details on the task and the dataset, refer to the [LRVSF paper](https://arxiv.org/abs/2306.02928).
|
183 |
+
- To download the leaderboard as CSV, click on the file below the table.
|
184 |
"""
|
185 |
)
|
186 |
with gr.Row():
|
|
|
192 |
value=DIST_EVALUATIONS,
|
193 |
label="Number of Distractors",
|
194 |
)
|
195 |
+
c_filter = gr.CheckboxGroup(
|
196 |
+
choices=["category", "text"],
|
197 |
+
value=["category", "text"],
|
198 |
+
label="Conditioning",
|
199 |
+
)
|
200 |
|
201 |
df_table = gr.Dataframe(type="pandas", interactive=False)
|
202 |
csv_file = gr.File(interactive=False)
|
|
|
205 |
# Actions
|
206 |
refresh.click(
|
207 |
load_lrvsf_models,
|
208 |
+
inputs=[k_filter, d_filter, c_filter, csv_file],
|
209 |
outputs=[df_table, csv_file],
|
210 |
)
|
211 |
demo.load(
|
212 |
load_lrvsf_models,
|
213 |
+
inputs=[k_filter, d_filter, c_filter, csv_file],
|
214 |
outputs=[df_table, csv_file],
|
215 |
)
|
216 |
|