|
|
| import json |
| import os |
| from datetime import datetime |
|
|
| import pandas as pd |
| from huggingface_hub import HfApi |
|
|
| API = HfApi() |
|
|
| SUBMISSIONS_REPO = "isic-archive/ISIC2024_submissions" |
| RESULTS_REPO = "isic-archive/ISIC2024_results" |
|
|
| |
| HF_TOKEN = os.environ.get("ISIC2024_ACCESS_TOKEN") |
|
|
|
|
| def submit_prediction(model_name: str, predictions_file) -> str: |
| """Upload a submission to the submissions dataset.""" |
| timestamp = datetime.now().isoformat() |
| submission_id = f"{model_name}_{timestamp}".replace(" ", "_") |
|
|
| |
| API.upload_file( |
| path_or_fileobj=predictions_file.name, |
| path_in_repo=f"predictions/{submission_id}.jsonl", |
| repo_id=SUBMISSIONS_REPO, |
| repo_type="dataset", |
| token=HF_TOKEN, |
| ) |
|
|
| |
| metadata = { |
| "model_name": model_name, |
| "submitted_by": "user", |
| "submission_time": timestamp, |
| "predictions_file": f"predictions/{submission_id}.jsonl", |
| } |
| metadata_bytes = json.dumps(metadata).encode() |
| API.upload_file( |
| path_or_fileobj=metadata_bytes, |
| path_in_repo=f"metadata/{submission_id}.json", |
| repo_id=SUBMISSIONS_REPO, |
| repo_type="dataset", |
| token=HF_TOKEN, |
| ) |
|
|
| return f"Submitted! Your submission ID is `{submission_id}`. Results will appear on the leaderboard once evaluation is complete." |
|
|
|
|
| def load_results() -> pd.DataFrame: |
| """Load the latest results from the results dataset.""" |
| try: |
| from datasets import load_dataset |
| ds = load_dataset(RESULTS_REPO, token=HF_TOKEN) |
| df = ds["train"].to_pandas() |
| |
| df = df.sort_values("overall_score", ascending=False).reset_index(drop=True) |
| return df |
| except Exception: |
| return pd.DataFrame(columns=["model_name", "overall_score"]) |
|
|