yangzhitao commited on
Commit
77ae007
·
2 Parent(s): 962327e 446074e

Merge branch 'main' of hf.co:spaces/y-playground/leaderboard

Browse files
app.py CHANGED
@@ -375,40 +375,80 @@ def main():
375
  return data.iloc[row_idx, 0] # 返回模型名
376
  return ""
377
 
378
- search_name.change(fn=search_models, inputs=search_name, outputs=table)
379
- table.select(fn=on_select, inputs=table, outputs=model_name_textbox)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
 
381
- with gr.Column():
382
- precision = gr.Dropdown(
383
- choices=[i.value.name for i in Precision if i != Precision.Unknown],
384
- label="Precision",
385
- multiselect=False,
386
- value="float16",
387
- interactive=True,
388
- )
389
- weight_type = gr.Dropdown(
390
- choices=[i.value.name for i in WeightType],
391
- label="Weights type",
392
- multiselect=False,
393
- value="Original",
394
- interactive=True,
395
- )
396
- base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
397
-
398
- submit_button = gr.Button("Submit Eval")
399
- submission_result = gr.Markdown()
400
- submit_button.click(
401
- add_new_eval,
402
- [
403
- model_name_textbox,
404
- base_model_name_textbox,
405
- revision_name_textbox,
406
- precision,
407
- weight_type,
408
- model_type,
409
- ],
410
- submission_result,
411
- )
 
 
 
412
 
413
  # Backend status indicator
414
  backend_status = gr.HTML(
 
375
  return data.iloc[row_idx, 0] # 返回模型名
376
  return ""
377
 
378
+ search_name.change(fn=search_models, inputs=search_name, outputs=table)
379
+ table.select(fn=on_select, inputs=table, outputs=model_name_textbox)
380
+
381
+ def file_to_json_str(file) -> str:
382
+ """
383
+ 读取上传的 JSON 文件并返回字符串
384
+ 如果解析失败,抛出异常以阻止上传成功
385
+ """
386
+ if file is None:
387
+ return ""
388
+ try:
389
+ import json
390
+ # file 是文件路径字符串(当 type="filepath" 时)
391
+ file_path = file if isinstance(file, str) else file.name
392
+ with open(file_path, 'r', encoding='utf-8') as f:
393
+ json_data = json.load(f)
394
+ # 将 JSON 对象转换为格式化的字符串
395
+ json_str = json.dumps(json_data, indent=2, ensure_ascii=False)
396
+ return json_str
397
+ except Exception as e:
398
+ raise gr.Error(f"Error reading JSON file: {str(e)}")
399
+
400
+ json_upload = gr.File(
401
+ label="Upload JSON file",
402
+ file_types=[".json"],
403
+ type="filepath",
404
+ )
405
+ json_str = gr.Textbox(
406
+ label="JSON Content",
407
+ placeholder="JSON content will appear here after upload",
408
+ lines=10,
409
+ interactive=True,
410
+ visible=False,
411
+ )
412
+ json_upload.upload(
413
+ fn=file_to_json_str,
414
+ inputs=json_upload,
415
+ outputs=json_str,
416
+ )
417
 
418
+
419
+ with gr.Column():
420
+ precision = gr.Dropdown(
421
+ choices=[i.value.name for i in Precision if i != Precision.Unknown],
422
+ label="Precision",
423
+ multiselect=False,
424
+ value="float16",
425
+ interactive=True,
426
+ )
427
+ weight_type = gr.Dropdown(
428
+ choices=[i.value.name for i in WeightType],
429
+ label="Weights type",
430
+ multiselect=False,
431
+ value="Original",
432
+ interactive=True,
433
+ )
434
+ base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
435
+ commit_textbox = gr.Textbox(label="Commits")
436
+
437
+ submit_button = gr.Button("Submit Eval")
438
+ submission_result = gr.Markdown()
439
+ submit_button.click(
440
+ add_new_submit,
441
+ [
442
+ model_name_textbox,
443
+ base_model_name_textbox,
444
+ revision_name_textbox,
445
+ precision,
446
+ weight_type,
447
+ json_str,
448
+ commit_textbox,
449
+ ],
450
+ submission_result,
451
+ )
452
 
453
  # Backend status indicator
454
  backend_status = gr.HTML(
src/assets/css/custom.css CHANGED
@@ -14,7 +14,7 @@
14
  font-size: 16px !important;
15
  }
16
 
17
- #citation-button > label > button {
18
  margin: 6px;
19
  transform: scale(1.3);
20
  }
@@ -27,7 +27,7 @@
27
  margin-top: 15px
28
  }
29
 
30
- #search-bar-table-box > div:first-child {
31
  background: none;
32
  border: none;
33
  }
@@ -60,36 +60,45 @@
60
  #scale-logo .download {
61
  display: none;
62
  }
