rodrigomasini commited on
Commit
f9dbb9d
·
verified ·
1 Parent(s): dea2f59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -208
app.py CHANGED
@@ -141,217 +141,94 @@ def filter_models(
141
  return filtered_df
142
 
143
 
144
- demo = gr.Blocks(css=custom_css)
145
- with demo:
146
- gr.HTML(TITLE)
147
- gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
148
-
149
- with gr.Tabs(elem_classes="tab-buttons") as tabs:
150
- with gr.TabItem("🏅 LLM Benchmark", elem_id="llm-benchmark-tab-table", id=0):
151
- with gr.Row():
152
- with gr.Column():
153
- with gr.Row():
154
- search_bar = gr.Textbox(
155
- placeholder=" 🔍 Search for your model (separate multiple queries with `;`) and press ENTER...",
156
- show_label=False,
157
- elem_id="search-bar",
158
- )
159
- with gr.Row():
160
- shown_columns = gr.CheckboxGroup(
161
- choices=[
162
- c.name
163
- for c in fields(AutoEvalColumn)
164
- if not c.hidden and not c.never_hidden and not c.dummy
165
- ],
166
- value=[
167
- c.name
168
- for c in fields(AutoEvalColumn)
169
- if c.displayed_by_default and not c.hidden and not c.never_hidden
170
- ],
171
- label="Select columns to show",
172
- elem_id="column-select",
173
- interactive=True,
174
- )
175
- with gr.Row():
176
- deleted_models_visibility = gr.Checkbox(
177
- value=False, label="Show gated/private/deleted models", interactive=True
178
- )
179
- with gr.Column(min_width=250):
180
- # with gr.Box(elem_id="box-filter"):
181
- filter_columns_type = gr.CheckboxGroup(
182
- label="Model types",
183
- choices=[t.to_str() for t in ModelType],
184
- value=[t.to_str() for t in ModelType],
185
- interactive=True,
186
- elem_id="filter-columns-type",
187
- )
188
- filter_columns_precision = gr.CheckboxGroup(
189
- label="Precision",
190
- choices=[i.value.name for i in Precision],
191
- value=[i.value.name for i in Precision],
192
- interactive=True,
193
- elem_id="filter-columns-precision",
194
- )
195
- filter_columns_size = gr.CheckboxGroup(
196
- label="Model sizes (in billions of parameters)",
197
- choices=list(NUMERIC_INTERVALS.keys()),
198
- value=list(NUMERIC_INTERVALS.keys()),
199
- interactive=True,
200
- elem_id="filter-columns-size",
201
- )
202
-
203
- leaderboard_table = gr.components.Dataframe(
204
- value=leaderboard_df[
205
- [c.name for c in fields(AutoEvalColumn) if c.never_hidden]
206
- + shown_columns.value
207
- + [AutoEvalColumn.dummy.name]
208
- ],
209
- headers=[c.name for c in fields(AutoEvalColumn) if c.never_hidden] + shown_columns.value,
210
- datatype=TYPES,
211
- elem_id="leaderboard-table",
212
- interactive=False,
213
- visible=True,
214
- column_widths=["2%", "20%", "10%", "10%", "12%"]
215
- )
216
 
217
- # Dummy leaderboard for handling the case when the user uses backspace key
218
- hidden_leaderboard_table_for_search = gr.components.Dataframe(
219
- value=original_df[COLS],
220
- headers=COLS,
221
- datatype=TYPES,
222
- visible=False,
223
- )
224
- search_bar.submit(
225
- update_table,
226
- [
227
- hidden_leaderboard_table_for_search,
228
- shown_columns,
229
- filter_columns_type,
230
- filter_columns_precision,
231
- filter_columns_size,
232
- deleted_models_visibility,
233
- search_bar,
234
- ],
235
- leaderboard_table,
236
- )
237
- for selector in [shown_columns, filter_columns_type, filter_columns_precision, filter_columns_size,
238
- deleted_models_visibility]:
239
- selector.change(
240
- update_table,
241
- [
242
- hidden_leaderboard_table_for_search,
243
- shown_columns,
244
- filter_columns_type,
245
- filter_columns_precision,
246
- filter_columns_size,
247
- deleted_models_visibility,
248
- search_bar,
249
- ],
250
- leaderboard_table,
251
- queue=True,
252
- )
253
-
254
- with gr.TabItem("📝 About", elem_id="llm-benchmark-tab-table", id=2):
255
- gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
256
-
257
- with gr.TabItem("🚀 Submit here! ", elem_id="llm-benchmark-tab-table", id=3):
258
- with gr.Column():
259
- with gr.Row():
260
- gr.Markdown(EVALUATION_QUEUE_TEXT, elem_classes="markdown-text")
261
-
262
- with gr.Column():
263
- with gr.Accordion(
264
- f"✅ Finished Evaluations ({len(finished_eval_queue_df)})",
265
- open=False,
266
- ):
267
- with gr.Row():
268
- finished_eval_table = gr.components.Dataframe(
269
- value=finished_eval_queue_df,
270
- headers=EVAL_COLS,
271
- datatype=EVAL_TYPES,
272
- row_count=5,
273
- )
274
- with gr.Accordion(
275
- f"🔄 Running Evaluation Queue ({len(running_eval_queue_df)})",
276
- open=False,
277
- ):
278
- with gr.Row():
279
- running_eval_table = gr.components.Dataframe(
280
- value=running_eval_queue_df,
281
- headers=EVAL_COLS,
282
- datatype=EVAL_TYPES,
283
- row_count=5,
284
- )
285
-
286
- with gr.Accordion(
287
- f"⏳ Pending Evaluation Queue ({len(pending_eval_queue_df)})",
288
- open=False,
289
- ):
290
- with gr.Row():
291
- pending_eval_table = gr.components.Dataframe(
292
- value=pending_eval_queue_df,
293
- headers=EVAL_COLS,
294
- datatype=EVAL_TYPES,
295
- row_count=5,
296
- )
297
- with gr.Row():
298
- gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
299
-
300
- with gr.Row():
301
- with gr.Column():
302
- model_name_textbox = gr.Textbox(label="Model name")
303
- revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
304
- model_type = gr.Dropdown(
305
- choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
306
- label="Model type",
307
- multiselect=False,
308
- value=None,
309
- interactive=True,
310
- )
311
-
312
- with gr.Column():
313
- precision = gr.Dropdown(
314
- choices=[i.value.name for i in Precision if i != Precision.Unknown],
315
- label="Precision",
316
- multiselect=False,
317
- value="float16",
318
- interactive=True,
319
- )
320
- weight_type = gr.Dropdown(
321
- choices=[i.value.name for i in WeightType],
322
- label="Weights type",
323
- multiselect=False,
324
- value="Original",
325
- interactive=True,
326
- )
327
- base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
328
-
329
- submit_button = gr.Button("Submit Eval")
330
- submission_result = gr.Markdown()
331
- submit_button.click(
332
- add_new_eval,
333
- [
334
- model_name_textbox,
335
- base_model_name_textbox,
336
- revision_name_textbox,
337
- precision,
338
- weight_type,
339
- model_type,
340
- ],
341
- submission_result,
342
- )
343
 
344
- with gr.Row():
345
- with gr.Accordion("📙 Citation", open=False):
346
- citation_button = gr.Textbox(
347
- value=CITATION_BUTTON_TEXT,
348
- label=CITATION_BUTTON_LABEL,
349
- lines=20,
350
- elem_id="citation-button",
351
- show_copy_button=True,
352
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
 
354
  scheduler = BackgroundScheduler()
355
  scheduler.add_job(restart_space, "interval", seconds=1800)
356
  scheduler.start()
357
- demo.queue(default_concurrency_limit=40).launch()
 
 
141
  return filtered_df
142
 
143
 
144
+ leaderboard_df = filter_models(
145
+ df=leaderboard_df,
146
+ type_query=[t.to_str(" : ") for t in ModelType],
147
+ size_query=list(NUMERIC_INTERVALS.keys()),
148
+ precision_query=[i.value.name for i in Precision],
149
+ show_deleted=False,
150
+ show_merges=False,
151
+ show_moe=True,
152
+ show_flagged=False
153
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
+ import unicodedata
156
+
157
+ def is_valid_unicode(char):
158
+ try:
159
+ unicodedata.name(char)
160
+ return True # Valid Unicode character
161
+ except ValueError:
162
+ return False # Invalid Unicode character
163
+
164
+ def remove_invalid_unicode(input_string):
165
+ if isinstance(input_string, str):
166
+ valid_chars = [char for char in input_string if is_valid_unicode(char)]
167
+ return ''.join(valid_chars)
168
+ else:
169
+ return input_string # Return non-string values as is
170
+
171
+ dummy1 = gr.Textbox(visible=False)
172
+
173
+ hidden_leaderboard_table_for_search = gr.components.Dataframe(
174
+ headers=COLS,
175
+ datatype=TYPES,
176
+ visible=False,
177
+ line_breaks=False,
178
+ interactive=False
179
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
+ def display(x, y):
182
+ # Assuming df is your DataFrame
183
+ for column in leaderboard_df.columns:
184
+ if leaderboard_df[column].dtype == 'object':
185
+ leaderboard_df[column] = leaderboard_df[column].apply(remove_invalid_unicode)
186
+
187
+ subset_df = leaderboard_df[COLS]
188
+ # Ensure the output directory exists
189
+ #output_dir = 'output'
190
+ #if not os.path.exists(output_dir):
191
+ # os.makedirs(output_dir)
192
+ #
193
+ ## Save JSON to a file in the output directory
194
+ #output_file_path = os.path.join(output_dir, 'output.json')
195
+ #with open(output_file_path, 'w') as file:
196
+ # file.write(subset_df.to_json(orient='records'))
197
+
198
+ #first_50_rows = subset_df.head(50)
199
+ #print(first_50_rows.to_string())
200
+ #json_data = first_50_rows.to_json(orient='records')
201
+ #print(json_data) # Print JSON representation
202
+ return subset_df
203
+
204
+ INTRODUCTION_TEXT = """
205
+ This is a copied space from Open Source LLM leaderboard. Instead of displaying
206
+ the results as table the space simply provides a gradio API interface to access
207
+ the full leaderboard data easily.
208
+ Example python on how to access the data:
209
+ ```python
210
+ from gradio_client import Client
211
+ import json
212
+ client = Client("https://felixz-open-llm-leaderboard.hf.space/")
213
+ json_data = client.predict("","", api_name='/predict')
214
+ with open(json_data, 'r') as file:
215
+ file_data = file.read()
216
+ # Load the JSON data
217
+ data = json.loads(file_data)
218
+ # Get the headers and the data
219
+ headers = data['headers']
220
+ data = data['data']
221
+ ```
222
+ """
223
+
224
+ interface = gr.Interface(
225
+ fn=display,
226
+ inputs=[gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text"), dummy1],
227
+ outputs=[hidden_leaderboard_table_for_search]
228
+ )
229
 
230
  scheduler = BackgroundScheduler()
231
  scheduler.add_job(restart_space, "interval", seconds=1800)
232
  scheduler.start()
233
+
234
+ interface.launch()