abhinav-joshi commited on
Commit
3948397
·
1 Parent(s): 783bedb
src/leaderboard/read_evals.py CHANGED
@@ -122,7 +122,7 @@ class EvalResult:
122
  # AutoEvalColumn.architecture.name: self.architecture,
123
  # AutoEvalColumn.model.name: make_clickable_model(self.full_model),
124
  # AutoEvalColumn.revision.name: self.revision,
125
- # AutoEvalColumn.average.name: average,
126
  # AutoEvalColumn.license.name: self.license,
127
  # AutoEvalColumn.likes.name: self.likes,
128
  # AutoEvalColumn.params.name: self.num_params,
 
122
  # AutoEvalColumn.architecture.name: self.architecture,
123
  # AutoEvalColumn.model.name: make_clickable_model(self.full_model),
124
  # AutoEvalColumn.revision.name: self.revision,
125
+ AutoEvalColumn.average.name: average,
126
  # AutoEvalColumn.license.name: self.license,
127
  # AutoEvalColumn.likes.name: self.likes,
128
  # AutoEvalColumn.params.name: self.num_params,
src/submission/submit.py CHANGED
@@ -14,106 +14,192 @@ from src.submission.check_validity import (
14
  REQUESTED_MODELS = None
15
  USERS_TO_SUBMISSION_DATES = None
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def add_new_eval(
18
  model: str,
19
- base_model: str,
20
- revision: str,
21
- precision: str,
22
- weight_type: str,
23
- model_type: str,
 
24
  ):
25
- global REQUESTED_MODELS
26
- global USERS_TO_SUBMISSION_DATES
27
- if not REQUESTED_MODELS:
28
- REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
29
-
30
- user_name = ""
31
- model_path = model
32
- if "/" in model:
33
- user_name = model.split("/")[0]
34
- model_path = model.split("/")[1]
35
-
36
- precision = precision.split(" ")[0]
37
- current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
38
-
39
- if model_type is None or model_type == "":
40
- return styled_error("Please select a model type.")
41
-
42
- # Does the model actually exist?
43
- if revision == "":
44
- revision = "main"
45
-
46
- # Is the model on the hub?
47
- if weight_type in ["Delta", "Adapter"]:
48
- base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
49
- if not base_model_on_hub:
50
- return styled_error(f'Base model "{base_model}" {error}')
51
-
52
- if not weight_type == "Adapter":
53
- model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
54
- if not model_on_hub:
55
- return styled_error(f'Model "{model}" {error}')
56
-
57
- # Is the model info correctly filled?
58
- try:
59
- model_info = API.model_info(repo_id=model, revision=revision)
60
- except Exception:
61
- return styled_error("Could not get your model information. Please fill it up properly.")
62
-
63
- model_size = get_model_size(model_info=model_info, precision=precision)
64
-
65
- # Were the model card and license filled?
66
- try:
67
- license = model_info.cardData["license"]
68
- except Exception:
69
- return styled_error("Please select a license for your model")
70
-
71
- modelcard_OK, error_msg = check_model_card(model)
72
- if not modelcard_OK:
73
- return styled_error(error_msg)
74
-
75
- # Seems good, creating the eval
76
- print("Adding new eval")
77
-
78
- eval_entry = {
79
- "model": model,
80
- "base_model": base_model,
81
- "revision": revision,
82
- "precision": precision,
83
- "weight_type": weight_type,
84
- "status": "PENDING",
85
- "submitted_time": current_time,
86
- "model_type": model_type,
87
- "likes": model_info.likes,
88
- "params": model_size,
89
- "license": license,
90
- "private": False,
91
- }
92
-
93
- # Check for duplicate submission
94
- if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
95
- return styled_warning("This model has been already submitted.")
96
-
97
- print("Creating eval file")
98
- OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
99
- os.makedirs(OUT_DIR, exist_ok=True)
100
- out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
101
-
102
- with open(out_path, "w") as f:
103
- f.write(json.dumps(eval_entry))
104
-
105
- print("Uploading eval file")
106
  API.upload_file(
107
- path_or_fileobj=out_path,
108
- path_in_repo=out_path.split("eval-queue/")[1],
109
- repo_id=QUEUE_REPO,
110
- repo_type="dataset",
111
- commit_message=f"Add {model} to eval queue",
112
  )
113
 
114
- # Remove the local file
115
- os.remove(out_path)
116
-
117
- return styled_message(
118
- "Your request has been submitted to the evaluation queue!\nPlease wait for up to an hour for the model to show in the PENDING list."
119
  )
 
14
  REQUESTED_MODELS = None
15
  USERS_TO_SUBMISSION_DATES = None
16
 
17
+ OUT_DIR = f"{EVAL_REQUESTS_PATH}"
18
+ RESULTS_PATH = f"{OUT_DIR}/evaluation.json"
19
+
20
+ # def add_new_eval(
21
+ # model: str,
22
+ # base_model: str,
23
+ # revision: str,
24
+ # precision: str,
25
+ # weight_type: str,
26
+ # model_type: str,
27
+ # ):
28
+ # global REQUESTED_MODELS
29
+ # global USERS_TO_SUBMISSION_DATES
30
+ # if not REQUESTED_MODELS:
31
+ # REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(EVAL_REQUESTS_PATH)
32
+
33
+ # user_name = ""
34
+ # model_path = model
35
+ # if "/" in model:
36
+ # user_name = model.split("/")[0]
37
+ # model_path = model.split("/")[1]
38
+
39
+ # precision = precision.split(" ")[0]
40
+ # current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
41
+
42
+ # if model_type is None or model_type == "":
43
+ # return styled_error("Please select a model type.")
44
+
45
+ # # Does the model actually exist?
46
+ # if revision == "":
47
+ # revision = "main"
48
+
49
+ # # Is the model on the hub?
50
+ # if weight_type in ["Delta", "Adapter"]:
51
+ # base_model_on_hub, error, _ = is_model_on_hub(
52
+ # model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True
53
+ # )
54
+ # if not base_model_on_hub:
55
+ # return styled_error(f'Base model "{base_model}" {error}')
56
+
57
+ # if not weight_type == "Adapter":
58
+ # model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
59
+ # if not model_on_hub:
60
+ # return styled_error(f'Model "{model}" {error}')
61
+
62
+ # # Is the model info correctly filled?
63
+ # try:
64
+ # model_info = API.model_info(repo_id=model, revision=revision)
65
+ # except Exception:
66
+ # return styled_error("Could not get your model information. Please fill it up properly.")
67
+
68
+ # model_size = get_model_size(model_info=model_info, precision=precision)
69
+
70
+ # # Were the model card and license filled?
71
+ # try:
72
+ # license = model_info.cardData["license"]
73
+ # except Exception:
74
+ # return styled_error("Please select a license for your model")
75
+
76
+ # modelcard_OK, error_msg = check_model_card(model)
77
+ # if not modelcard_OK:
78
+ # return styled_error(error_msg)
79
+
80
+ # # Seems good, creating the eval
81
+ # print("Adding new eval")
82
+
83
+ # eval_entry = {
84
+ # "model": model,
85
+ # "base_model": base_model,
86
+ # "revision": revision,
87
+ # "precision": precision,
88
+ # "weight_type": weight_type,
89
+ # "status": "PENDING",
90
+ # "submitted_time": current_time,
91
+ # "model_type": model_type,
92
+ # "likes": model_info.likes,
93
+ # "params": model_size,
94
+ # "license": license,
95
+ # "private": False,
96
+ # }
97
+
98
+ # # Check for duplicate submission
99
+ # if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
100
+ # return styled_warning("This model has been already submitted.")
101
+
102
+ # print("Creating eval file")
103
+ # OUT_DIR = f"{EVAL_REQUESTS_PATH}/{user_name}"
104
+ # os.makedirs(OUT_DIR, exist_ok=True)
105
+ # out_path = f"{OUT_DIR}/{model_path}_eval_request_False_{precision}_{weight_type}.json"
106
+
107
+ # with open(out_path, "w") as f:
108
+ # f.write(json.dumps(eval_entry))
109
+
110
+ # print("Uploading eval file")
111
+ # API.upload_file(
112
+ # path_or_fileobj=out_path,
113
+ # path_in_repo=out_path.split("eval-queue/")[1],
114
+ # repo_id=QUEUE_REPO,
115
+ # repo_type="dataset",
116
+ # commit_message=f"Add {model} to eval queue",
117
+ # )
118
+
119
+ # # Remove the local file
120
+ # os.remove(out_path)
121
+
122
+ # return styled_message(
123
+ # "Your request has been submitted to the evaluation queue!\nPlease wait for up to an hour for the model to show in the PENDING list."
124
+ # )
125
+
126
+
127
+ def format_error(msg):
128
+ return f"<p style='color: red; font-size: 20px; text-align: center;'>{msg}</p>"
129
+
130
+
131
+ def format_warning(msg):
132
+ return f"<p style='color: orange; font-size: 20px; text-align: center;'>{msg}</p>"
133
+
134
+
135
+ def format_log(msg):
136
+ return f"<p style='color: green; font-size: 20px; text-align: center;'>{msg}</p>"
137
+
138
+
139
+ def model_hyperlink(link, model_name):
140
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>'
141
+
142
+
143
+ def input_verification(model, model_family, forget_rate, url, path_to_file, organisation, mail):
144
+ for input in [model, model_family, forget_rate, url, organisation]:
145
+ if input == "":
146
+ return format_warning("Please fill all the fields.")
147
+
148
+ # Very basic email parsing
149
+ _, parsed_mail = parseaddr(mail)
150
+ if not "@" in parsed_mail:
151
+ return format_warning("Please provide a valid email adress.")
152
+
153
+ if path_to_file is None:
154
+ return format_warning("Please attach a file.")
155
+
156
+ return parsed_mail
157
+
158
+
159
  def add_new_eval(
160
  model: str,
161
+ model_family: str,
162
+ forget_rate: str,
163
+ url: str,
164
+ path_to_file: str,
165
+ organisation: str,
166
+ mail: str,
167
  ):
168
+
169
+ parsed_mail = input_verification(model, model_family, forget_rate, url, path_to_file, organisation, mail)
170
+
171
+ # load the file
172
+ df = pd.read_csv(path_to_file)
173
+
174
+ # modify the df to include metadata
175
+ df["model"] = model
176
+ df["model_family"] = model_family
177
+ df["forget_rate"] = forget_rate
178
+ df["url"] = url
179
+ df["organisation"] = organisation
180
+ df["mail"] = parsed_mail
181
+ df["timestamp"] = datetime.datetime.now()
182
+
183
+ # upload to spaces using the hf api at
184
+
185
+ path_in_repo = f"versions/{model_family}-{forget_rate.replace('%', 'p')}"
186
+ file_name = f"{model}-{organisation}-{datetime.datetime.now().strftime('%Y-%m-%d')}.csv"
187
+
188
+ # upload the df to spaces
189
+ import io
190
+
191
+ buffer = io.BytesIO()
192
+ df.to_csv(buffer, index=False) # Write the DataFrame to a buffer in CSV format
193
+ buffer.seek(0) # Rewind the buffer to the beginning
194
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  API.upload_file(
196
+ repo_id=RESULTS_PATH,
197
+ path_in_repo=f"{path_in_repo}/{file_name}",
198
+ path_or_fileobj=buffer,
199
+ token=TOKEN,
200
+ repo_type="space",
201
  )
202
 
203
+ return format_log(
204
+ f"Model {model} submitted by {organisation} successfully. \nPlease refresh the leaderboard, and wait a bit to see the score displayed"
 
 
 
205
  )