MotzWanted commited on
Commit
a87427d
1 Parent(s): d17d71b

fix: display bug in gadio

Browse files
Files changed (1) hide show
  1. src/display/utils.py +109 -30
src/display/utils.py CHANGED
@@ -1,11 +1,13 @@
1
- from dataclasses import dataclass, make_dataclass
2
  from enum import Enum
3
 
4
  import pandas as pd
5
 
6
 
7
  def fields(raw_class):
8
- return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"]
 
 
9
 
10
 
11
  @dataclass
@@ -16,16 +18,18 @@ class Task:
16
 
17
 
18
  class Tasks(Enum):
19
-
20
  # medqa = Task("medqa", "acc_norm", "MedQA") # medqa_4options?
21
  # am i just manually going to include everything? hmm for display, idk how easily do i want to be able to tick this on and off?
22
- # where does the acc_norm come from
23
- medmcqa = Task("medmcqa", "acc_norm", "MedMCQA")
24
  pubmedqa = Task("pubmedqa", "acc", "PubMedQA")
25
- # task2 = Task("pubmedqa_no_context", "PubMedQA_no_context", 0)
26
- pubmedqa_no_context = Task("pubmedqa_no_context", "acc", "PubMedQA_no_context") # adding this throws an error. -> value=leaderboard_df[
 
 
27
  biolama_umls = Task("biolama_umls", "acc", "BioLAMA-UMLS")
28
-
 
29
  # These classes are for user facing column names,
30
  # to avoid having to change them all around the code
31
  # when a modif is needed
@@ -39,29 +43,103 @@ class ColumnContent:
39
  dummy: bool = False
40
  is_task: bool = False
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  auto_eval_column_dict = []
43
  # Init