63
- #filter_type{
 
64
  border: 0;
65
  padding-left: 0;
66
  padding-top: 0;
67
  }
 
68
  #filter_type label {
69
  display: flex;
70
  }
71
- #filter_type label > span{
 
72
  margin-top: var(--spacing-lg);
73
  margin-right: 0.5em;
74
  }
75
- #filter_type label > .wrap{
 
76
  width: 103px;
77
  }
78
- #filter_type label > .wrap .wrap-inner{
 
79
  padding: 2px;
80
  }
81
- #filter_type label > .wrap .wrap-inner input{
 
82
  width: 1px
83
  }
84
- #filter-columns-type{
85
- border:0;
86
- padding:0.5;
 
87
  }
88
- #filter-columns-size{
89
- border:0;
90
- padding:0.5;
 
91
  }
92
- #box-filter > .form{
 
93
  border: 0
94
  }
95
 
@@ -104,4 +113,4 @@
104
  white-space: nowrap !important;
105
  overflow: hidden !important;
106
  text-overflow: ellipsis !important;
107
- }
 
14
  font-size: 16px !important;
15
  }
16
 
17
+ #citation-button>label>button {
18
  margin: 6px;
19
  transform: scale(1.3);
20
  }
 
27
  margin-top: 15px
28
  }
29
 
30
+ #search-bar-table-box>div:first-child {
31
  background: none;
32
  border: none;
33
  }
 
60
  #scale-logo .download {
61
  display: none;
62
  }
63
+
64
+ #filter_type {
65
  border: 0;
66
  padding-left: 0;
67
  padding-top: 0;
68
  }
69
+
70
  #filter_type label {
71
  display: flex;
72
  }
73
+
74
+ #filter_type label>span {
75
  margin-top: var(--spacing-lg);
76
  margin-right: 0.5em;
77
  }
78
+
79
+ #filter_type label>.wrap {
80
  width: 103px;
81
  }
82
+
83
+ #filter_type label>.wrap .wrap-inner {
84
  padding: 2px;
85
  }
86
+
87
+ #filter_type label>.wrap .wrap-inner input {
88
  width: 1px
89
  }
90
+
91
+ #filter-columns-type {
92
+ border: 0;
93
+ padding: 0.5;
94
  }
95
+
96
+ #filter-columns-size {
97
+ border: 0;
98
+ padding: 0.5;
99
  }
100
+
101
+ #box-filter>.form {
102
  border: 0
103
  }
104
 
 
113
  white-space: nowrap !important;
114
  overflow: hidden !important;
115
  text-overflow: ellipsis !important;
