Spaces:
Running
Running
yangzhitao
commited on
Commit
·
852f90d
1
Parent(s):
77ae007
feat: enhance submission functionality by adding new submit method and updating file handling in app.py
Browse files- app.py +39 -39
- src/__init__.py +0 -0
- src/backend/__init__.py +0 -0
- src/backend/routes/__init__.py +0 -0
- src/display/__init__.py +0 -0
- src/leaderboard/__init__.py +0 -0
- src/prepare.py +1 -1
- src/submission/__init__.py +0 -0
- src/submission/submit.py +14 -22
app.py
CHANGED
|
@@ -38,7 +38,7 @@ from src.display.utils import (
|
|
| 38 |
from src.envs import API, settings
|
| 39 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 40 |
from src.prepare import prepare_space
|
| 41 |
-
from src.submission.submit import
|
| 42 |
|
| 43 |
prepare_space()
|
| 44 |
BENCHMARKS = get_benchmarks()
|
|
@@ -387,9 +387,10 @@ def main():
|
|
| 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,
|
| 393 |
json_data = json.load(f)
|
| 394 |
# 将 JSON 对象转换为格式化的字符串
|
| 395 |
json_str = json.dumps(json_data, indent=2, ensure_ascii=False)
|
|
@@ -415,7 +416,6 @@ def main():
|
|
| 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],
|
|
@@ -434,43 +434,43 @@ def main():
|
|
| 434 |
base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
|
| 435 |
commit_textbox = gr.Textbox(label="Commits")
|
| 436 |
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
|
| 475 |
with gr.Row():
|
| 476 |
with gr.Accordion("📙 Citation", open=False):
|
|
|
|
| 38 |
from src.envs import API, settings
|
| 39 |
from src.populate import get_evaluation_queue_df, get_leaderboard_df
|
| 40 |
from src.prepare import prepare_space
|
| 41 |
+
from src.submission.submit import add_new_submit
|
| 42 |
|
| 43 |
prepare_space()
|
| 44 |
BENCHMARKS = get_benchmarks()
|
|
|
|
| 387 |
return ""
|
| 388 |
try:
|
| 389 |
import json
|
| 390 |
+
|
| 391 |
# file 是文件路径字符串(当 type="filepath" 时)
|
| 392 |
file_path = file if isinstance(file, str) else file.name
|
| 393 |
+
with open(file_path, encoding='utf-8') as f:
|
| 394 |
json_data = json.load(f)
|
| 395 |
# 将 JSON 对象转换为格式化的字符串
|
| 396 |
json_str = json.dumps(json_data, indent=2, ensure_ascii=False)
|
|
|
|
| 416 |
outputs=json_str,
|
| 417 |
)
|
| 418 |
|
|
|
|
| 419 |
with gr.Column():
|
| 420 |
precision = gr.Dropdown(
|
| 421 |
choices=[i.value.name for i in Precision if i != Precision.Unknown],
|
|
|
|
| 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(
|
| 455 |
+
value=get_backend_status_undefined_html(),
|
| 456 |
+
elem_id="backend-status-container",
|
| 457 |
+
)
|
| 458 |
+
# trigger button to bind the click event
|
| 459 |
+
status_trigger = gr.Button(elem_id="backend-status-trigger-btn", visible=False)
|
| 460 |
+
status_trigger.click(
|
| 461 |
+
fn=lambda: check_backend_health()[1],
|
| 462 |
+
inputs=None,
|
| 463 |
+
outputs=backend_status,
|
| 464 |
+
)
|
| 465 |
+
# load external JavaScript file
|
| 466 |
+
js_content = backend_status_js()
|
| 467 |
+
status_trigger_js_html = f'<script>{js_content}</script>'
|
| 468 |
+
gr.HTML(status_trigger_js_html, visible=False)
|
| 469 |
+
demo.load(
|
| 470 |
+
fn=lambda: check_backend_health()[1],
|
| 471 |
+
inputs=None,
|
| 472 |
+
outputs=backend_status,
|
| 473 |
+
)
|
| 474 |
|
| 475 |
with gr.Row():
|
| 476 |
with gr.Accordion("📙 Citation", open=False):
|
src/__init__.py
ADDED
|
File without changes
|
src/backend/__init__.py
ADDED
|
File without changes
|
src/backend/routes/__init__.py
ADDED
|
File without changes
|
src/display/__init__.py
ADDED
|
File without changes
|
src/leaderboard/__init__.py
ADDED
|
File without changes
|
src/prepare.py
CHANGED
|
@@ -45,7 +45,7 @@ def prepare_space():
|
|
| 45 |
repo_type="dataset",
|
| 46 |
tqdm_class=None,
|
| 47 |
etag_timeout=30,
|
| 48 |
-
|
| 49 |
token=settings.HF_TOKEN.get_secret_value(),
|
| 50 |
)
|
| 51 |
except Exception as e:
|
|
|
|
| 45 |
repo_type="dataset",
|
| 46 |
tqdm_class=None,
|
| 47 |
etag_timeout=30,
|
| 48 |
+
allow_patterns=["leaderboard/*.toml", "leaderboard/**/*.json"],
|
| 49 |
token=settings.HF_TOKEN.get_secret_value(),
|
| 50 |
)
|
| 51 |
except Exception as e:
|
src/submission/__init__.py
ADDED
|
File without changes
|
src/submission/submit.py
CHANGED
|
@@ -2,8 +2,8 @@ import json
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
-
|
| 6 |
-
import
|
| 7 |
|
| 8 |
from src.display.formatting import styled_error, styled_message, styled_warning
|
| 9 |
from src.envs import API, settings
|
|
@@ -22,14 +22,9 @@ else:
|
|
| 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
|
|
@@ -50,14 +45,14 @@ def add_new_submit(
|
|
| 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.
|
| 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.
|
| 61 |
)
|
| 62 |
if not model_on_hub:
|
| 63 |
return styled_error(f'Model "{model}" {error}')
|
|
@@ -79,22 +74,22 @@ def add_new_submit(
|
|
| 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)
|
| 98 |
if response.status_code == 200:
|
| 99 |
data = response.json()
|
| 100 |
print("returned data: ", data)
|
|
@@ -102,13 +97,10 @@ def add_new_submit(
|
|
| 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 |
-
|
| 111 |
-
)
|
| 112 |
|
| 113 |
def add_new_eval(
|
| 114 |
model: str,
|
|
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
+
|
| 6 |
+
import requests
|
| 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 |
+
|
| 26 |
def add_new_submit(
|
| 27 |
+
model: str, base_model: str, revision: str, precision: str, weight_type: str, json_str: str, commit_message: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
):
|
| 29 |
global REQUESTED_MODELS
|
| 30 |
global USERS_TO_SUBMISSION_DATES
|
|
|
|
| 45 |
# Is the model on the hub?
|
| 46 |
if weight_type in ["Delta", "Adapter"]:
|
| 47 |
base_model_on_hub, error, _ = is_model_on_hub(
|
| 48 |
+
model_name=base_model, revision=revision, token=settings.HF_TOKEN.get_secret_value(), test_tokenizer=True
|
| 49 |
)
|
| 50 |
if not base_model_on_hub:
|
| 51 |
return styled_error(f'Base model "{base_model}" {error}')
|
| 52 |
|
| 53 |
if not weight_type == "Adapter":
|
| 54 |
model_on_hub, error, _ = is_model_on_hub(
|
| 55 |
+
model_name=model, revision=revision, token=settings.HF_TOKEN.get_secret_value(), test_tokenizer=True
|
| 56 |
)
|
| 57 |
if not model_on_hub:
|
| 58 |
return styled_error(f'Model "{model}" {error}')
|
|
|
|
| 74 |
"model_id": model,
|
| 75 |
"model_sha": revision,
|
| 76 |
"model_dtype": precision,
|
| 77 |
+
"content": json_str,
|
| 78 |
"weight_type": weight_type,
|
| 79 |
+
"commit_message": commit_message,
|
| 80 |
}
|
| 81 |
|
| 82 |
# Check for duplicate submission
|
| 83 |
if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
| 84 |
return styled_warning("This model has been already submitted.")
|
| 85 |
+
|
| 86 |
try:
|
| 87 |
response = requests.post(
|
| 88 |
url=f"http://localhost:{settings.BACKEND_PORT}/api/v1/hf/community/submit/",
|
| 89 |
json=request_json, # 使用 json 参数发送 JSON body
|
| 90 |
+
headers={"Content-Type": "application/json"},
|
| 91 |
)
|
| 92 |
+
print("response: ", response) # print response content for debugging
|
| 93 |
if response.status_code == 200:
|
| 94 |
data = response.json()
|
| 95 |
print("returned data: ", data)
|
|
|
|
| 97 |
return styled_message(
|
| 98 |
"Your request has been submitted to the evaluation queue!\nPlease wait for the model to show in the PENDING list."
|
| 99 |
)
|
| 100 |
+
return styled_error("Submission unsuccessful.")
|
|
|
|
|
|
|
| 101 |
except Exception:
|
| 102 |
+
return styled_error("Submission unsuccessful.")
|
| 103 |
+
|
|
|
|
| 104 |
|
| 105 |
def add_new_eval(
|
| 106 |
model: str,
|