44
- auto_eval_column_dict.append(["model_type_symbol", ColumnContent, ColumnContent("T", "str", True, never_hidden=True)])
45
- auto_eval_column_dict.append(["model", ColumnContent, ColumnContent("Model", "markdown", True, never_hidden=True)])
46
- #Scores
47
- auto_eval_column_dict.append(["average", ColumnContent, ColumnContent("Avg", "number", True)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  for task in Tasks:
49
- auto_eval_column_dict.append([task.name, ColumnContent, ColumnContent(task.value.col_name, "number", True, is_task=True)]) # hidden was true by default
 
 
 
 
 
 
50
  # Model information
51
- auto_eval_column_dict.append(["model_type", ColumnContent, ColumnContent("Type", "str", False)])
52
- auto_eval_column_dict.append(["architecture", ColumnContent, ColumnContent("Architecture", "str", False)])
53
- auto_eval_column_dict.append(["weight_type", ColumnContent, ColumnContent("Weight type", "str", False, True)])
54
- auto_eval_column_dict.append(["precision", ColumnContent, ColumnContent("Precision", "str", False)])
55
- auto_eval_column_dict.append(["license", ColumnContent, ColumnContent("Hub License", "str", False)])
56
- auto_eval_column_dict.append(["params", ColumnContent, ColumnContent("#Params (B)", "number", False)])
57
- auto_eval_column_dict.append(["likes", ColumnContent, ColumnContent("Hub ❤️", "number", False)])
58
- auto_eval_column_dict.append(["still_on_hub", ColumnContent, ColumnContent("Available on the hub", "bool", False)])
59
- auto_eval_column_dict.append(["revision", ColumnContent, ColumnContent("Model sha", "str", False, False)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  # Dummy column for the search bar (hidden by the custom CSS)
61
- auto_eval_column_dict.append(["dummy", ColumnContent, ColumnContent("model_name_for_query", "str", False, dummy=True)])
 
 
 
 
 
 
 
 
 
 
62
 
63
  # We use make dataclass to dynamically fill the scores from Tasks
64
- AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_dict, frozen=True)
65
 
66
 
67
  @dataclass(frozen=True)
@@ -109,9 +187,6 @@ class WeightType(Enum):
109
  Delta = ModelDetails("Delta")
110
 
111
 
112
-
113
-
114
-
115
  class Precision(Enum):
116
  float32 = ModelDetails("float32")
117
  float16 = ModelDetails("float16")
@@ -136,13 +211,17 @@ class Precision(Enum):
136
  if precision in ["GPTQ", "None"]:
137
  return Precision.qt_GPTQ
138
  return Precision.Unknown
139
-
140
 
141
  # Column selection
142
  COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
143
  TYPES = [c.type for c in fields(AutoEvalColumn) if not c.hidden]
144
- COLS_LITE = [c.name for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
145
- TYPES_LITE = [c.type for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden]
 
 
 
 
146
 
147
  EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
148
  EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]
 
1
+ from dataclasses import dataclass, field, make_dataclass
2
  from enum import Enum
3
 
4
  import pandas as pd
5
 
6
 
7
  def fields(raw_class):
8
+ return [
9
+ v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__"
10
+ ]
11
 
12
 
13
  @dataclass
 
18
 
19
 
20
  class Tasks(Enum):
 
21
  # medqa = Task("medqa", "acc_norm", "MedQA") # medqa_4options?
22
  # am i just manually going to include everything? hmm for display, idk how easily do i want to be able to tick this on and off?
23
+ # where does the acc_norm come from
24
+ medmcqa = Task("medmcqa", "acc_norm", "MedMCQA")
25
  pubmedqa = Task("pubmedqa", "acc", "PubMedQA")
26
+ # task2 = Task("pubmedqa_no_context", "PubMedQA_no_context", 0)
27
+ pubmedqa_no_context = Task(
28
+ "pubmedqa_no_context", "acc", "PubMedQA_no_context"
29
+ ) # adding this throws an error. -> value=leaderboard_df[
30
  biolama_umls = Task("biolama_umls", "acc", "BioLAMA-UMLS")
31
+
32
+
33
  # These classes are for user facing column names,
34
  # to avoid having to change them all around the code
35
  # when a modif is needed
 
43
  dummy: bool = False
44
  is_task: bool = False
45
 
46
+
47
+ # Define a function to generate ColumnContent instances
48
+ def column_content_factory(
49
+ name: str,
50
+ type: str,
51
+ displayed_by_default: bool,
52
+ hidden: bool = False,
53
+ never_hidden: bool = False,
54
+ dummy: bool = False,
55
+ is_task: bool = False,
56
+ ):
57
+ return lambda: ColumnContent(
58
+ name=name,
59
+ type=type,
60
+ displayed_by_default=displayed_by_default,
61
+ hidden=hidden,
62
+ never_hidden=never_hidden,
63
+ dummy=dummy,
64
+ is_task=is_task,
65
+ )
66
+
67
+
68
  auto_eval_column_dict = []
69
  # Init
70
+ auto_eval_column_dict.append(
71
+ [
72
+ "model_type_symbol",
73
+ ColumnContent,
74
+ ColumnContent("T", "str", True, never_hidden=True),
75
+ ]
76
+ )
77
+ auto_eval_column_dict.append(
78
+ [
79
+ "model",
80
+ ColumnContent,
81
+ ColumnContent("Model", "markdown", True, never_hidden=True),
82
+ ]
83
+ )
84
+ # Scores
85
+ auto_eval_column_dict.append(
86
+ ["average", ColumnContent, ColumnContent("Avg", "number", True)]
87
+ )
88
  for task in Tasks:
89
+ auto_eval_column_dict.append(
90
+ [
91
+ task.name,
92
+ ColumnContent,
93
+ ColumnContent(task.value.col_name, "number", True, is_task=True),
94
+ ]
95
+ ) # hidden was true by default
96
  # Model information
97
+ auto_eval_column_dict.append(
98
+ ["model_type", ColumnContent, ColumnContent("Type", "str", False)]
99
+ )
100
+ auto_eval_column_dict.append(
101
+ ["architecture", ColumnContent, ColumnContent("Architecture", "str", False)]
102
+ )
103
+ auto_eval_column_dict.append(
104
+ ["weight_type", ColumnContent, ColumnContent("Weight type", "str", False, True)]
105
+ )
106
+ auto_eval_column_dict.append(
107
+ ["precision", ColumnContent, ColumnContent("Precision", "str", False)]
108
+ )
109
+ auto_eval_column_dict.append(
110
+ ["license", ColumnContent, ColumnContent("Hub License", "str", False)]
111
+ )
112
+ auto_eval_column_dict.append(
113
+ ["params", ColumnContent, ColumnContent("#Params (B)", "number", False)]
114
+ )
115
+ auto_eval_column_dict.append(
116
+ ["likes", ColumnContent, ColumnContent("Hub ���️", "number", False)]
117
+ )
118
+ auto_eval_column_dict.append(
119
+ [
120
+ "still_on_hub",
121
+ ColumnContent,
122
+ ColumnContent("Available on the hub", "bool", False),
123
+ ]
124
+ )
125
+ auto_eval_column_dict.append(
126
+ ["revision", ColumnContent, ColumnContent("Model sha", "str", False, False)]
127
+ )
128
  # Dummy column for the search bar (hidden by the custom CSS)
129
+ # Define the structure of your dataclass fields with default_factory for mutable defaults
130
+ auto_eval_column_fields = [
131
+ (
132
+ "model_type_symbol",
133
+ ColumnContent,
134
+ field(
135
+ default_factory=column_content_factory("T", "str", True, never_hidden=True)
136
+ ),
137
+ ),
138
+ # Add other fields similarly...
139
+ ]
140
 
141
  # We use make dataclass to dynamically fill the scores from Tasks
142
+ AutoEvalColumn = make_dataclass("AutoEvalColumn", auto_eval_column_fields, frozen=True)
143
 
144
 
145
  @dataclass(frozen=True)
 
187
  Delta = ModelDetails("Delta")
188
 
189
 
 
 
 
190
  class Precision(Enum):
191
  float32 = ModelDetails("float32")
192
  float16 = ModelDetails("float16")
 
211
  if precision in ["GPTQ", "None"]:
212
  return Precision.qt_GPTQ
213
  return Precision.Unknown
214
+
215
 
216
  # Column selection
217
  COLS = [c.name for c in fields(AutoEvalColumn) if not c.hidden]
218
  TYPES = [c.type for c in fields(AutoEvalColumn) if not c.hidden]
219
+ COLS_LITE = [
220
+ c.name for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden
221
+ ]
222
+ TYPES_LITE = [
223
+ c.type for c in fields(AutoEvalColumn) if c.displayed_by_default and not c.hidden
224
+ ]
225
 
226
  EVAL_COLS = [c.name for c in fields(EvalQueueColumn)]
227
  EVAL_TYPES = [c.type for c in fields(EvalQueueColumn)]