rodrigomasini commited on
Commit
80ab0f0
·
verified ·
1 Parent(s): 5f99deb

Update app.py

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