import pandas as pd | |
from .dataset import get_leaderboard_df, save_leaderboard_df | |
from .evaluation import evaluate_model | |
def submit_model(model_name: str, model_url: str): | |
if not model_name.strip(): | |
raise ValueError("Model name cannot be empty.") | |
if not model_url.strip(): | |
raise ValueError("Model URL cannot be empty.") | |
# 現在のリーダーボードを取得 | |
df = get_leaderboard_df() | |
# 新規評価 | |
score = evaluate_model(model_url) | |
# 新規行追加 | |
new_entry = {"Model Name": model_name.strip(), "Score (relative_error_loss)": score} | |
df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True) | |
# スコアが小さいほど良いと仮定し、昇順ソート&Rank再計算 | |
df = df.sort_values(by="Score (relative_error_loss)", ascending=True).reset_index(drop=True) | |
df["Rank"] = range(1, len(df) + 1) | |
# データセットをHugging Face Hubに反映 | |
save_leaderboard_df(df) | |
return df | |