import json import os import pprint from datetime import datetime, timezone import click from colorama import Fore from huggingface_hub import HfApi, snapshot_download from src.envs import TOKEN, EVAL_REQUESTS_PATH, QUEUE_REPO def main(): api = HfApi() current_time = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") snapshot_download( repo_id=QUEUE_REPO, revision="main", local_dir=EVAL_REQUESTS_PATH, repo_type="dataset", token=TOKEN ) model_name = click.prompt("Enter model name") revision = click.prompt("Enter revision", default="main") status = click.prompt("Enter status", default="FINISHED") try: model_info = api.model_info(repo_id=model_name, revision=revision) except Exception as e: print(f"{Fore.RED}Could not find model info for {model_name} on the Hub\n{e}{Fore.RESET}") return 1 try: license = model_info.cardData["license"] except Exception: license = "?" eval_entry = { "model": model_name, "revision": revision, "status": status, "submitted_time": current_time, "likes": model_info.likes, "license": license, } user_name = "" model_path = model_name if "/" in model_name: user_name = model_name.split("/")[0] model_path = model_name.split("/")[1] pprint.pprint(eval_entry) if click.confirm("Do you want to continue? This request file will be pushed to the hub"): click.echo("continuing...") out_dir = f"{EVAL_REQUESTS_PATH}/{user_name}" os.makedirs(out_dir, exist_ok=True) out_path = f"{out_dir}/{model_path}_eval_request.json" with open(out_path, "w") as f: f.write(json.dumps(eval_entry)) api.upload_file( path_or_fileobj=out_path, path_in_repo=out_path.split(f"{EVAL_REQUESTS_PATH}/")[1], repo_id=QUEUE_REPO, repo_type="dataset", commit_message=f"Add {model_name} to eval queue", ) else: click.echo("aborting...") if __name__ == "__main__": main()