Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,7 @@ def load_leaderboard_table_csv(filename, add_hyperlink=True):
|
|
54 |
for j in range(len(heads)):
|
55 |
item = {}
|
56 |
for h, v in zip(heads, row):
|
57 |
-
if h != "Model" and h != "Link":
|
58 |
item[h] = int(v)
|
59 |
else:
|
60 |
item[h] = v
|
@@ -76,6 +76,12 @@ def get_arena_table(model_table_df):
|
|
76 |
# model display name
|
77 |
row.append(model_name)
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
row.append(
|
80 |
model_table_df["Text Recognition"].values[model_key]
|
81 |
)
|
@@ -102,10 +108,59 @@ def get_arena_table(model_table_df):
|
|
102 |
values.append(row)
|
103 |
return values
|
104 |
|
105 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
if leaderboard_table_file:
|
107 |
data = load_leaderboard_table_csv(leaderboard_table_file)
|
|
|
108 |
model_table_df = pd.DataFrame(data)
|
|
|
109 |
md_head = f"""
|
110 |
# π OCRBench Leaderboard
|
111 |
| [GitHub](https://github.com/Yuliang-Liu/MultimodalOCR) | [Paper](https://arxiv.org/abs/2305.07895) |
|
@@ -121,6 +176,8 @@ def build_leaderboard_tab(leaderboard_table_file, show_plot=False):
|
|
121 |
headers=[
|
122 |
"Rank",
|
123 |
"Name",
|
|
|
|
|
124 |
"Text Recognition",
|
125 |
"Scene Text-Centric VQA",
|
126 |
"Doc-Oriented VQA",
|
@@ -131,6 +188,45 @@ def build_leaderboard_tab(leaderboard_table_file, show_plot=False):
|
|
131 |
datatype=[
|
132 |
"str",
|
133 |
"markdown",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
"number",
|
135 |
"number",
|
136 |
"number",
|
@@ -141,9 +237,10 @@ def build_leaderboard_tab(leaderboard_table_file, show_plot=False):
|
|
141 |
value=arena_table_vals,
|
142 |
elem_id="arena_leaderboard_dataframe",
|
143 |
height=700,
|
144 |
-
column_widths=[60, 120,
|
145 |
wrap=True,
|
146 |
)
|
|
|
147 |
else:
|
148 |
pass
|
149 |
md_tail = f"""
|
@@ -151,7 +248,7 @@ def build_leaderboard_tab(leaderboard_table_file, show_plot=False):
|
|
151 |
If you would like to include your model in the OCRBench leaderboard, please follow the evaluation instructions provided on [GitHub](https://github.com/Yuliang-Liu/MultimodalOCR) and feel free to contact us via email at [email protected]. We will update the leaderboard in time."""
|
152 |
gr.Markdown(md_tail, elem_id="leaderboard_markdown")
|
153 |
|
154 |
-
def build_demo(leaderboard_table_file):
|
155 |
text_size = gr.themes.sizes.text_lg
|
156 |
|
157 |
with gr.Blocks(
|
@@ -160,7 +257,7 @@ def build_demo(leaderboard_table_file):
|
|
160 |
css=block_css,
|
161 |
) as demo:
|
162 |
leader_components = build_leaderboard_tab(
|
163 |
-
leaderboard_table_file, show_plot=True
|
164 |
)
|
165 |
return demo
|
166 |
|
@@ -168,7 +265,8 @@ if __name__ == "__main__":
|
|
168 |
parser = argparse.ArgumentParser()
|
169 |
parser.add_argument("--share", action="store_true")
|
170 |
parser.add_argument("--OCRBench_file", type=str, default="./OCRBench.csv")
|
|
|
171 |
args = parser.parse_args()
|
172 |
|
173 |
-
demo = build_demo(args.OCRBench_file)
|
174 |
demo.launch()
|
|
|
54 |
for j in range(len(heads)):
|
55 |
item = {}
|
56 |
for h, v in zip(heads, row):
|
57 |
+
if h != "Model" and h != "Link" and h != "Language Model" and h != "Open Source":
|
58 |
item[h] = int(v)
|
59 |
else:
|
60 |
item[h] = v
|
|
|
76 |
# model display name
|
77 |
row.append(model_name)
|
78 |
|
79 |
+
row.append(
|
80 |
+
model_table_df["Language Model"].values[model_key]
|
81 |
+
)
|
82 |
+
row.append(
|
83 |
+
model_table_df["Open Source"].values[model_key]
|
84 |
+
)
|
85 |
row.append(
|
86 |
model_table_df["Text Recognition"].values[model_key]
|
87 |
)
|
|
|
108 |
values.append(row)
|
109 |
return values
|
110 |
|
111 |
+
def get_recog_table(model_table_df):
|
112 |
+
# sort by rating
|
113 |
+
values = []
|
114 |
+
for i in range(len(model_table_df)):
|
115 |
+
row = []
|
116 |
+
model_key = model_table_df.index[i]
|
117 |
+
model_name = model_table_df["Model"].values[model_key]
|
118 |
+
# rank
|
119 |
+
row.append(i + 1)
|
120 |
+
# model display name
|
121 |
+
row.append(model_name)
|
122 |
+
|
123 |
+
row.append(
|
124 |
+
model_table_df["Language Model"].values[model_key]
|
125 |
+
)
|
126 |
+
row.append(
|
127 |
+
model_table_df["Open Source"].values[model_key]
|
128 |
+
)
|
129 |
+
row.append(
|
130 |
+
model_table_df["Regular Text"].values[model_key]
|
131 |
+
)
|
132 |
+
|
133 |
+
row.append(
|
134 |
+
model_table_df["Irregular Text"].values[model_key]
|
135 |
+
)
|
136 |
+
|
137 |
+
row.append(
|
138 |
+
model_table_df["Artistic Text"].values[model_key]
|
139 |
+
)
|
140 |
+
|
141 |
+
row.append(
|
142 |
+
model_table_df["Handwriting"].values[model_key]
|
143 |
+
)
|
144 |
+
|
145 |
+
row.append(
|
146 |
+
model_table_df["Digit string"].values[model_key]
|
147 |
+
)
|
148 |
+
|
149 |
+
row.append(
|
150 |
+
model_table_df["Non-semantic Text"].values[model_key]
|
151 |
+
)
|
152 |
+
row.append(
|
153 |
+
model_table_df["ALL"].values[model_key]
|
154 |
+
)
|
155 |
+
values.append(row)
|
156 |
+
return values
|
157 |
+
|
158 |
+
def build_leaderboard_tab(leaderboard_table_file, text_recog_file, show_plot=False):
|
159 |
if leaderboard_table_file:
|
160 |
data = load_leaderboard_table_csv(leaderboard_table_file)
|
161 |
+
data_recog = load_leaderboard_table_csv(text_recog_file)
|
162 |
model_table_df = pd.DataFrame(data)
|
163 |
+
recog_table_df = pd.DataFrame(data_recog)
|
164 |
md_head = f"""
|
165 |
# π OCRBench Leaderboard
|
166 |
| [GitHub](https://github.com/Yuliang-Liu/MultimodalOCR) | [Paper](https://arxiv.org/abs/2305.07895) |
|
|
|
176 |
headers=[
|
177 |
"Rank",
|
178 |
"Name",
|
179 |
+
"Language Model",
|
180 |
+
"Open Source",
|
181 |
"Text Recognition",
|
182 |
"Scene Text-Centric VQA",
|
183 |
"Doc-Oriented VQA",
|
|
|
188 |
datatype=[
|
189 |
"str",
|
190 |
"markdown",
|
191 |
+
"str",
|
192 |
+
"str",
|
193 |
+
"number",
|
194 |
+
"number",
|
195 |
+
"number",
|
196 |
+
"number",
|
197 |
+
"number",
|
198 |
+
"number",
|
199 |
+
],
|
200 |
+
value=arena_table_vals,
|
201 |
+
elem_id="arena_leaderboard_dataframe",
|
202 |
+
height=700,
|
203 |
+
column_widths=[60, 120,150,100, 150, 200, 180, 80, 80, 160],
|
204 |
+
wrap=True,
|
205 |
+
)
|
206 |
+
with gr.Tab("Text Recognition", id=1):
|
207 |
+
arena_table_vals = get_recog_table(recog_table_df)
|
208 |
+
md = "OCRBench is a comprehensive evaluation benchmark designed to assess the OCR capabilities of Large Multimodal Models. It comprises five components: Text Recognition, SceneText-Centric VQA, Document-Oriented VQA, Key Information Extraction, and Handwritten Mathematical Expression Recognition. The benchmark includes 1000 question-answer pairs, and all the answers undergo manual verification and correction to ensure a more precise evaluation."
|
209 |
+
gr.Markdown(md, elem_id="leaderboard_markdown")
|
210 |
+
gr.Dataframe(
|
211 |
+
headers=[
|
212 |
+
"Rank",
|
213 |
+
"Name",
|
214 |
+
"Language Model",
|
215 |
+
"Open Source",
|
216 |
+
"Regular Text",
|
217 |
+
"Irregular Text",
|
218 |
+
"Artistic Text",
|
219 |
+
"Handwriting",
|
220 |
+
"Digit string",
|
221 |
+
"Non-semantic Text",
|
222 |
+
"ALL",
|
223 |
+
],
|
224 |
+
datatype=[
|
225 |
+
"str",
|
226 |
+
"markdown",
|
227 |
+
"str",
|
228 |
+
"str",
|
229 |
+
"number",
|
230 |
"number",
|
231 |
"number",
|
232 |
"number",
|
|
|
237 |
value=arena_table_vals,
|
238 |
elem_id="arena_leaderboard_dataframe",
|
239 |
height=700,
|
240 |
+
column_widths=[60, 120,150,100, 100, 100, 100, 100, 100,100, 80],
|
241 |
wrap=True,
|
242 |
)
|
243 |
+
|
244 |
else:
|
245 |
pass
|
246 |
md_tail = f"""
|
|
|
248 |
If you would like to include your model in the OCRBench leaderboard, please follow the evaluation instructions provided on [GitHub](https://github.com/Yuliang-Liu/MultimodalOCR) and feel free to contact us via email at [email protected]. We will update the leaderboard in time."""
|
249 |
gr.Markdown(md_tail, elem_id="leaderboard_markdown")
|
250 |
|
251 |
+
def build_demo(leaderboard_table_file, recog_table_file):
|
252 |
text_size = gr.themes.sizes.text_lg
|
253 |
|
254 |
with gr.Blocks(
|
|
|
257 |
css=block_css,
|
258 |
) as demo:
|
259 |
leader_components = build_leaderboard_tab(
|
260 |
+
leaderboard_table_file, recog_table_file,show_plot=True
|
261 |
)
|
262 |
return demo
|
263 |
|
|
|
265 |
parser = argparse.ArgumentParser()
|
266 |
parser.add_argument("--share", action="store_true")
|
267 |
parser.add_argument("--OCRBench_file", type=str, default="./OCRBench.csv")
|
268 |
+
parser.add_argument("--TextRecognition_file", type=str, default="./TextRecognition.csv")
|
269 |
args = parser.parse_args()
|
270 |
|
271 |
+
demo = build_demo(args.OCRBench_file, args.TextRecognition_file)
|
272 |
demo.launch()
|