DashboardSafeScan / utils.py
bulubula's picture
config fetch
cc1b673
raw
history blame
3.44 kB
import streamlit as st
import pandas as pd
import wandb
import time
from datetime import datetime
import requests
def get_competition_id(CONFIG_URL):
"""
Get competition names from the config URL.
"""
competition_names = []
try:
config = requests.get(CONFIG_URL).json()
for competition in config:
competition_names.append(competition["competition_id"])
except Exception as e:
st.write(f"Error loading competition names: {str(e)}")
return competition_names
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({
"Created At": run.created_at,
"Validator ID": summary.get("validator_hotkey"),
"Winning Hotkey": summary.get("winning_hotkey"),
"Run Time (s)": summary.get("run_time_s"),
})
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
model_link = summary.get("hf_model_link", "")
if model_link:
# Create clickable link
model_link_html = f'<a href="{model_link}" target="_blank">Model Link</a>'
else:
model_link_html = "N/A"
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"),
"Model link": model_link_html,
"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 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]