philippds commited on
Commit
78fcc7c
·
verified ·
1 Parent(s): 693b619

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -19
app.py CHANGED
@@ -262,7 +262,18 @@ def get_difficulty_pattern_ids_and_key(rl_env, path):
262
 
263
  return key, difficulty_pattern_ids
264
 
 
 
 
 
 
 
 
 
 
 
265
 
 
266
 
267
  run_update_dataset()
268
 
@@ -292,43 +303,66 @@ with block:
292
  )
293
 
294
  path_ = download_leaderboard_dataset()
295
- # gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  # ENVIRONMENT TABS
297
- with gr.Tabs() as tabs: # elem_classes="tab-buttons"
298
  for env_index in range(0, len(hivex_envs)):
299
  hivex_env = hivex_envs[env_index]
300
  with gr.Tab(f"{hivex_env['title']}") as env_tabs:
301
-
302
- # Call the function to get the actual values
303
  dp_key, difficulty_pattern_ids = get_difficulty_pattern_ids_and_key(
304
  hivex_env["hivex_env"], path_
305
  )
306
- if dp_key is not None:
307
- gr.CheckboxGroup([str(dp_id) for dp_id in difficulty_pattern_ids], label=dp_key)
308
 
309
- # TASK TABS
310
- for task_id in range(0, hivex_env["task_count"]):
311
- task_title = convert_to_title_case(
312
- get_task(hivex_env["hivex_env"], task_id, path_)
313
  )
314
- with gr.TabItem(f"Task {task_id}: {task_title}"):
315
- with gr.Row():
 
 
 
 
 
 
316
  data = get_data(hivex_env["hivex_env"], task_id, path_)
317
- row_count = len(data) # Number of rows in the data
318
 
319
- gr_dataframe = gr.components.Dataframe(
320
  value=data,
321
  headers=["User", "Model"],
322
  datatype=["markdown", "markdown"],
323
- row_count=(
324
- row_count,
325
- "fixed",
326
- ), # Set to the exact number of rows in the data
327
  )
328
 
 
 
 
 
 
 
 
 
329
 
330
  scheduler = BackgroundScheduler()
331
  scheduler.add_job(restart, "interval", seconds=86400)
332
  scheduler.start()
333
 
334
- block.launch()
 
262
 
263
  return key, difficulty_pattern_ids
264
 
265
+ def filter_checkbox_data(rl_env, task_id, selected_values, path):
266
+ """
267
+ Filters the data based on the selected difficulty/pattern values.
268
+ """
269
+ data = get_data(rl_env, task_id, path)
270
+
271
+ # If there are selected values, filter the DataFrame
272
+ if selected_values:
273
+ filter_column = "Pattern" if "Pattern" in data.columns else "Difficulty"
274
+ data = data[data[filter_column].isin(selected_values)]
275
 
276
+ return data
277
 
278
  run_update_dataset()
279
 
 
303
  )
304
 
305
  path_ = download_leaderboard_dataset()
306
+
307
+ def filter_data(rl_env, task_id, selected_values, path):
308
+ """
309
+ Filters the data based on the selected difficulty/pattern values.
310
+ """
311
+ data = get_data(rl_env, task_id, path)
312
+
313
+ # If there are selected values, filter the DataFrame
314
+ if selected_values:
315
+ filter_column = "Pattern" if "Pattern" in data.columns else "Difficulty"
316
+ data = data[data[filter_column].isin(selected_values)]
317
+
318
+ return data
319
+
320
+ def update_filtered_data(selected_values, rl_env, task_id, path):
321
+ filtered_data = filter_data(rl_env, task_id, selected_values, path)
322
+ return filtered_data
323
+
324
  # ENVIRONMENT TABS
325
+ with gr.Tabs() as tabs:
326
  for env_index in range(0, len(hivex_envs)):
327
  hivex_env = hivex_envs[env_index]
328
  with gr.Tab(f"{hivex_env['title']}") as env_tabs:
 
 
329
  dp_key, difficulty_pattern_ids = get_difficulty_pattern_ids_and_key(
330
  hivex_env["hivex_env"], path_
331
  )
 
 
332
 
333
+ if dp_key is not None and difficulty_pattern_ids:
334
+ selected_checkboxes = gr.CheckboxGroup(
335
+ [str(dp_id) for dp_id in difficulty_pattern_ids], label=dp_key
 
336
  )
337
+
338
+ for task_id in range(0, hivex_env["task_count"]):
339
+ task_title = convert_to_title_case(
340
+ get_task(hivex_env["hivex_env"], task_id, path_)
341
+ )
342
+ with gr.TabItem(f"Task {task_id}: {task_title}"):
343
+
344
+ # Display initial data
345
  data = get_data(hivex_env["hivex_env"], task_id, path_)
346
+ row_count = len(data)
347
 
348
+ gr_dataframe = gr.DataFrame(
349
  value=data,
350
  headers=["User", "Model"],
351
  datatype=["markdown", "markdown"],
352
+ row_count=(row_count, "fixed"),
 
 
 
353
  )
354
 
355
+ # Add a callback to update the DataFrame when checkboxes are changed
356
+ selected_checkboxes.change(
357
+ fn=update_filtered_data,
358
+ inputs=[selected_checkboxes, gr.Textbox(hivex_env["hivex_env"]), gr.Number(task_id), gr.Textbox(path_)],
359
+ outputs=gr_dataframe,
360
+ )
361
+ else:
362
+ gr.HTML("<p>No difficulty or pattern data available for this environment.</p>")
363
 
364
  scheduler = BackgroundScheduler()
365
  scheduler.add_job(restart, "interval", seconds=86400)
366
  scheduler.start()
367
 
368
+ block.launch()