guipenedo HF staff commited on
Commit
37f8510
1 Parent(s): c82d897
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -8,9 +8,11 @@ import pandas as pd
8
  from datasets import load_dataset
9
  from gradio_leaderboard import Leaderboard, SelectColumns, SearchColumns, ColumnFilter
10
 
11
- df = pd.read_json("https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/tasks_table.jsonl", lines=True).explode("suite").reset_index(drop=True)
 
12
 
13
- with urllib.request.urlopen("https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/tasks_prompt_formatting.py") as f:
 
14
  tasks_prompt_functions_raw = f.read().decode('utf-8')
15
  tree = ast.parse(tasks_prompt_functions_raw)
16
  tasks_prompt_functions = {}
@@ -22,11 +24,14 @@ with urllib.request.urlopen("https://raw.githubusercontent.com/huggingface/light
22
  function_code = ast.get_source_segment(tasks_prompt_functions_raw, node)
23
  tasks_prompt_functions[function_name] = function_code
24
 
 
25
  def load_task_metadata(task_id):
26
  task_row = df.iloc[task_id]
27
- return (task_row.to_dict(), f"""Examples from the HF repository ([{task_row['hf_repo']}](https://huggingface.co/datasets/{task_row['hf_repo']}))""",
 
28
  tasks_prompt_functions.get(task_row["prompt_function"]), "unknown")
29
 
 
30
  def load_task_examples(task_id):
31
  task_row = df.iloc[task_id]
32
  dataset = load_dataset(task_row["hf_repo"], task_row["hf_subset"], split="+".join(task_row["evaluation_splits"]),
@@ -34,9 +39,9 @@ def load_task_examples(task_id):
34
 
35
  sample_data = next(dataset.iter(20))
36
  # dictionary of lists to list of dictionaries
37
- return pd.DataFrame(dict(zip(sample_data, t if not isinstance(t, dict) and not isinstance(t, list) else json.dumps(t)))
38
- for t in zip(*sample_data.values()))
39
-
40
 
41
 
42
  with gr.Blocks() as demo:
@@ -47,10 +52,13 @@ with gr.Blocks() as demo:
47
  with gr.TabItem("🗃️ Tasks List"):
48
  Leaderboard(
49
  value=df,
50
- select_columns=SelectColumns(default_selection=["name", "suite", "prompt_function", "hf_repo", "hf_subset", "evaluation_splits", "metric"],
51
- cant_deselect=["name", "suite"],
52
- label="Columns to display"),
53
- search_columns=SearchColumns(primary_column="name", secondary_columns=["suite", "prompt_function", "hf_repo", "metric"],
 
 
 
54
  placeholder="Search for a task by name, suite, prompt_function, hf_repo or "
55
  "metric. To search by suite, for example, type 'suite:<query>'. Separate queries by \";\"",
56
  label="Search"),
@@ -75,9 +83,10 @@ with gr.Blocks() as demo:
75
  task_dataset_header = gr.Markdown("Examples from the HF repository")
76
  task_dataset = gr.Dataframe(wrap=True)
77
 
78
- gr.on(triggers=[task_inspector_selector.change], inputs=[task_inspector_selector], outputs=[task_metadata, task_dataset_header, task_prompt_function], fn=load_task_metadata)
79
- gr.on(triggers=[task_inspector_selector.change], inputs=[task_inspector_selector], outputs=[task_dataset], fn=load_task_examples)
80
-
 
81
 
82
  if __name__ == "__main__":
83
  demo.launch()
 
8
  from datasets import load_dataset
9
  from gradio_leaderboard import Leaderboard, SelectColumns, SearchColumns, ColumnFilter
10
 
11
+ df = pd.read_json("https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/tasks_table.jsonl",
12
+ lines=True).explode("suite").reset_index(drop=True)
13
 
14
+ with urllib.request.urlopen(
15
+ "https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/tasks_prompt_formatting.py") as f:
16
  tasks_prompt_functions_raw = f.read().decode('utf-8')
17
  tree = ast.parse(tasks_prompt_functions_raw)
18
  tasks_prompt_functions = {}
 
24
  function_code = ast.get_source_segment(tasks_prompt_functions_raw, node)
25
  tasks_prompt_functions[function_name] = function_code
26
 
27
+
28
  def load_task_metadata(task_id):
29
  task_row = df.iloc[task_id]
30
+ return (task_row.to_dict(),
31
+ f"""Examples from the HF repository ([{task_row['hf_repo']}](https://huggingface.co/datasets/{task_row['hf_repo']}))""",
32
  tasks_prompt_functions.get(task_row["prompt_function"]), "unknown")
33
 
34
+
35
  def load_task_examples(task_id):
36
  task_row = df.iloc[task_id]
37
  dataset = load_dataset(task_row["hf_repo"], task_row["hf_subset"], split="+".join(task_row["evaluation_splits"]),
 
39
 
40
  sample_data = next(dataset.iter(20))
41
  # dictionary of lists to list of dictionaries
42
+ return pd.DataFrame(
43
+ dict(zip(sample_data, t if not isinstance(t, dict) and not isinstance(t, list) else json.dumps(t)))
44
+ for t in zip(*sample_data.values()))
45
 
46
 
47
  with gr.Blocks() as demo:
 
52
  with gr.TabItem("🗃️ Tasks List"):
53
  Leaderboard(
54
  value=df,
55
+ select_columns=SelectColumns(
56
+ default_selection=["name", "suite", "prompt_function", "hf_repo", "hf_subset", "evaluation_splits",
57
+ "metric"],
58
+ cant_deselect=["name", "suite"],
59
+ label="Columns to display"),
60
+ search_columns=SearchColumns(primary_column="name",
61
+ secondary_columns=["suite", "prompt_function", "hf_repo", "metric"],
62
  placeholder="Search for a task by name, suite, prompt_function, hf_repo or "
63
  "metric. To search by suite, for example, type 'suite:<query>'. Separate queries by \";\"",
64
  label="Search"),
 
83
  task_dataset_header = gr.Markdown("Examples from the HF repository")
84
  task_dataset = gr.Dataframe(wrap=True)
85
 
86
+ gr.on(triggers=[task_inspector_selector.change], inputs=[task_inspector_selector],
87
+ outputs=[task_metadata, task_dataset_header, task_prompt_function], fn=load_task_metadata)
88
+ gr.on(triggers=[task_inspector_selector.change], inputs=[task_inspector_selector], outputs=[task_dataset],
89
+ fn=load_task_examples)
90
 
91
  if __name__ == "__main__":
92
  demo.launch()