Spaces:
Running
Running
from enum import Enum | |
import gradio as gr | |
import pandas as pd | |
from chain_data import sync_metagraph, COMMITMENTS, UIDS_BY_HOTKEY, metagraph | |
from src import Key | |
from wandb_data import get_current_runs, Run, BLACKLISTED_HOTKEYS, BLACKLISTED_COLDKEYS, DUPLICATE_SUBMISSIONS | |
class SubmissionStatus(Enum): | |
BLACKLISTED = ("Blacklisted", "gray") | |
DUPLICATE = ("Duplicate", "gray") | |
PENDING = ("Pending", "orange") | |
DONE = ("Done", "springgreen") | |
INVALID = ("Invalid", "red") | |
def get_status(run: Run, hotkey: Key, coldkey: Key, block: int, revision: str) -> "SubmissionStatus": | |
if hotkey in BLACKLISTED_HOTKEYS or coldkey in BLACKLISTED_COLDKEYS: | |
return SubmissionStatus.BLACKLISTED | |
if any( | |
submission.hotkey == hotkey and submission.revision == revision | |
for submission in DUPLICATE_SUBMISSIONS | |
): | |
return SubmissionStatus.DUPLICATE | |
if hotkey in run.submissions and block > run.submissions[hotkey].info.block and hotkey not in run.invalid_submissions: | |
return SubmissionStatus.PENDING | |
if hotkey in run.submissions: | |
return SubmissionStatus.DONE | |
if hotkey in run.invalid_submissions: | |
return SubmissionStatus.INVALID | |
return SubmissionStatus.PENDING | |
DROPDOWN_OPTIONS = [status.value[0] for status in SubmissionStatus] | |
def create_submissions(submission_filters: list[str]) -> gr.Dataframe: | |
data: list[list] = [] | |
sync_metagraph() | |
runs = sorted(get_current_runs(), key=lambda run: run.uid) | |
for hotkey, commitment in COMMITMENTS.items(): | |
coldkey = metagraph.nodes[hotkey].coldkey | |
row = [ | |
UIDS_BY_HOTKEY[hotkey], | |
f"[{'/'.join(commitment.get_repo_link().split('/')[-2:])}]({commitment.get_repo_link()})", | |
f"[{commitment.block}](https://taostats.io/block/{commitment.block}/extrinsics)", | |
f"[{commitment.revision}]({commitment.get_repo_link()}/commit/{commitment.revision})", | |
f"[{hotkey[:6]}...](https://taostats.io/hotkey/{hotkey})", | |
f"[{coldkey[:6]}...](https://taostats.io/coldkey/{coldkey})", | |
commitment.contest.name, | |
] | |
has_data = False | |
for run in runs: | |
status = SubmissionStatus.get_status(run, hotkey, coldkey, commitment.block, commitment.revision) | |
if status.value[0] in submission_filters: | |
row.append(f"<span style='color: {status.value[1]}'>{status.value[0]}</span>") | |
has_data = True | |
else: | |
row.append("") | |
if not has_data: | |
continue | |
data.append(row) | |
data.sort(key=lambda x: int(x[2].split('[')[1].split(']')[0]), reverse=True) | |
columns = ["UID", "Model", "Block", "Revision", "Hotkey", "Coldkey", "Contest"] | |
datatype = ["number", "markdown", "markdown", "markdown", "markdown", "markdown", "markdown"] | |
for run in runs: | |
columns.append(f"{run.uid}") | |
datatype.append("markdown") | |
return gr.Dataframe( | |
pd.DataFrame(data, columns=columns), | |
datatype=datatype, | |
interactive=False, | |
max_height=800, | |
) | |