File size: 1,667 Bytes
50e75cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import pathlib
from pathlib import Path
import tempfile
from typing import BinaryIO, Literal
import json
import pandas as pd
import gradio as gr
from datasets import load_dataset, Dataset
from huggingface_hub import upload_file, hf_hub_download
from gradio_leaderboard import ColumnFilter, Leaderboard, SelectColumns
from evaluation import evaluate_problem
from datetime import datetime
import os
from about import PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo
def read_boundary(filename):
local_path = hf_hub_download(
repo_id=submissions_repo,
repo_type="dataset",
filename=filename,
)
return local_path
def write_results(record, result):
record.update(result)
record['result_filename'] = record['submission_filename'].strip('.json') + '_results.json'
record['evaluated'] = True
if 'objectives' in record.keys():
record['objective'] = record.pop('objectives')
record['minimize_objective'] = True
with tempfile.NamedTemporaryFile(mode="w", suffix=".json", delete=False) as tmp:
json.dump(record, tmp, indent=2)
tmp.flush()
tmp_name = tmp.name
API.upload_file(
path_or_fileobj=tmp_name,
path_in_repo=record['result_filename'],
repo_id=results_repo,
repo_type="dataset",
commit_message=f"Add result data for {record['result_filename']}"
)
pathlib.Path(tmp_name).unlink()
return
def get_user(profile: gr.OAuthProfile | None) -> str:
if profile is None:
return "Please login to submit a boundary for evaluation."
return profile.username |