Spaces:
Running
Running
Commit
·
1d0c560
1
Parent(s):
1290009
update
Browse files- app.py +1 -4
- src/submission/submit.py +16 -134
app.py
CHANGED
|
@@ -37,9 +37,6 @@ from src.envs import API, EVAL_REQUESTS_PATH, EVAL_RESULTS_PATH, DYNAMIC_INFO_RE
|
|
| 37 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df, get_leaderboard_df_quota
|
| 38 |
from src.submission.submit import (
|
| 39 |
add_new_eval,
|
| 40 |
-
submit_model_info,
|
| 41 |
-
submit_api_info,
|
| 42 |
-
submit_inference_info,
|
| 43 |
submit_eval_complete
|
| 44 |
)
|
| 45 |
from src.scripts.update_all_request_files import update_dynamic_files
|
|
@@ -465,7 +462,7 @@ with demo:
|
|
| 465 |
|
| 466 |
# 4. Submit Eval 按钮
|
| 467 |
submit_btn = gr.Button("Submit Eval")
|
| 468 |
-
submit_output = gr.
|
| 469 |
|
| 470 |
# 绑定事件
|
| 471 |
submit_btn.click(
|
|
|
|
| 37 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df, get_leaderboard_df_quota
|
| 38 |
from src.submission.submit import (
|
| 39 |
add_new_eval,
|
|
|
|
|
|
|
|
|
|
| 40 |
submit_eval_complete
|
| 41 |
)
|
| 42 |
from src.scripts.update_all_request_files import update_dynamic_files
|
|
|
|
| 462 |
|
| 463 |
# 4. Submit Eval 按钮
|
| 464 |
submit_btn = gr.Button("Submit Eval")
|
| 465 |
+
submit_output = gr.HTML(label="", visible=True)
|
| 466 |
|
| 467 |
# 绑定事件
|
| 468 |
submit_btn.click(
|
src/submission/submit.py
CHANGED
|
@@ -16,94 +16,6 @@ from src.submission.check_validity import (
|
|
| 16 |
REQUESTED_MODELS = None
|
| 17 |
USERS_TO_SUBMISSION_DATES = None
|
| 18 |
|
| 19 |
-
def submit_model_info(
|
| 20 |
-
model_name: str,
|
| 21 |
-
revision_commit: str
|
| 22 |
-
):
|
| 23 |
-
"""
|
| 24 |
-
提交模型信息 - 对应页面上的 "Submit your modelinfos here!" 部分
|
| 25 |
-
"""
|
| 26 |
-
if not model_name or not model_name.strip():
|
| 27 |
-
return styled_error("请输入模型名称")
|
| 28 |
-
|
| 29 |
-
if not revision_commit or not revision_commit.strip():
|
| 30 |
-
revision_commit = "main"
|
| 31 |
-
|
| 32 |
-
# 验证模型名称格式
|
| 33 |
-
if "/" not in model_name:
|
| 34 |
-
return styled_error("模型名称格式不正确,请使用 '用户名/模型名' 格式")
|
| 35 |
-
|
| 36 |
-
# 检查模型是否存在于Hugging Face Hub
|
| 37 |
-
try:
|
| 38 |
-
model_info = API.model_info(repo_id=model_name, revision=revision_commit)
|
| 39 |
-
return styled_message(f"模型信息验证成功!模型: {model_name}, 版本: {revision_commit}")
|
| 40 |
-
except Exception as e:
|
| 41 |
-
return styled_error(f"无法找到模型 {model_name},请检查模型名称和版本是否正确")
|
| 42 |
-
|
| 43 |
-
def submit_api_info(
|
| 44 |
-
model_api_url: str,
|
| 45 |
-
model_api_key: str,
|
| 46 |
-
online_api_model_name: str
|
| 47 |
-
):
|
| 48 |
-
"""
|
| 49 |
-
提交API信息 - 对应页面上的 "Submit your API infos here! (API only)" 部分
|
| 50 |
-
"""
|
| 51 |
-
if not model_api_url or not model_api_url.strip():
|
| 52 |
-
return styled_error("请输入模型在线API URL")
|
| 53 |
-
|
| 54 |
-
if not model_api_key or not model_api_key.strip():
|
| 55 |
-
return styled_error("请输入模型在线API密钥")
|
| 56 |
-
|
| 57 |
-
if not online_api_model_name or not online_api_model_name.strip():
|
| 58 |
-
return styled_error("请输入在线API模型名称")
|
| 59 |
-
|
| 60 |
-
# 验证URL格式
|
| 61 |
-
if not model_api_url.startswith(('http://', 'https://')):
|
| 62 |
-
return styled_error("API URL格式不正确,请以 http:// 或 https:// 开头")
|
| 63 |
-
|
| 64 |
-
return styled_message(f"API信息验证成功!URL: {model_api_url}, 模型名: {online_api_model_name}")
|
| 65 |
-
|
| 66 |
-
def submit_inference_info(
|
| 67 |
-
runsh_file,
|
| 68 |
-
adapter_file
|
| 69 |
-
):
|
| 70 |
-
"""
|
| 71 |
-
提交推理信息 - 对应页面上的 "Submit your inference infos here! (inference only)" 部分
|
| 72 |
-
"""
|
| 73 |
-
if not runsh_file:
|
| 74 |
-
return styled_error("请上传 run.sh 文件")
|
| 75 |
-
|
| 76 |
-
if not adapter_file:
|
| 77 |
-
return styled_error("请上传 model_adapter.py 文件")
|
| 78 |
-
|
| 79 |
-
# 检查文件大小
|
| 80 |
-
max_size = 5 * 1024 * 1024 # 5MB
|
| 81 |
-
if os.path.getsize(runsh_file.name) > max_size:
|
| 82 |
-
return styled_error("run.sh 文件大小不能超过 5MB")
|
| 83 |
-
|
| 84 |
-
if os.path.getsize(adapter_file.name) > max_size:
|
| 85 |
-
return styled_error("model_adapter.py 文件大小不能超过 5MB")
|
| 86 |
-
|
| 87 |
-
# 验证文件内容
|
| 88 |
-
try:
|
| 89 |
-
with open(runsh_file.name, "r") as f:
|
| 90 |
-
runsh_content = f.read()
|
| 91 |
-
|
| 92 |
-
with open(adapter_file.name, "r") as f:
|
| 93 |
-
adapter_content = f.read()
|
| 94 |
-
|
| 95 |
-
# 检查run.sh是否包含必要的脚本内容
|
| 96 |
-
if "python" not in runsh_content.lower():
|
| 97 |
-
return styled_warning("run.sh 文件可能不包含正确的Python执行脚本")
|
| 98 |
-
|
| 99 |
-
# 检查adapter文件是否包含必要的类定义
|
| 100 |
-
if "class" not in adapter_content and "def" not in adapter_content:
|
| 101 |
-
return styled_warning("model_adapter.py 文件可能不包含正确的类或函数定义")
|
| 102 |
-
|
| 103 |
-
return styled_message("推理文件验证成功!run.sh 和 model_adapter.py 文件已准备就绪")
|
| 104 |
-
|
| 105 |
-
except Exception as e:
|
| 106 |
-
return styled_error(f"文件读取失败: {str(e)}")
|
| 107 |
|
| 108 |
def submit_eval_complete(
|
| 109 |
model_name: str,
|
|
@@ -115,48 +27,48 @@ def submit_eval_complete(
|
|
| 115 |
adapter_file
|
| 116 |
):
|
| 117 |
"""
|
| 118 |
-
|
| 119 |
"""
|
| 120 |
-
#
|
| 121 |
if not model_name or not model_name.strip():
|
| 122 |
-
return styled_error("
|
| 123 |
|
| 124 |
if not revision_commit or not revision_commit.strip():
|
| 125 |
revision_commit = "main"
|
| 126 |
|
| 127 |
-
#
|
| 128 |
if model_api_url and model_api_key and online_api_model_name:
|
| 129 |
if not model_api_url.startswith(('http://', 'https://')):
|
| 130 |
-
return styled_error("API URL
|
| 131 |
|
| 132 |
-
#
|
| 133 |
if runsh_file and adapter_file:
|
| 134 |
max_size = 5 * 1024 * 1024 # 5MB
|
| 135 |
if os.path.getsize(runsh_file.name) > max_size:
|
| 136 |
-
return styled_error("run.sh
|
| 137 |
|
| 138 |
if os.path.getsize(adapter_file.name) > max_size:
|
| 139 |
-
return styled_error("model_adapter.py
|
| 140 |
|
| 141 |
-
#
|
| 142 |
try:
|
| 143 |
result = add_new_eval(
|
| 144 |
model=model_name,
|
| 145 |
model_api_url=model_api_url or "",
|
| 146 |
model_api_key=model_api_key or "",
|
| 147 |
model_api_name=online_api_model_name or "",
|
| 148 |
-
base_model="", #
|
| 149 |
revision=revision_commit,
|
| 150 |
-
precision="float16", #
|
| 151 |
private="false",
|
| 152 |
-
weight_type="Original", #
|
| 153 |
-
model_type="", #
|
| 154 |
runsh=runsh_file,
|
| 155 |
adapter=adapter_file
|
| 156 |
)
|
| 157 |
return result
|
| 158 |
except Exception as e:
|
| 159 |
-
return styled_error(f"
|
| 160 |
|
| 161 |
def add_new_eval(
|
| 162 |
model: str,
|
|
@@ -199,26 +111,6 @@ def add_new_eval(
|
|
| 199 |
created_at = ""
|
| 200 |
# Is the model on the hub?
|
| 201 |
if len(model_api_url)==0:
|
| 202 |
-
#if weight_type in ["Delta", "Adapter"]:
|
| 203 |
-
# base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 204 |
-
# if not base_model_on_hub:
|
| 205 |
-
# return styled_error(f'Base model "{base_model}" {error}')
|
| 206 |
-
|
| 207 |
-
#if not weight_type == "Adapter":
|
| 208 |
-
# model_on_hub, error, model_config = is_model_on_hub(model_name=model, revision=revision, test_tokenizer=True)
|
| 209 |
-
# if not model_on_hub:
|
| 210 |
-
# return styled_error(f'Model "{model}" {error}')
|
| 211 |
-
# if model_config is not None:
|
| 212 |
-
# architectures = getattr(model_config, "architectures", None)
|
| 213 |
-
# if architectures:
|
| 214 |
-
# architecture = ";".join(architectures)
|
| 215 |
-
# downloads = getattr(model_config, 'downloads', 0)
|
| 216 |
-
# created_at = getattr(model_config, 'created_at', '')
|
| 217 |
-
#if not weight_type == "Adapter":
|
| 218 |
-
# model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 219 |
-
# if not model_on_hub:
|
| 220 |
-
# return styled_error(f'Model "{model}" {error}')
|
| 221 |
-
|
| 222 |
# Is the model info correctly filled?
|
| 223 |
try:
|
| 224 |
model_info = API.model_info(repo_id=model, revision=revision)
|
|
@@ -226,17 +118,9 @@ def add_new_eval(
|
|
| 226 |
return styled_error("Could not get your model information. Please fill it up properly.")
|
| 227 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
| 228 |
|
| 229 |
-
# Were the model card and license filled?
|
| 230 |
-
try:
|
| 231 |
-
license = model_info.cardData["license"]
|
| 232 |
-
except Exception:
|
| 233 |
-
return styled_error("Please select a license for your model")
|
| 234 |
-
|
| 235 |
modelcard_OK, error_msg = check_model_card(model)
|
| 236 |
if not modelcard_OK:
|
| 237 |
return styled_error(error_msg)
|
| 238 |
-
#tags = get_model_tags(model_card, model)
|
| 239 |
-
# TODO: tags
|
| 240 |
tags = []
|
| 241 |
|
| 242 |
likes = model_info.likes
|
|
@@ -252,9 +136,9 @@ def add_new_eval(
|
|
| 252 |
max_size = 5 * 1024 * 1024 # 5MB
|
| 253 |
if (runsh is not None) and (adapter is not None):
|
| 254 |
if os.path.getsize(runsh.name) > max_size:
|
| 255 |
-
return "
|
| 256 |
if os.path.getsize(adapter.name) > max_size:
|
| 257 |
-
return "
|
| 258 |
with open(runsh.name, "r") as f:
|
| 259 |
runsh = f.read()
|
| 260 |
with open(adapter.name, "r") as f:
|
|
@@ -275,9 +159,7 @@ def add_new_eval(
|
|
| 275 |
"status": "PENDING",
|
| 276 |
"submitted_time": current_time,
|
| 277 |
"model_type": model_type,
|
| 278 |
-
#"likes": model_info.likes,
|
| 279 |
"params": model_size,
|
| 280 |
-
#"license": license,
|
| 281 |
"private": False,
|
| 282 |
"runsh": runsh,
|
| 283 |
"adapter": adapter,
|
|
|
|
| 16 |
REQUESTED_MODELS = None
|
| 17 |
USERS_TO_SUBMISSION_DATES = None
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def submit_eval_complete(
|
| 21 |
model_name: str,
|
|
|
|
| 27 |
adapter_file
|
| 28 |
):
|
| 29 |
"""
|
| 30 |
+
Complete evaluation submission - integrates all three parts of information
|
| 31 |
"""
|
| 32 |
+
# Validate model information
|
| 33 |
if not model_name or not model_name.strip():
|
| 34 |
+
return styled_error("Please enter model name")
|
| 35 |
|
| 36 |
if not revision_commit or not revision_commit.strip():
|
| 37 |
revision_commit = "main"
|
| 38 |
|
| 39 |
+
# Validate API information (if provided)
|
| 40 |
if model_api_url and model_api_key and online_api_model_name:
|
| 41 |
if not model_api_url.startswith(('http://', 'https://')):
|
| 42 |
+
return styled_error("API URL format is incorrect, please start with http:// or https://")
|
| 43 |
|
| 44 |
+
# Validate inference files (if provided)
|
| 45 |
if runsh_file and adapter_file:
|
| 46 |
max_size = 5 * 1024 * 1024 # 5MB
|
| 47 |
if os.path.getsize(runsh_file.name) > max_size:
|
| 48 |
+
return styled_error("run.sh file size cannot exceed 5MB")
|
| 49 |
|
| 50 |
if os.path.getsize(adapter_file.name) > max_size:
|
| 51 |
+
return styled_error("model_adapter.py file size cannot exceed 5MB")
|
| 52 |
|
| 53 |
+
# Call the original add_new_eval function
|
| 54 |
try:
|
| 55 |
result = add_new_eval(
|
| 56 |
model=model_name,
|
| 57 |
model_api_url=model_api_url or "",
|
| 58 |
model_api_key=model_api_key or "",
|
| 59 |
model_api_name=online_api_model_name or "",
|
| 60 |
+
base_model="", # Can be set as needed
|
| 61 |
revision=revision_commit,
|
| 62 |
+
precision="float16", # Default precision
|
| 63 |
private="false",
|
| 64 |
+
weight_type="Original", # Default weight type
|
| 65 |
+
model_type="", # Can be set as needed
|
| 66 |
runsh=runsh_file,
|
| 67 |
adapter=adapter_file
|
| 68 |
)
|
| 69 |
return result
|
| 70 |
except Exception as e:
|
| 71 |
+
return styled_error(f"Submission failed: {str(e)}")
|
| 72 |
|
| 73 |
def add_new_eval(
|
| 74 |
model: str,
|
|
|
|
| 111 |
created_at = ""
|
| 112 |
# Is the model on the hub?
|
| 113 |
if len(model_api_url)==0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
# Is the model info correctly filled?
|
| 115 |
try:
|
| 116 |
model_info = API.model_info(repo_id=model, revision=revision)
|
|
|
|
| 118 |
return styled_error("Could not get your model information. Please fill it up properly.")
|
| 119 |
model_size = get_model_size(model_info=model_info, precision=precision)
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
modelcard_OK, error_msg = check_model_card(model)
|
| 122 |
if not modelcard_OK:
|
| 123 |
return styled_error(error_msg)
|
|
|
|
|
|
|
| 124 |
tags = []
|
| 125 |
|
| 126 |
likes = model_info.likes
|
|
|
|
| 136 |
max_size = 5 * 1024 * 1024 # 5MB
|
| 137 |
if (runsh is not None) and (adapter is not None):
|
| 138 |
if os.path.getsize(runsh.name) > max_size:
|
| 139 |
+
return "Error: File size cannot exceed 5MB!"
|
| 140 |
if os.path.getsize(adapter.name) > max_size:
|
| 141 |
+
return "Error: File size cannot exceed 5MB!"
|
| 142 |
with open(runsh.name, "r") as f:
|
| 143 |
runsh = f.read()
|
| 144 |
with open(adapter.name, "r") as f:
|
|
|
|
| 159 |
"status": "PENDING",
|
| 160 |
"submitted_time": current_time,
|
| 161 |
"model_type": model_type,
|
|
|
|
| 162 |
"params": model_size,
|
|
|
|
| 163 |
"private": False,
|
| 164 |
"runsh": runsh,
|
| 165 |
"adapter": adapter,
|