jaothan commited on
Commit
3632f4b
·
verified ·
1 Parent(s): 92ba7fd

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -265
app.py DELETED
@@ -1,265 +0,0 @@
1
- import gradio as gr
2
- import numpy as np
3
- import pandas as pd
4
- import argparse
5
-
6
- def make_default_md():
7
- leaderboard_md = f"""
8
- # 🏆 LLms Benchmark
9
-
10
- The main goal of this project is to utilize Large Language Models (LLMs) to extract specific information from PDF documents and organize it into a structured JSON format.
11
-
12
- To achieve this objective, we are assessing various LLMs on two benchmarks:
13
-
14
- 1. [Benchmark1](https://huggingface.co/spaces/Nechba/LLms-Benchmark/blob/main/dataset.jsonl):
15
- This benchmark consists of a dataset of 59 pages as context and corresponding JSON extracts from "Interchange and Service Fees Manual: Europe Region".
16
-
17
- 2. [Benchmark2](https://huggingface.co/datasets/Effyis/Table-Extraction):
18
- This benchmark comprises a dataset of 16573 tables as context and corresponding JSON extracts.
19
- """
20
- return leaderboard_md
21
-
22
-
23
- def make_arena_leaderboard_md(total_models):
24
- leaderboard_md = f"""
25
- Total #models: **{total_models}**. Last updated: Juin 01, 2024.
26
-
27
- """
28
- return leaderboard_md
29
-
30
- def model_hyperlink(model_name, link):
31
- return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
32
-
33
- def load_leaderboard_table_csv(filename, add_hyperlink=True):
34
- rows = []
35
- with open(filename, 'r') as file:
36
- lines = file.readlines()
37
- heads = [v.strip() for v in lines[0].split(",")]
38
- for line in lines[1:]:
39
- row = [v.strip() for v in line.split(",")]
40
- item = {}
41
- for h, v in zip(heads, row):
42
- item[h] = v
43
- if add_hyperlink:
44
- item["Model"] = model_hyperlink(item["Model"], item["Link"])
45
- item["Notebook link"] = model_hyperlink("Notebook", item["Notebook link"])
46
- rows.append(item)
47
- return rows
48
-
49
- def get_arena_table(model_table_df):
50
- # change type Percentage of values column of df
51
- model_table_df["Percentage of values"] = model_table_df["Percentage of values"].astype(float)
52
- model_table_df["Percentage of keys"] = model_table_df["Percentage of keys"].astype(float)
53
- model_table_df["Average time (s)"] = model_table_df["Average time (s)"].astype(float)
54
- arena_df = model_table_df.sort_values(by=["Percentage of values"], ascending=False)
55
- values = []
56
- if not arena_df.empty: # Check if arena_df is not empty
57
- for i in range(len(arena_df)):
58
- row = []
59
- model_name = arena_df["Model"].values[i] # Access model name directly without index 0
60
- row.append(model_name)
61
- row.append(arena_df.iloc[i]["Percentage of values"])
62
- row.append(arena_df.iloc[i]["Percentage of keys"])
63
- row.append(arena_df.iloc[i]["Average time (s)"])
64
- row.append(arena_df.iloc[i]["Notebook link"])
65
- row.append(arena_df.iloc[i]["License"])
66
- # row.append(arena_df.iloc[i]["Link"])
67
- values.append(row)
68
- return values
69
-
70
-
71
-
72
- def build_leaderboard_tab(leaderboard_table_file1, leaderboard_table_file2, show_plot=False):
73
- default_md = make_default_md()
74
- md_1 = gr.Markdown(default_md, elem_id="leaderboard_markdown")
75
-
76
- if leaderboard_table_file1:
77
- data1 = load_leaderboard_table_csv(leaderboard_table_file1)
78
- model_table_df1 = pd.DataFrame(data1)
79
- data2 = load_leaderboard_table_csv(leaderboard_table_file2)
80
- model_table_df2 = pd.DataFrame(data2)
81
-
82
- with gr.Tabs() as tabs:
83
- with gr.Tab(" 🏅 Benchmark 1", id=0):
84
- arena_table_vals = get_arena_table(model_table_df1)
85
- md = make_arena_leaderboard_md(len(arena_table_vals))
86
- gr.Markdown(md, elem_id="leaderboard_markdown")
87
-
88
- # Remove height argument
89
- gr.Dataframe(
90
- headers=[
91
- "Model",
92
- "Percentage of values (%)",
93
- "Percentage of keys (%)",
94
- "Average time (s)",
95
- "Code",
96
- "License",
97
- ],
98
- datatype=[
99
- "markdown",
100
- "number",
101
- "number",
102
- "number",
103
- "markdown",
104
- "str"
105
- ],
106
- value=arena_table_vals,
107
- elem_id="arena_leaderboard_dataframe",
108
- column_widths=[200, 150, 150, 130, 100, 140],
109
- wrap=True,
110
- )
111
-
112
- # Displaying a note about the leaderboard analysis
113
- gr.Markdown(
114
- f"""Note: Upon reviewing the leaderboard, it's evident that two models, Gemini and OpenHermes, outperform the others. Our next step involves a detailed analysis and comparison of the results obtained by these two models.""",
115
- elem_id="leaderboard_markdown"
116
- )
117
-
118
- # Displaying additional statistics for Gemini and OpenHermes
119
- gr.Markdown(
120
- f"""## More Statistics for Gemini and OpenHermes\n
121
- Now we will focus on Gemini and OpenHermes, diving deeper into their performance for a comprehensive comparison.""",
122
- elem_id=0
123
- )
124
-
125
- # Displaying the confusion matrices for Gemini and OpenHermes
126
- with gr.Row():
127
- with gr.Column():
128
- gr.Markdown(
129
- "#### Figure 1: Gemini Confusion Matrix"
130
- )
131
- plot_1 = gr.Image("./Benchmark1/gemini_cm.png", show_label=False)
132
- # Detailed analysis of Gemini's performance
133
- gr.Markdown(
134
- """### True Positives:
135
- Our model correctly identified all 18 pages lacking the desired information (Payment product, FeeTier, and Rate).
136
-
137
- ### True Negatives:
138
- The model successfully predicted desired information on 39 out of 41 pages with an accuracy ranging from 12% to 100%. (For more details about accuracy, check the Notebook [here](https://huggingface.co/spaces/Effyis/LLms-Benchmark/blob/main/Benchmark1/gemini.ipynb))
139
-
140
- ### False Negatives:
141
- In 2 instances, the model incorrectly predicted that pages lacked the desired information when they actually contained it.
142
-
143
- ### False Positives:
144
- The model incorrectly predicted that 0 pages contained the desired information when they were actually missing it."""
145
- )
146
-
147
- with gr.Column():
148
- gr.Markdown(
149
- "#### Figure 2: OpenHermes Confusion Matrix"
150
- )
151
- plot_2 = gr.Image("./Benchmark1/openhermes_cm.png", show_label=False)
152
- # Detailed analysis of OpenHermes's performance
153
- gr.Markdown(
154
- """### True Positives:
155
- Our model correctly identified 12 out of 18 pages lacking the desired information (Payment product, FeeTier, and Rate).
156
-
157
- ### True Negatives:
158
- The model successfully predicted desired information on 21 out of 41 pages with an accuracy ranging from 5% to 66%. (For more details about accuracy, check the Notebook [here](https://huggingface.co/spaces/Effyis/LLms-Benchmark/blob/main/Benchmark1/openhermes.ipynb))
159
-
160
- ### False Negatives:
161
- In 20 instances, the model incorrectly predicted that pages lacked the desired information when they actually contained it.
162
-
163
- ### False Positives:
164
- The model incorrectly predicted that 6 pages contained the desired information when they were actually missing it."""
165
- )
166
-
167
- # Conclusion based on the analysis
168
- gr.Markdown(
169
- """## Conclusion\n
170
- Upon analyzing the performance of Gemini and OpenHermes, it becomes evident that both models exhibit strengths and weaknesses. Gemini demonstrates higher accuracy in identifying pages lacking desired information and also performs better in predicting pages containing the desired information. On the other hand, while OpenHermes shows good results in identifying pages lacking desired information, it achieves only 50% accuracy in predicting pages containing the desired information. Further fine-tuning of both models could lead to enhanced overall performance."""
171
- )
172
-
173
-
174
- with gr.Tab("🏅 Benchmark 2", id=1):
175
- arena_table_vals = get_arena_table(model_table_df2)
176
- md = make_arena_leaderboard_md(len(arena_table_vals))
177
- gr.Markdown(md, elem_id="leaderboard_markdown")
178
- gr.Dataframe(
179
- headers=[
180
- "Model",
181
- "Percentage of values (%)",
182
- "Percentage of keys (%)",
183
- "Average time (s)",
184
- "Code",
185
- "License",
186
- ],
187
- datatype=[
188
- "markdown",
189
- "number",
190
- "number",
191
- "number",
192
- "markdown",
193
- "str"
194
- ],
195
- value=arena_table_vals,
196
- elem_id="arena_leaderboard_dataframe",
197
- height=700,
198
- column_widths=[200, 150, 150, 130, 100, 140],
199
- wrap=True,
200
- )
201
- # gr.Markdown(
202
- # f"""
203
- # Note: For this benchmark, only a sample of 100 points from the dataset is utilized. It's evident that the data context is straightforward, yet it includes Arabic names. This could explain the lower performance scores of the models, as they may lack robust capabilities in handling Arabic names.""",
204
- # elem_id="leaderboard_markdown"
205
- # )
206
-
207
- else:
208
- pass
209
- return [md_1,plot_1, plot_2]
210
-
211
- block_css = """
212
- #notice_markdown {
213
- font-size: 104%
214
- }
215
- #notice_markdown th {
216
- display: none;
217
- }
218
- #notice_markdown td {
219
- padding-top: 6px;
220
- padding-bottom: 6px;
221
- }
222
- #leaderboard_markdown {
223
- font-size: 104%
224
- }
225
- #leaderboard_markdown td {
226
- padding-top: 6px;
227
- padding-bottom: 6px;
228
- }
229
- #leaderboard_dataframe td {
230
- line-height: 0.1em;
231
- }
232
- footer {
233
- display:none !important
234
- }
235
- .sponsor-image-about img {
236
- margin: 0 20px;
237
- margin-top: 20px;
238
- height: 40px;
239
- max-height: 100%;
240
- width: auto;
241
- float: left;
242
- }
243
- """
244
-
245
- def build_demo(leaderboard_table_file1, leaderboard_table_file2):
246
- text_size = gr.themes.sizes.text_lg
247
- with gr.Blocks(
248
- title="LLMS Benchmark",
249
- theme=gr.themes.Base(text_size=text_size),
250
- css=block_css,
251
- ) as demo:
252
- leader_components = build_leaderboard_tab(
253
- leaderboard_table_file1,leaderboard_table_file2, show_plot=True
254
- )
255
- return demo
256
-
257
- if __name__ == "__main__":
258
- parser = argparse.ArgumentParser()
259
- parser.add_argument("--share", action="store_true")
260
- args = parser.parse_args()
261
-
262
- leaderboard_table_file1 = "./Benchmark1/leaderboard.csv"
263
- leaderboard_table_file2 = "./Benchmark2/leaderboard.csv"
264
- demo = build_demo(leaderboard_table_file1,leaderboard_table_file2)
265
- demo.launch(share=args.share)