116
+ }
src/backend/routes/hf.py CHANGED
@@ -95,7 +95,7 @@ async def upload_file_content_handler(
95
 
96
  @router.post("/community/submit/")
97
  async def community_submit(
98
- params: Annotated[CommunitySubmit_Params, Depends()],
99
  ) -> ResponseData[UploadFileContent_RespData]:
100
  """Submit a new evaluation request to the Hugging Face repository."""
101
  file_obj = io.BytesIO(params.content.encode("utf-8"))
 
95
 
96
  @router.post("/community/submit/")
97
  async def community_submit(
98
+ params: CommunitySubmit_Params,
99
  ) -> ResponseData[UploadFileContent_RespData]:
100
  """Submit a new evaluation request to the Hugging Face repository."""
101
  file_obj = io.BytesIO(params.content.encode("utf-8"))
src/display/utils.py CHANGED
@@ -153,6 +153,13 @@ class WeightType(Enum):
153
  class Precision(Enum):
154
  float16 = ModelDetails(name="float16")
155
  bfloat16 = ModelDetails(name="bfloat16")
 
 
 
 
 
 
 
156
  Unknown = ModelDetails(name="?")
157
 
158
  @classmethod
@@ -161,6 +168,20 @@ class Precision(Enum):
161
  return Precision.float16
162
  if precision in ["torch.bfloat16", "bfloat16"]:
163
  return Precision.bfloat16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  return Precision.Unknown
165
 
166
 
 
153
  class Precision(Enum):
154
  float16 = ModelDetails(name="float16")
155
  bfloat16 = ModelDetails(name="bfloat16")
156
+ float32 = ModelDetails(name="float32")
157
+ float64 = ModelDetails(name="float64")
158
+ int8 = ModelDetails(name="int8")
159
+ uint8 = ModelDetails(name="uint8")
160
+ int16 = ModelDetails(name="int16")
161
+ int32 = ModelDetails(name="int32")
162
+ int64 = ModelDetails(name="int64")
163
  Unknown = ModelDetails(name="?")
164
 
165
  @classmethod
 
168
  return Precision.float16
169
  if precision in ["torch.bfloat16", "bfloat16"]:
170
  return Precision.bfloat16
171
+ if precision in ["torch.float32", "float32"]:
172
+ return Precision.float32
173
+ if precision in ["torch.float64", "float64"]:
174
+ return Precision.float64
175
+ if precision in ["torch.int8", "int8"]:
176
+ return Precision.int8
177
+ if precision in ["torch.uint8", "uint8"]:
178
+ return Precision.uint8
179
+ if precision in ["torch.int16", "int16"]:
180
+ return Precision.int16
181
+ if precision in ["torch.int32", "int32"]:
182
+ return Precision.int32
183
+ if precision in ["torch.int64", "int64"]:
184
+ return Precision.int64
185
  return Precision.Unknown
186
 
187
 
src/submission/submit.py CHANGED
@@ -2,6 +2,8 @@ import json
2
  import os
3
  import sys
4
  from datetime import datetime, timezone
 
 
5
 
6
  from src.display.formatting import styled_error, styled_message, styled_warning
7
  from src.envs import API, settings
@@ -20,6 +22,93 @@ else:
20
  REQUESTED_MODELS = None
21
  USERS_TO_SUBMISSION_DATES = None
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def add_new_eval(
25
  model: str,
 
2
  import os
3
  import sys
4
  from datetime import datetime, timezone
5
+ import requests
6
+ import json
7
 
8
  from src.display.formatting import styled_error, styled_message, styled_warning
9
  from src.envs import API, settings
 
22
  REQUESTED_MODELS = None
23
  USERS_TO_SUBMISSION_DATES = None
24
 
25
+ def add_new_submit(
26
+ model: str,
27
+ base_model: str,
28
+ revision: str,
29
+ precision: str,
30
+ weight_type: str,
31
+ json_str: str,
32
+ commit_message: str
33
+ ):
34
+ global REQUESTED_MODELS
35
+ global USERS_TO_SUBMISSION_DATES
36
+ if not REQUESTED_MODELS:
37
+ REQUESTED_MODELS, USERS_TO_SUBMISSION_DATES = already_submitted_models(settings.EVAL_REQUESTS_PATH)
38
+
39
+ user_name = ""
40
+ model_path = model
41
+ if "/" in model:
42
+ user_name = model.split("/")[0]
43
+ model_path = model.split("/")[1]
44
+
45
+ precision = precision.split(" ")[0]
46
+ # Does the model actually exist?
47
+ if revision == "":
48
+ revision = "main"
49
+
50
+ # Is the model on the hub?
51
+ if weight_type in ["Delta", "Adapter"]:
52
+ base_model_on_hub, error, _ = is_model_on_hub(
53
+ model_name=base_model, revision=revision, token=settings.TOKEN, test_tokenizer=True
54
+ )
55
+ if not base_model_on_hub:
56
+ return styled_error(f'Base model "{base_model}" {error}')
57
+
58
+ if not weight_type == "Adapter":
59
+ model_on_hub, error, _ = is_model_on_hub(
60
+ model_name=model, revision=revision, token=settings.TOKEN, test_tokenizer=True
61
+ )
62
+ if not model_on_hub:
63
+ return styled_error(f'Model "{model}" {error}')
64
+
65
+ # Is the model info correctly filled?
66
+ try:
67
+ model_info = API.model_info(repo_id=model, revision=revision)
68
+ except Exception:
69
+ return styled_error("Could not get your model information. Please fill it up properly.")
70
+
71
+ # Were the model card and license filled?
72
+ try:
73
+ license = model_info.cardData["license"]
74
+ except Exception:
75
+ return styled_error("Please select a license for your model")
76
+
77
+ request_json = {
78
+ "username": user_name,
79
+ "model_id": model,
80
+ "model_sha": revision,
81
+ "model_dtype": precision,
82
+ "content": json_str,
83
+ "weight_type": weight_type,
84
+ "commit_message":commit_message
85
+ }
86
+
87
+ # Check for duplicate submission
88
+ if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
89
+ return styled_warning("This model has been already submitted.")
90
+
91
+ try:
92
+ response = requests.post(
93
+ url=f"http://localhost:{settings.BACKEND_PORT}/api/v1/hf/community/submit/",
94
+ json=request_json, # 使用 json 参数发送 JSON body
95
+ headers={"Content-Type": "application/json"}
96
+ )
97
+ print("response: ", response) #print response content for debugging
98
+ if response.status_code == 200:
99
+ data = response.json()
100
+ print("returned data: ", data)
101
+ if data.get("code") == 0:
102
+ return styled_message(
103
+ "Your request has been submitted to the evaluation queue!\nPlease wait for the model to show in the PENDING list."
104
+ )
105
+ return styled_error(
106
+ "Submission unsuccessful."
107
+ )
108
+ except Exception:
109
+ return styled_error(
110
+ "Submission unsuccessful."
111
+ )
112
 
113
  def add_new_eval(
114
  model: str,