Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import pandas as pd
|
4 |
+
from huggingface_hub.repocard import metadata_load
|
5 |
+
from huggingface_hub import hf_hub_download, HfApi
|
6 |
+
import os
|
7 |
+
import json
|
8 |
+
|
9 |
+
|
10 |
+
def make_clickable_model(model_name, link=None):
|
11 |
+
if link is None:
|
12 |
+
link = "https://huggingface.co/" + model_name
|
13 |
+
# Remove user from model name
|
14 |
+
# return (
|
15 |
+
# f'<a target="_blank" style="text-decoration: underline" href="{link}">{model_name.split("/")[-1]}</a>'
|
16 |
+
# )
|
17 |
+
return (
|
18 |
+
f'<a target="_blank" style="text-decoration: underline" href="{link}">{model_name}</a>'
|
19 |
+
)
|
20 |
+
|
21 |
+
|
22 |
+
def add_rank(df):
|
23 |
+
cols_to_rank = [col for col in df.columns if
|
24 |
+
col not in ["Model", "Model Size (Million Parameters)", "Memory Usage (GB, fp32)",
|
25 |
+
"Embedding Dimensions", "Max Tokens"]]
|
26 |
+
if len(cols_to_rank) == 1:
|
27 |
+
df.sort_values(cols_to_rank[0], ascending=False, inplace=True)
|
28 |
+
else:
|
29 |
+
df.insert(len(df.columns) - len(cols_to_rank), "Average", df[cols_to_rank].mean(axis=1, skipna=False))
|
30 |
+
df.sort_values("Average", ascending=False, inplace=True)
|
31 |
+
df.insert(0, "Rank", list(range(1, len(df) + 1)))
|
32 |
+
df = df.round(2)
|
33 |
+
# Fill NaN after averaging
|
34 |
+
df.fillna("", inplace=True)
|
35 |
+
return df
|
36 |
+
|
37 |
+
|
38 |
+
def get_vidore_data():
|
39 |
+
api = HfApi()
|
40 |
+
|
41 |
+
# local cache path
|
42 |
+
model_infos_path = "model_infos.json"
|
43 |
+
MODEL_INFOS = {}
|
44 |
+
if os.path.exists(model_infos_path):
|
45 |
+
with open(model_infos_path) as f:
|
46 |
+
MODEL_INFOS = json.load(f)
|
47 |
+
|
48 |
+
models = api.list_models(filter="vidore")
|
49 |
+
|
50 |
+
for model in models:
|
51 |
+
if model.modelId not in MODEL_INFOS:
|
52 |
+
readme_path = hf_hub_download(model.modelId, filename="README.md")
|
53 |
+
meta = metadata_load(readme_path)
|
54 |
+
try:
|
55 |
+
result_path = hf_hub_download(model.modelId, filename="results.json")
|
56 |
+
|
57 |
+
with open(result_path) as f:
|
58 |
+
results = json.load(f)
|
59 |
+
# keep only ndcg_at_5
|
60 |
+
for dataset in results:
|
61 |
+
results[dataset] = {key: value for key, value in results[dataset].items() if "ndcg_at_5" in key}
|
62 |
+
|
63 |
+
MODEL_INFOS[model.modelId] = {
|
64 |
+
"metadata": meta,
|
65 |
+
"results": results
|
66 |
+
}
|
67 |
+
except:
|
68 |
+
continue
|
69 |
+
|
70 |
+
model_res = {}
|
71 |
+
df = None
|
72 |
+
if len(MODEL_INFOS) > 0:
|
73 |
+
for model in MODEL_INFOS.keys():
|
74 |
+
res = MODEL_INFOS[model]["results"]
|
75 |
+
dataset_res = {}
|
76 |
+
for dataset in res.keys():
|
77 |
+
if "validation_set" == dataset:
|
78 |
+
continue
|
79 |
+
dataset_res[dataset] = res[dataset]["ndcg_at_5"]
|
80 |
+
model_res[model] = dataset_res
|
81 |
+
|
82 |
+
df = pd.DataFrame(model_res).T
|
83 |
+
|
84 |
+
# add average
|
85 |
+
# df["average"] = df.mean(axis=1)
|
86 |
+
# df = df.sort_values(by="average", ascending=False)
|
87 |
+
# # round to 2 decimals
|
88 |
+
# df = df.round(2)
|
89 |
+
return df
|
90 |
+
|
91 |
+
|
92 |
+
def add_rank_and_format(df):
|
93 |
+
df = df.reset_index()
|
94 |
+
df = df.rename(columns={"index": "Model"})
|
95 |
+
df = add_rank(df)
|
96 |
+
df["Model"] = df["Model"].apply(make_clickable_model)
|
97 |
+
return df
|
98 |
+
|
99 |
+
# 1. Force headers to wrap
|
100 |
+
# 2. Force model column (maximum) width
|
101 |
+
# 3. Prevent model column from overflowing, scroll instead
|
102 |
+
# 4. Prevent checkbox groups from taking up too much space
|
103 |
+
|
104 |
+
css = """
|
105 |
+
table > thead {
|
106 |
+
white-space: normal
|
107 |
+
}
|
108 |
+
|
109 |
+
table {
|
110 |
+
--cell-width-1: 250px
|
111 |
+
}
|
112 |
+
|
113 |
+
table > tbody > tr > td:nth-child(2) > div {
|
114 |
+
overflow-x: auto
|
115 |
+
}
|
116 |
+
|
117 |
+
.filter-checkbox-group {
|
118 |
+
max-width: max-content;
|
119 |
+
}
|
120 |
+
|
121 |
+
"""
|
122 |
+
|
123 |
+
|
124 |
+
def get_refresh_function():
|
125 |
+
def _refresh():
|
126 |
+
data_task_category = get_vidore_data()
|
127 |
+
return data_task_category
|
128 |
+
|
129 |
+
return _refresh
|
130 |
+
|
131 |
+
|
132 |
+
def get_refresh_overall_function():
|
133 |
+
return lambda: get_refresh_function()
|
134 |
+
|
135 |
+
|
136 |
+
data = get_vidore_data()
|
137 |
+
data = add_rank_and_format(data)
|
138 |
+
|
139 |
+
NUM_DATASETS = len(data.columns) - 3
|
140 |
+
NUM_SCORES = len(data) * NUM_DATASETS
|
141 |
+
NUM_MODELS = len(data)
|
142 |
+
|
143 |
+
with gr.Blocks(css=css) as block:
|
144 |
+
gr.Markdown("# ViDoRe: The Visual Document Retrieval Benchmark ππ")
|
145 |
+
gr.Markdown("## From the paper - ColPali: Efficient Document Retrieval with Vision Language Models π")
|
146 |
+
|
147 |
+
|
148 |
+
gr.Markdown(f"""
|
149 |
+
Visual Document Retrieval Benchmark leaderboard. To submit, refer to the <a href="https://github.com/tonywu71/vidore-benchmark/" target="_blank" style="text-decoration: underline">ViDoRe GitHub repository</a>. Refer to the [ColPali paper](https://arxiv.org/abs/XXXX.XXXXX) for details on metrics, tasks and models.
|
150 |
+
""")
|
151 |
+
|
152 |
+
with gr.Row():
|
153 |
+
datatype = ["number", "markdown"] + ["number"] * (NUM_DATASETS + 1)
|
154 |
+
dataframe = gr.Dataframe(data, datatype=datatype, type="pandas", height=500)
|
155 |
+
|
156 |
+
with gr.Row():
|
157 |
+
refresh_button = gr.Button("Refresh")
|
158 |
+
refresh_button.click(get_refresh_function(), inputs=None, outputs=dataframe,
|
159 |
+
concurrency_limit=20)
|
160 |
+
|
161 |
+
gr.Markdown(f"""
|
162 |
+
- **Total Datasets**: {NUM_DATASETS}
|
163 |
+
- **Total Scores**: {NUM_SCORES}
|
164 |
+
- **Total Models**: {NUM_MODELS}
|
165 |
+
""" + r"""
|
166 |
+
Please consider citing:
|
167 |
+
|
168 |
+
```bibtex
|
169 |
+
@article{}
|
170 |
+
```
|
171 |
+
""")
|
172 |
+
|
173 |
+
|
174 |
+
if __name__ == "__main__":
|
175 |
+
block.queue(max_size=10).launch(debug=True)
|
176 |
+
|