Spaces:
Sleeping
Sleeping
renw
Browse files
app.py
CHANGED
|
@@ -1,239 +1,158 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import wandb
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import os
|
| 5 |
-
import time
|
| 6 |
-
import datetime
|
| 7 |
-
from utils import fetch_competition_summary, fetch_models_evaluation, get_all_competition_summary,
|
| 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 |
-
if
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
st.
|
| 85 |
-
st.markdown("<
|
| 86 |
-
st.write("
|
| 87 |
-
|
| 88 |
-
#
|
| 89 |
-
st.
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
# Set the desired font size here (in pixels)
|
| 160 |
-
summary_font_size = 14 # You can adjust this value as needed
|
| 161 |
-
|
| 162 |
-
st.subheader("Dashboard summary information")
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# Display summary statistics in a table-like format
|
| 166 |
-
st.markdown(f"""
|
| 167 |
-
<div class="table-container">
|
| 168 |
-
<table class="summary-table">
|
| 169 |
-
<tr>
|
| 170 |
-
<th>Number of competitions</th>
|
| 171 |
-
<th>Number of models run</th>
|
| 172 |
-
<th>Last updated</th>
|
| 173 |
-
</tr>
|
| 174 |
-
<tr>
|
| 175 |
-
<td>{number_of_competitions}</td>
|
| 176 |
-
<td>{number_of_runs}</td>
|
| 177 |
-
<td>{last_updated}</td>
|
| 178 |
-
</tr>
|
| 179 |
-
</table>
|
| 180 |
-
</div>
|
| 181 |
-
""", unsafe_allow_html=True)
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
st.subheader("###")
|
| 186 |
-
st.markdown("<h2 style='text-align: center; font-size: 28px;'>Competitions</h2>", unsafe_allow_html=True)
|
| 187 |
-
st.write("#### Select a competition to view more details and rankings.")
|
| 188 |
-
|
| 189 |
-
# Create a header for the table
|
| 190 |
-
cols = st.columns([1, 3, 2, 2, 2, 1, 2])
|
| 191 |
-
cols[0].write("Index")
|
| 192 |
-
cols[1].write("Competition Name")
|
| 193 |
-
cols[2].write("Leader")
|
| 194 |
-
cols[3].write("Date")
|
| 195 |
-
cols[4].write("Hotkey")
|
| 196 |
-
cols[5].write("Days on Top")
|
| 197 |
-
|
| 198 |
-
for index, (competition, details) in enumerate(projects.items(), start=1):
|
| 199 |
-
leader_info = st.session_state.get("leader_info", {}).get(competition, {})
|
| 200 |
-
|
| 201 |
-
cols = st.columns([1, 3, 2, 2, 2, 1, 2])
|
| 202 |
-
cols[0].write(index)
|
| 203 |
-
if cols[1].button(competition):
|
| 204 |
-
st.session_state.selected_competition = competition
|
| 205 |
-
cols[2].write(leader_info.get("Username", "N/A"))
|
| 206 |
-
cols[3].write(leader_info.get("Date", "N/A"))
|
| 207 |
-
cols[4].write(leader_info.get("Hotkey", "N/A"))
|
| 208 |
-
cols[5].write(leader_info.get("Days on Top", "N/A"))
|
| 209 |
-
if st.session_state.selected_competition:
|
| 210 |
-
competition_name = st.session_state.selected_competition
|
| 211 |
-
competition_details = projects.get(competition_name, {})
|
| 212 |
-
description = competition_details.get("description", "No description available.")
|
| 213 |
-
|
| 214 |
-
st.subheader(f"Competition: {competition_name}")
|
| 215 |
-
st.write(description)
|
| 216 |
-
|
| 217 |
-
st.subheader("Competition Summary")
|
| 218 |
-
competition_summary_df = competition_summaries.get(competition_name, pd.DataFrame())
|
| 219 |
-
|
| 220 |
-
if not competition_summary_df.empty:
|
| 221 |
-
st.dataframe(competition_summary_df)
|
| 222 |
-
else:
|
| 223 |
-
st.warning("No competition summary data available.")
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
# TODO highlight score collumn
|
| 227 |
-
st.subheader("Models Evaluation")
|
| 228 |
-
models_evaluation_df = model_evaluations.get(competition_name, pd.DataFrame())
|
| 229 |
-
if not models_evaluation_df.empty:
|
| 230 |
-
st.dataframe(models_evaluation_df.style.apply(highlight_score_column, axis=0))
|
| 231 |
-
else:
|
| 232 |
-
st.warning("No models evaluation data available.")
|
| 233 |
-
else:
|
| 234 |
-
st.write("Please select a competition to view details.")
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
# Run the app
|
| 238 |
-
if __name__ == "__main__":
|
| 239 |
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import wandb
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import datetime
|
| 7 |
+
from utils import fetch_competition_summary, fetch_models_evaluation, get_all_competition_summary, update_leader_info
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
from cfg import *
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
st.set_page_config(layout="wide")
|
| 13 |
+
|
| 14 |
+
table_font_size = 16
|
| 15 |
+
st.markdown(TABLE_STYLE, unsafe_allow_html=True)
|
| 16 |
+
|
| 17 |
+
### WANDB
|
| 18 |
+
|
| 19 |
+
# Access the API key from the environment variable
|
| 20 |
+
wandb_api_key = os.getenv('WANDB_API_KEY')
|
| 21 |
+
|
| 22 |
+
# Log in to wandb using the API key
|
| 23 |
+
if wandb_api_key:
|
| 24 |
+
wandb.login(key=wandb_api_key)
|
| 25 |
+
# wandb.login()
|
| 26 |
+
else:
|
| 27 |
+
st.error("WANDB_API_KEY not found in environment variables.")
|
| 28 |
+
|
| 29 |
+
wandb_api = wandb.Api()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@st.cache_data()
|
| 34 |
+
def load_competition_data(last_update_time=None):
|
| 35 |
+
competition_summaries = {}
|
| 36 |
+
model_evaluations = {}
|
| 37 |
+
for competition in COMPETITIONS:
|
| 38 |
+
competition_summaries[competition] = fetch_competition_summary(wandb_api, COMPETITIONS, competition)
|
| 39 |
+
model_evaluations[competition] = fetch_models_evaluation(wandb_api, COMPETITIONS, competition)
|
| 40 |
+
|
| 41 |
+
last_update_time = time.time()
|
| 42 |
+
return competition_summaries, model_evaluations, last_update_time
|
| 43 |
+
|
| 44 |
+
# Streamlit app main function
|
| 45 |
+
def main():
|
| 46 |
+
st.markdown(HEADER, unsafe_allow_html=True)
|
| 47 |
+
|
| 48 |
+
if 'last_update_time' not in st.session_state:
|
| 49 |
+
st.session_state.last_update_time = None
|
| 50 |
+
if "leader_info" not in st.session_state:
|
| 51 |
+
st.session_state.leader_info = {}
|
| 52 |
+
if 'selected_competition' not in st.session_state:
|
| 53 |
+
st.session_state.selected_competition = None
|
| 54 |
+
|
| 55 |
+
if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > UPDATE_INTERVAL):
|
| 56 |
+
competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
|
| 57 |
+
|
| 58 |
+
for competition in COMPETITIONS:
|
| 59 |
+
if not competition_summaries[competition].empty:
|
| 60 |
+
# get all winning hotkeys and number of wins
|
| 61 |
+
winning_hotkeys = competition_summaries[competition]["Winning Hotkey"].value_counts()
|
| 62 |
+
|
| 63 |
+
# if not empty, get the best hotkey
|
| 64 |
+
if not winning_hotkeys.empty:
|
| 65 |
+
best_hotkey = winning_hotkeys.idxmax()
|
| 66 |
+
|
| 67 |
+
# get the best model with the winning hotkey
|
| 68 |
+
best_model = model_evaluations[competition][model_evaluations[competition]["Hotkey"] == best_hotkey].iloc[0]
|
| 69 |
+
st.session_state.leader_info[competition] = update_leader_info(st.session_state.leader_info, competition, best_model)
|
| 70 |
+
else:
|
| 71 |
+
st.session_state.leader_info[competition] = {
|
| 72 |
+
"Username": "N/A", "Model Name": "N/A", "Hotkey": "N/A",
|
| 73 |
+
"Date": "N/A", "UID": "N/A", "Days on Top": "N/A"
|
| 74 |
+
}
|
| 75 |
+
else:
|
| 76 |
+
competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
|
| 77 |
+
|
| 78 |
+
number_of_competitions, number_of_runs = get_all_competition_summary(wandb_api, COMPETITIONS)
|
| 79 |
+
last_updated = datetime.datetime.fromtimestamp(st.session_state.last_update_time).strftime('%Y-%m-%d %H:%M:%S')
|
| 80 |
+
|
| 81 |
+
# Set the desired font size here (in pixels)
|
| 82 |
+
summary_font_size = 14 # You can adjust this value as needed
|
| 83 |
+
|
| 84 |
+
st.subheader("###")
|
| 85 |
+
st.markdown("<h2 style='text-align: center; font-size: 28px;'>Competitions</h2>", unsafe_allow_html=True)
|
| 86 |
+
st.write("#### Select a competition to view more details and rankings.")
|
| 87 |
+
|
| 88 |
+
# Create a header for the table
|
| 89 |
+
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 90 |
+
headers = ["Index", "Competition Name", "Leader", "Model", "Date", "Hotkey", "Days on Top"]
|
| 91 |
+
for col, header in zip(cols, headers):
|
| 92 |
+
col.write(header)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
for index, (competition, details) in enumerate(COMPETITIONS.items(), start=1):
|
| 96 |
+
leader_info = st.session_state.get("leader_info", {}).get(competition, {})
|
| 97 |
+
|
| 98 |
+
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 99 |
+
cols[0].write(index)
|
| 100 |
+
|
| 101 |
+
if cols[1].button(competition):
|
| 102 |
+
st.session_state.selected_competition = competition
|
| 103 |
+
cols[2].write(leader_info.get("Username", "N/A"))
|
| 104 |
+
cols[3].write(leader_info.get("Model Name", "N/A"))
|
| 105 |
+
cols[4].write(leader_info.get("Date", "N/A"))
|
| 106 |
+
cols[5].write(leader_info.get("Hotkey", "N/A"))
|
| 107 |
+
cols[6].write(leader_info.get("Days on Top", "N/A"))
|
| 108 |
+
if st.session_state.selected_competition:
|
| 109 |
+
competition_name = st.session_state.selected_competition
|
| 110 |
+
competition_details = COMPETITIONS.get(competition_name, {})
|
| 111 |
+
description = competition_details.get("description", "No description available.")
|
| 112 |
+
|
| 113 |
+
st.subheader(f"Competition: {competition_name}")
|
| 114 |
+
st.write(description)
|
| 115 |
+
|
| 116 |
+
st.subheader("Competition Summary")
|
| 117 |
+
competition_summary_df = competition_summaries.get(competition_name, pd.DataFrame())
|
| 118 |
+
if not competition_summary_df.empty:
|
| 119 |
+
st.markdown('<div class="table-container">' + competition_summary_df.to_html(classes='dataframe', escape=False) + '</div>', unsafe_allow_html=True)
|
| 120 |
+
else:
|
| 121 |
+
st.warning("No competition summary data available.")
|
| 122 |
+
|
| 123 |
+
st.subheader("Models Evaluation")
|
| 124 |
+
models_evaluation_df = model_evaluations.get(competition_name, pd.DataFrame())
|
| 125 |
+
if not models_evaluation_df.empty:
|
| 126 |
+
st.markdown('<div class="table-container">' + models_evaluation_df.to_html(classes='dataframe', escape=False) + '</div>', unsafe_allow_html=True)
|
| 127 |
+
else:
|
| 128 |
+
st.warning("No models evaluation data available.")
|
| 129 |
+
else:
|
| 130 |
+
st.write("Please select a competition to view details.")
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
st.subheader("Summary information")
|
| 135 |
+
st.markdown(f"""
|
| 136 |
+
<div class="table-container">
|
| 137 |
+
<table class="summary-table">
|
| 138 |
+
<tr>
|
| 139 |
+
<th>Number of competitions</th>
|
| 140 |
+
<th>Number of models run</th>
|
| 141 |
+
<th>Last updated</th>
|
| 142 |
+
</tr>
|
| 143 |
+
<tr>
|
| 144 |
+
<td>{number_of_competitions}</td>
|
| 145 |
+
<td>{number_of_runs}</td>
|
| 146 |
+
<td>{last_updated}</td>
|
| 147 |
+
</tr>
|
| 148 |
+
</table>
|
| 149 |
+
</div>
|
| 150 |
+
""", unsafe_allow_html=True)
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
# Run the app
|
| 157 |
+
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
main()
|
cfg.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
UPDATE_INTERVAL = 2 * 60 # 20 minutes in seconds
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
COMPETITIONS = {
|
| 6 |
+
"Melanoma-1": {
|
| 7 |
+
"entity": "safe-scan-ai",
|
| 8 |
+
"project": "melanoma-1",
|
| 9 |
+
"description": "This is a testnet competition for melanoma detection."
|
| 10 |
+
},
|
| 11 |
+
"Melanoma-testnet": {
|
| 12 |
+
"entity": "safe-scan-ai",
|
| 13 |
+
"project": "melanoma-testnet",
|
| 14 |
+
"description": "This is a testnet competition for melanoma detection."
|
| 15 |
+
},
|
| 16 |
+
|
| 17 |
+
# Add more projects as needed
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
HEADER = """
|
| 23 |
+
<h1 style='text-align: center;'>Safe Scan competition dashboard</h1>
|
| 24 |
+
<a href='https://safe-scan.ai/'><img src='https://img.shields.io/badge/Website-Project-blue?logo=google-chrome' alt='Safe Scan website'></a>
|
| 25 |
+
<a href='https://github.com/safe-scan-ai/cancer-ai'><img src='https://img.shields.io/badge/GitHub-Repository-blue?logo=github' alt='GitHub'></a>
|
| 26 |
+
<a href='https://discord.com/invite/sFyJ35yQ'><img src='https://img.shields.io/badge/Discord-Community-blue?logo=discord' alt='Discord'></a>
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
TABLE_STYLE = """
|
| 33 |
+
<style>
|
| 34 |
+
.dataframe, .summary-table {
|
| 35 |
+
width: 100%;
|
| 36 |
+
border-collapse: collapse;
|
| 37 |
+
margin: 20px 0;
|
| 38 |
+
font-size: 16px;
|
| 39 |
+
min-width: 400px;
|
| 40 |
+
}
|
| 41 |
+
.dataframe th,
|
| 42 |
+
.dataframe td,
|
| 43 |
+
.summary-table th,
|
| 44 |
+
.summary-table td {
|
| 45 |
+
padding: 12px 15px;
|
| 46 |
+
border: 1px solid #CCCCCC;
|
| 47 |
+
text-align: left;
|
| 48 |
+
}
|
| 49 |
+
.dataframe thead th,
|
| 50 |
+
.summary-table th {
|
| 51 |
+
background-color: #333333;
|
| 52 |
+
color: #FFFFFF;
|
| 53 |
+
}
|
| 54 |
+
.dataframe tbody tr:nth-child(even),
|
| 55 |
+
.summary-table tr:nth-child(even) {
|
| 56 |
+
background-color: #F0F0F0;
|
| 57 |
+
}
|
| 58 |
+
.dataframe tbody tr:nth-child(odd),
|
| 59 |
+
.summary-table tr:nth-child(odd) {
|
| 60 |
+
background-color: #E0E0E0;
|
| 61 |
+
}
|
| 62 |
+
.dataframe tbody td,
|
| 63 |
+
.summary-table td {
|
| 64 |
+
color: #333333;
|
| 65 |
+
}
|
| 66 |
+
.dataframe tbody tr:hover,
|
| 67 |
+
.summary-table tr:hover {
|
| 68 |
+
background-color: #D1D1D1;
|
| 69 |
+
}
|
| 70 |
+
.table-container {
|
| 71 |
+
overflow-x: auto;
|
| 72 |
+
}
|
| 73 |
+
</style>
|
| 74 |
+
"""
|
utils.py
CHANGED
|
@@ -1,7 +1,32 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import wandb
|
| 4 |
-
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def get_all_competition_summary(api, projects):
|
|
@@ -29,10 +54,10 @@ def fetch_competition_summary(api, projects, selected_project):
|
|
| 29 |
for run in runs:
|
| 30 |
try:
|
| 31 |
summary = run.summary
|
| 32 |
-
if summary.get("
|
| 33 |
data.append({
|
| 34 |
"ID": run.id,
|
| 35 |
-
"Validator
|
| 36 |
"Winning Hotkey": summary.get("winning_hotkey"),
|
| 37 |
"Run Time (s)": summary.get("run_time_s"),
|
| 38 |
"Created At": run.created_at,
|
|
@@ -58,25 +83,18 @@ def fetch_models_evaluation(api, projects, selected_project):
|
|
| 58 |
for run in runs:
|
| 59 |
try:
|
| 60 |
summary = run.summary
|
| 61 |
-
if summary.get("
|
| 62 |
data.append({
|
| 63 |
"ID": run.id,
|
| 64 |
"Username": run.user.username,
|
| 65 |
-
"
|
|
|
|
| 66 |
"Score": summary.get("score"),
|
| 67 |
-
|
| 68 |
-
"F1-beta": summary.get("fbeta"),
|
| 69 |
"Accuracy": summary.get("accuracy"),
|
| 70 |
"Recall": summary.get("recall"),
|
| 71 |
-
"Precision": summary.get("precision"),
|
| 72 |
-
|
| 73 |
-
"Tested entries": summary.get("tested_entries"),
|
| 74 |
-
|
| 75 |
"ROC AUC": summary.get("roc_auc"),
|
| 76 |
-
"Confusion Matrix": summary.get("confusion_matrix"),
|
| 77 |
-
|
| 78 |
"Created At": run.created_at,
|
| 79 |
-
#TODO link to huggingface model
|
| 80 |
})
|
| 81 |
except Exception as e:
|
| 82 |
st.write(f"Error processing run {run.id}: {str(e)}")
|
|
@@ -88,74 +106,3 @@ def fetch_models_evaluation(api, projects, selected_project):
|
|
| 88 |
|
| 89 |
return df
|
| 90 |
|
| 91 |
-
def update_leader_info(leader_info, competition, best_model):
|
| 92 |
-
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 93 |
-
if leader_info.get(competition) is None:
|
| 94 |
-
leader_info[competition] = {
|
| 95 |
-
"Username": best_model["Username"],
|
| 96 |
-
"Hotkey": best_model["Hotkey"],
|
| 97 |
-
"Date": current_date,
|
| 98 |
-
"Days on Top": 1
|
| 99 |
-
}
|
| 100 |
-
else:
|
| 101 |
-
if leader_info[competition]["UID"] == best_model["ID"]:
|
| 102 |
-
leader_info[competition]["Days on Top"] += 1
|
| 103 |
-
else:
|
| 104 |
-
leader_info[competition] = {
|
| 105 |
-
"Username": best_model["Username"],
|
| 106 |
-
"Hotkey": best_model["Hotkey"],
|
| 107 |
-
"Date": current_date,
|
| 108 |
-
"Days on Top": 1
|
| 109 |
-
}
|
| 110 |
-
return leader_info[competition]
|
| 111 |
-
|
| 112 |
-
def highlight_score_column(s):
|
| 113 |
-
"""
|
| 114 |
-
Highlight the 'Score' column with a custom background color.
|
| 115 |
-
"""
|
| 116 |
-
return ['background-color: yellow' if s.name == 'Score' else '' for _ in s]
|
| 117 |
-
|
| 118 |
-
def set_custom_table_style():
|
| 119 |
-
st.markdown("""
|
| 120 |
-
<style>
|
| 121 |
-
.dataframe, .summary-table {
|
| 122 |
-
width: 100%;
|
| 123 |
-
border-collapse: collapse;
|
| 124 |
-
margin: 20px 0;
|
| 125 |
-
font-size: 16px;
|
| 126 |
-
min-width: 400px;
|
| 127 |
-
}
|
| 128 |
-
.dataframe th,
|
| 129 |
-
.dataframe td,
|
| 130 |
-
.summary-table th,
|
| 131 |
-
.summary-table td {
|
| 132 |
-
padding: 12px 15px;
|
| 133 |
-
border: 1px solid #CCCCCC;
|
| 134 |
-
text-align: left;
|
| 135 |
-
}
|
| 136 |
-
.dataframe thead th,
|
| 137 |
-
.summary-table th {
|
| 138 |
-
background-color: #333333;
|
| 139 |
-
color: #FFFFFF;
|
| 140 |
-
}
|
| 141 |
-
.dataframe tbody tr:nth-child(even),
|
| 142 |
-
.summary-table tr:nth-child(even) {
|
| 143 |
-
background-color: #F0F0F0;
|
| 144 |
-
}
|
| 145 |
-
.dataframe tbody tr:nth-child(odd),
|
| 146 |
-
.summary-table tr:nth-child(odd) {
|
| 147 |
-
background-color: #E0E0E0;
|
| 148 |
-
}
|
| 149 |
-
.dataframe tbody td,
|
| 150 |
-
.summary-table td {
|
| 151 |
-
color: #333333;
|
| 152 |
-
}
|
| 153 |
-
.dataframe tbody tr:hover,
|
| 154 |
-
.summary-table tr:hover {
|
| 155 |
-
background-color: #D1D1D1;
|
| 156 |
-
}
|
| 157 |
-
.table-container {
|
| 158 |
-
overflow-x: auto;
|
| 159 |
-
}
|
| 160 |
-
</style>
|
| 161 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import wandb
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def update_leader_info(leader_info, competition, best_model):
|
| 9 |
+
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 10 |
+
if leader_info.get(competition) is None:
|
| 11 |
+
leader_info[competition] = {
|
| 12 |
+
"Username": best_model["Username"],
|
| 13 |
+
"Model Name": best_model["Model Name"],
|
| 14 |
+
"Hotkey": best_model["Hotkey"],
|
| 15 |
+
"Date": current_date,
|
| 16 |
+
"Days on Top": 1
|
| 17 |
+
}
|
| 18 |
+
else:
|
| 19 |
+
if leader_info[competition]["UID"] == best_model["ID"]:
|
| 20 |
+
leader_info[competition]["Days on Top"] += 1
|
| 21 |
+
else:
|
| 22 |
+
leader_info[competition] = {
|
| 23 |
+
"Username": best_model["Username"],
|
| 24 |
+
"Model Name": best_model["Model Name"],
|
| 25 |
+
"Hotkey": best_model["Hotkey"],
|
| 26 |
+
"Date": current_date,
|
| 27 |
+
"Days on Top": 1
|
| 28 |
+
}
|
| 29 |
+
return leader_info[competition]
|
| 30 |
|
| 31 |
|
| 32 |
def get_all_competition_summary(api, projects):
|
|
|
|
| 54 |
for run in runs:
|
| 55 |
try:
|
| 56 |
summary = run.summary
|
| 57 |
+
if summary.get("validator_id") and summary.get("winning_hotkey"):
|
| 58 |
data.append({
|
| 59 |
"ID": run.id,
|
| 60 |
+
"Validator ID": summary.get("validator_id"),
|
| 61 |
"Winning Hotkey": summary.get("winning_hotkey"),
|
| 62 |
"Run Time (s)": summary.get("run_time_s"),
|
| 63 |
"Created At": run.created_at,
|
|
|
|
| 83 |
for run in runs:
|
| 84 |
try:
|
| 85 |
summary = run.summary
|
| 86 |
+
if summary.get("accuracy") is not None: # Assuming runs with accuracy are model evaluations
|
| 87 |
data.append({
|
| 88 |
"ID": run.id,
|
| 89 |
"Username": run.user.username,
|
| 90 |
+
"Model Name": summary.get("model_name", "N/A"),
|
| 91 |
+
"Hotkey": summary.get("hotkey", "N/A"),
|
| 92 |
"Score": summary.get("score"),
|
| 93 |
+
"F1-beta": summary.get("f1-beta"),
|
|
|
|
| 94 |
"Accuracy": summary.get("accuracy"),
|
| 95 |
"Recall": summary.get("recall"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
"ROC AUC": summary.get("roc_auc"),
|
|
|
|
|
|
|
| 97 |
"Created At": run.created_at,
|
|
|
|
| 98 |
})
|
| 99 |
except Exception as e:
|
| 100 |
st.write(f"Error processing run {run.id}: {str(e)}")
|
|
|
|
| 106 |
|
| 107 |
return df
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|