helshahaby commited on
Commit
b9459d9
·
verified ·
1 Parent(s): ce4d20a

Update src/display/utils.py

Browse files
Files changed (1) hide show
  1. src/display/utils.py +35 -29
src/display/utils.py CHANGED
@@ -1,10 +1,11 @@
1
- from dataclasses import dataclass, field, make_dataclass
2
  from enum import Enum
3
 
4
  import pandas as pd
5
 
6
  from src.about import Tasks
7
 
 
8
  def fields(raw_class):
9
  return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
10
 
@@ -20,39 +21,45 @@ class ColumnContent:
20
  hidden: bool = False
21
  never_hidden: bool = False
22
 
23
- ## Leaderboard columns
24
- auto_eval_column_dict = []
25
- # Init
26
- auto_eval_column_dict.append(["model_type_symbol", ColumnContent, field(default_factory=lambda: ColumnContent("T", "str", True, never_hidden=True))])
27
- auto_eval_column_dict.append(["model", ColumnContent, field(default_factory=lambda: ColumnContent("Model", "markdown", True, never_hidden=True))])
28
- # Scores
29
- auto_eval_column_dict.append(["average", ColumnContent, field(default_factory=lambda: ColumnContent("Average ⬆️", "number", True))])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  for task in Tasks:
31
- auto_eval_column_dict.append([task.name, ColumnContent, field(default_factory=lambda t=task: ColumnContent(t.value.col_name, "number", True))])
32
- # Model information
33
- auto_eval_column_dict.append(["model_type", ColumnContent, field(default_factory=lambda: ColumnContent("Type", "str", False))])
34
- auto_eval_column_dict.append(["architecture", ColumnContent, field(default_factory=lambda: ColumnContent("Architecture", "str", False))])
35
- auto_eval_column_dict.append(["weight_type", ColumnContent, field(default_factory=lambda: ColumnContent("Weight type", "str", False, True))])
36
- auto_eval_column_dict.append(["precision", ColumnContent, field(default_factory=lambda: ColumnContent("Precision", "str", False))])
37
- auto_eval_column_dict.append(["license", ColumnContent, field(default_factory=lambda: ColumnContent("Hub License", "str", False))])
38
- auto_eval_column_dict.append(["params", ColumnContent, field(default_factory=lambda: ColumnContent("#Params (B)", "number", False))])
39
- auto_eval_column_dict.append(["likes", ColumnContent, field(default_factory=lambda: ColumnContent("Hub ❤️", "number", False))])
40
- auto_eval_column_dict.append(["still_on_hub", ColumnContent, field(default_factory=lambda: ColumnContent("Available on the hub", "bool", False))])
41
- auto_eval_column_dict.append(["revision", ColumnContent, field(default_factory=lambda: ColumnContent("Model sha", "str", False, False))])
42
-
43
- # We use make_dataclass to dynamically fill the scores from Tasks
44
- AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
45
 
46
  ## For the queue columns in the submission tab
47
- @dataclass(frozen=True)
48
- class EvalQueueColumn: # Queue column
49
  model = ColumnContent("model", "markdown", True)
50
  revision = ColumnContent("revision", "str", True)
51
  private = ColumnContent("private", "bool", True)
52
  precision = ColumnContent("precision", "str", True)
53
- weight_type = ColumnContent("weight_type", "str", "Original")
54
  status = ColumnContent("status", "str", True)
55
 
 
56
  ## All the model information that we might need
57
  @dataclass
58
  class ModelDetails:
@@ -98,8 +105,7 @@ class Precision(Enum):
98
 
99
 
100
  # Column selection
101
- COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
102
- EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
103
- EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
104
-
105
  BENCHMARK_COLS = [t.value.col_name for t in Tasks]
 
1
+ from dataclasses import dataclass, field
2
  from enum import Enum
3
 
4
  import pandas as pd
5
 
6
  from src.about import Tasks
7
 
8
+
9
  def fields(raw_class):
10
  return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
11
 
 
21
  hidden: bool = False
22
  never_hidden: bool = False
23
 
24
+
25
+ # ── AutoEvalColumn ────────────────────────────────────────────────────────
26
+ # Built as a plain class with class-level attributes so that
27
+ # AutoEvalColumn.precision.name (class-level access used in read_evals.py)
28
+ # works correctly on all Python versions.
29
+ # Previously used make_dataclass() which only supports instance-level access.
30
+ class AutoEvalColumn:
31
+ # Identity
32
+ model_type_symbol = ColumnContent("T", "str", True, never_hidden=True)
33
+ model = ColumnContent("Model", "markdown", True, never_hidden=True)
34
+ # Scores
35
+ average = ColumnContent("Average ⬆️", "number", True)
36
+ # Model information
37
+ model_type = ColumnContent("Type", "str", False)
38
+ architecture = ColumnContent("Architecture", "str", False)
39
+ weight_type = ColumnContent("Weight type", "str", False, True)
40
+ precision = ColumnContent("Precision", "str", False)
41
+ license = ColumnContent("Hub License", "str", False)
42
+ params = ColumnContent("#Params (B)", "number", False)
43
+ likes = ColumnContent("Hub ❤️", "number", False)
44
+ still_on_hub = ColumnContent("Available on the hub", "bool", False)
45
+ revision = ColumnContent("Model sha", "str", False, False)
46
+
47
+
48
+ # Dynamically add task score columns from Tasks enum
49
  for task in Tasks:
50
+ setattr(AutoEvalColumn, task.name, ColumnContent(task.value.col_name, "number", True))
51
+
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  ## For the queue columns in the submission tab
54
+ class EvalQueueColumn:
 
55
  model = ColumnContent("model", "markdown", True)
56
  revision = ColumnContent("revision", "str", True)
57
  private = ColumnContent("private", "bool", True)
58
  precision = ColumnContent("precision", "str", True)
59
+ weight_type = ColumnContent("weight_type", "str", True)
60
  status = ColumnContent("status", "str", True)
61
 
62
+
63
  ## All the model information that we might need
64
  @dataclass
65
  class ModelDetails:
 
105
 
106
 
107
  # Column selection
108
+ COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
109
+ EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
110
+ EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
 
111
  BENCHMARK_COLS = [t.value.col_name for t in Tasks]