philippds commited on
Commit
009cd74
·
verified ·
1 Parent(s): c0cfb75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -35
app.py CHANGED
@@ -260,7 +260,23 @@ def get_difficulty_pattern_ids_and_key(rl_env, path):
260
  difficulty_pattern_ids = []
261
 
262
  return key, difficulty_pattern_ids
 
 
 
 
 
 
263
 
 
 
 
 
 
 
 
 
 
 
264
 
265
  run_update_dataset()
266
 
@@ -291,23 +307,6 @@ with block:
291
 
292
  path_ = download_leaderboard_dataset()
293
 
294
- def filter_data(rl_env, task_id, selected_values, path):
295
- """
296
- Filters the data based on the selected difficulty/pattern values.
297
- """
298
- data = get_data(rl_env, task_id, path)
299
-
300
- # If there are selected values, filter the DataFrame
301
- if selected_values:
302
- filter_column = "Pattern" if "Pattern" in data.columns else "Difficulty"
303
- data = data[data[filter_column].isin(selected_values)]
304
-
305
- return data
306
-
307
- def update_filtered_data(selected_values, rl_env, task_id, path):
308
- filtered_data = filter_data(rl_env, task_id, selected_values, path)
309
- return filtered_data
310
-
311
  # ENVIRONMENT TABS
312
  with gr.Tabs() as tabs:
313
  for env_index in range(0, len(hivex_envs)):
@@ -318,38 +317,39 @@ with block:
318
  )
319
 
320
  # Check if dp_key is defined and difficulty_pattern_ids is not empty
321
- if dp_key is not None and len(difficulty_pattern_ids) > 0:
322
  selected_checkboxes = gr.CheckboxGroup(
323
  [str(dp_id) for dp_id in difficulty_pattern_ids], label=dp_key
324
  )
325
 
326
- for task_id in range(0, hivex_env["task_count"]):
327
- task_title = convert_to_title_case(
328
- get_task(hivex_env["hivex_env"], task_id, path_)
329
- )
330
- with gr.TabItem(f"Task {task_id}: {task_title}"):
331
 
332
- # Display initial data
333
- data = get_data(hivex_env["hivex_env"], task_id, path_)
334
- row_count = len(data)
335
 
336
- gr_dataframe = gr.DataFrame(
337
- value=data,
338
- headers=["User", "Model"],
339
- datatype=["markdown", "markdown"],
340
- row_count=(row_count, "fixed"),
341
- )
342
 
343
- if dp_key is not None and len(difficulty_pattern_ids) > 0:
344
  # Add a callback to update the DataFrame when checkboxes are changed
345
  selected_checkboxes.change(
346
  fn=update_filtered_data,
347
- inputs=[selected_checkboxes, hivex_env["hivex_env"], task_id, path_],
348
  outputs=gr_dataframe,
349
  )
 
 
350
 
351
  scheduler = BackgroundScheduler()
352
  scheduler.add_job(restart, "interval", seconds=86400)
353
  scheduler.start()
354
 
355
- block.launch()
 
260
  difficulty_pattern_ids = []
261
 
262
  return key, difficulty_pattern_ids
263
+
264
+ def filter_data(rl_env, task_id, selected_values, path):
265
+ """
266
+ Filters the data based on the selected difficulty/pattern values.
267
+ """
268
+ data = get_data(rl_env, task_id, path)
269
 
270
+ # If there are selected values, filter the DataFrame
271
+ if selected_values:
272
+ filter_column = "Pattern" if "Pattern" in data.columns else "Difficulty"
273
+ data = data[data[filter_column].isin(selected_values)]
274
+
275
+ return data
276
+
277
+ def update_filtered_data(selected_values, rl_env, task_id, path):
278
+ filtered_data = filter_data(rl_env, task_id, selected_values, path)
279
+ return filtered_data
280
 
281
  run_update_dataset()
282
 
 
307
 
308
  path_ = download_leaderboard_dataset()
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  # ENVIRONMENT TABS
311
  with gr.Tabs() as tabs:
312
  for env_index in range(0, len(hivex_envs)):
 
317
  )
318
 
319
  # Check if dp_key is defined and difficulty_pattern_ids is not empty
320
+ if dp_key is not None and difficulty_pattern_ids.size > 0:
321
  selected_checkboxes = gr.CheckboxGroup(
322
  [str(dp_id) for dp_id in difficulty_pattern_ids], label=dp_key
323
  )
324
 
325
+ for task_id in range(0, hivex_env["task_count"]):
326
+ task_title = convert_to_title_case(
327
+ get_task(hivex_env["hivex_env"], task_id, path_)
328
+ )
329
+ with gr.TabItem(f"Task {task_id}: {task_title}"):
330
 
331
+ # Display initial data
332
+ data = get_data(hivex_env["hivex_env"], task_id, path_)
333
+ row_count = len(data)
334
 
335
+ gr_dataframe = gr.DataFrame(
336
+ value=data,
337
+ headers=["User", "Model"],
338
+ datatype=["markdown", "markdown"],
339
+ row_count=(row_count, "fixed"),
340
+ )
341
 
 
342
  # Add a callback to update the DataFrame when checkboxes are changed
343
  selected_checkboxes.change(
344
  fn=update_filtered_data,
345
+ inputs=[selected_checkboxes, gr.Textbox(hivex_env["hivex_env"]), gr.Number(task_id), gr.Textbox(path_)],
346
  outputs=gr_dataframe,
347
  )
348
+ else:
349
+ gr.HTML("<p>No difficulty or pattern data available for this environment.</p>")
350
 
351
  scheduler = BackgroundScheduler()
352
  scheduler.add_job(restart, "interval", seconds=86400)
353
  scheduler.start()
354
 
355
+ block.launch()