Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import wandb | |
import time | |
from datetime import datetime | |
def get_all_competition_summary(api, projects): | |
number_of_competitions = 0 | |
number_of_runs = 0 | |
for project in projects: | |
entity = projects[project]["entity"] | |
project_name = projects[project]["project"] | |
runs = api.runs(f"{entity}/{project_name}") | |
number_of_competitions += 1 | |
number_of_runs += len(runs) | |
return number_of_competitions,number_of_runs | |
def fetch_competition_summary(api, projects, selected_project): | |
data = [] | |
entity = projects[selected_project]["entity"] | |
project = projects[selected_project]["project"] | |
runs = api.runs(f"{entity}/{project}") | |
for run in runs: | |
try: | |
summary = run.summary | |
if summary.get("validator_hotkey") and summary.get("winning_hotkey"): | |
data.append({ | |
"ID": run.id, | |
"Validator ID": summary.get("validator_hotkey"), | |
"Winning Hotkey": summary.get("winning_hotkey"), | |
"Run Time (s)": summary.get("run_time_s"), | |
"Created At": run.created_at, | |
}) | |
except Exception as e: | |
st.write(f"Error processing run {run.id}: {str(e)}") | |
df = pd.DataFrame(data) | |
if not df.empty: | |
df['Created At'] = pd.to_datetime(df['Created At']) | |
df = df.sort_values(by="Created At", ascending=False) | |
return df | |
def fetch_models_evaluation(api, projects, selected_project): | |
data = [] | |
entity = projects[selected_project]["entity"] | |
project = projects[selected_project]["project"] | |
runs = api.runs(f"{entity}/{project}") | |
for run in runs: | |
try: | |
summary = run.summary | |
if summary.get("score") is not None: # Assuming runs with score are model evaluations | |
data.append({ | |
"Created At": run.created_at, | |
"Miner hotkey": summary.get("miner_hotkey", "N/A"), | |
"F1-beta": summary.get("fbeta"), | |
"Accuracy": summary.get("accuracy"), | |
"Recall": summary.get("recall"), | |
"Precision": summary.get("precision"), | |
"Tested entries": summary.get("tested_entries"), | |
"ROC AUC": summary.get("roc_auc"), | |
"Confusion Matrix": summary.get("confusion_matrix"), | |
"Score": summary.get("score"), | |
#TODO link to huggingface model | |
}) | |
except Exception as e: | |
st.write(f"Error processing run {run.id}: {str(e)}") | |
df = pd.DataFrame(data) | |
if not df.empty: | |
df['Created At'] = pd.to_datetime(df['Created At']) | |
df = df.sort_values(by="Created At", ascending=False) | |
return df | |
def competition_summary_table(number_of_competitions, number_of_runs, last_updated): | |
return f""" | |
<div class="table-container"> | |
<table class="summary-table"> | |
<tr> | |
<th>Number of competitions</th> | |
<th>Number of models run</th> | |
<th>Last updated</th> | |
</tr> | |
<tr> | |
<td>{number_of_competitions}</td> | |
<td>{number_of_runs}</td> | |
<td>{last_updated}</td> | |
</tr> | |
</table> | |
</div> | |
""" | |
def highlight_score_column(s): | |
""" | |
Highlight the 'Score' column with a custom background color. | |
""" | |
return ['background-color: yellow' if s.name == 'Score' else '' for _ in s] | |