Spaces:
Sleeping
Sleeping
Commit
·
da95145
1
Parent(s):
764d370
Dashnoard test
Browse files
app.py
CHANGED
|
@@ -4,7 +4,9 @@ import pandas as pd
|
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
import datetime
|
| 7 |
-
from utils import
|
|
|
|
|
|
|
| 8 |
|
| 9 |
### WANDB
|
| 10 |
|
|
@@ -24,11 +26,12 @@ api = wandb.Api()
|
|
| 24 |
|
| 25 |
# Define available projects (bookmarks)
|
| 26 |
projects = {
|
| 27 |
-
"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
# Add more projects as needed
|
| 33 |
}
|
| 34 |
|
|
@@ -65,68 +68,54 @@ def update_leader_info(leader_info, competition, best_model):
|
|
| 65 |
leader_info[competition]["UID"] = best_model["ID"]
|
| 66 |
leader_info[competition]["Days on Top"] = 1
|
| 67 |
return leader_info[competition]
|
| 68 |
-
|
| 69 |
-
|
| 70 |
@st.cache_data()
|
| 71 |
def load_competition_data(last_update_time=None):
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
ranking_df = fetch_models_to_df(api, projects, competition, df)
|
| 78 |
-
|
| 79 |
-
# Rank the models by accuracy, then recall, then ROC AUC
|
| 80 |
-
rank_by = ["Recall", "Accuracy", "ROC AUC"]
|
| 81 |
-
ascending = [False, False, False]
|
| 82 |
-
ranking_df = ranking_df.sort_values(by=rank_by, ascending=ascending)
|
| 83 |
-
|
| 84 |
-
ranking_dfs[competition] = ranking_df
|
| 85 |
|
| 86 |
-
# Update the timestamp of the last update
|
| 87 |
last_update_time = time.time()
|
| 88 |
-
return
|
| 89 |
-
|
| 90 |
|
| 91 |
# Streamlit app main function
|
| 92 |
def main():
|
| 93 |
-
# Set Streamlit page configuration to wide
|
| 94 |
-
st.set_page_config(layout="wide")
|
| 95 |
st.title("LaUltimate Dashboard")
|
|
|
|
| 96 |
st.subheader("Welcome to the Competition Dashboard!")
|
| 97 |
st.write("Explore the various AI competitions and their respective rankings. Select a competition to view more details and rankings.")
|
| 98 |
|
| 99 |
-
|
| 100 |
-
update_interval = 20 * 60 # 10 minutes in seconds
|
| 101 |
|
| 102 |
-
# Initialize session state to track the last update time
|
| 103 |
if 'last_update_time' not in st.session_state:
|
| 104 |
st.session_state.last_update_time = None
|
| 105 |
-
# Initialize or update leader_info
|
| 106 |
if "leader_info" not in st.session_state:
|
| 107 |
st.session_state.leader_info = {}
|
| 108 |
|
| 109 |
-
# Check if we need to refresh the data
|
| 110 |
if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > update_interval):
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
else:
|
| 119 |
-
|
| 120 |
|
| 121 |
-
# Display the time of the last update
|
| 122 |
st.write(f"Last updated: {time.ctime(st.session_state.last_update_time)}")
|
| 123 |
|
| 124 |
st.markdown("### Competitions")
|
| 125 |
|
| 126 |
st.write("### Select Competition")
|
| 127 |
|
| 128 |
-
# Create a header for the table
|
| 129 |
-
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 130 |
cols[0].write("Index")
|
| 131 |
cols[1].write("Competition Name")
|
| 132 |
cols[2].write("Leader")
|
|
@@ -136,32 +125,23 @@ def main():
|
|
| 136 |
cols[6].write("Hotkey")
|
| 137 |
cols[7].write("Days on Top")
|
| 138 |
|
| 139 |
-
|
| 140 |
-
# Display the project names in a table-like structure with buttons and placeholders for additional data
|
| 141 |
for index, (competition, details) in enumerate(projects.items(), start=1):
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
# Use the leader_info from session_state
|
| 145 |
-
leader_info = st.session_state.get("leader_info")
|
| 146 |
-
|
| 147 |
|
| 148 |
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 149 |
cols[0].write(index)
|
| 150 |
if cols[1].button(competition):
|
| 151 |
-
st.
|
| 152 |
-
cols[2].write(leader_info
|
| 153 |
-
cols[3].write(leader_info
|
| 154 |
-
cols[4].write(leader_info
|
| 155 |
-
cols[5].write(leader_info
|
| 156 |
-
cols[6].write(leader_info
|
| 157 |
-
cols[7].write(leader_info
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
# Get query parameters to identify which competition page to show
|
| 161 |
-
query_params = st.experimental_get_query_params()
|
| 162 |
-
|
| 163 |
if "comp" in query_params:
|
| 164 |
-
competition_name = query_params["comp"]
|
| 165 |
st.write(f"Selected competition: {competition_name}")
|
| 166 |
competition_details = projects.get(competition_name, {})
|
| 167 |
description = competition_details.get("description", "No description available.")
|
|
@@ -169,15 +149,23 @@ def main():
|
|
| 169 |
st.header(f"Competition: {competition_name}")
|
| 170 |
st.write(description)
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
else:
|
| 176 |
-
st.warning("No
|
| 177 |
else:
|
| 178 |
st.write("Please select a competition to view details.")
|
| 179 |
|
| 180 |
|
| 181 |
# Run the app
|
| 182 |
if __name__ == "__main__":
|
| 183 |
-
main()
|
|
|
|
| 4 |
import os
|
| 5 |
import time
|
| 6 |
import datetime
|
| 7 |
+
from utils import fetch_competition_summary, fetch_models_evaluation
|
| 8 |
+
|
| 9 |
+
st.set_page_config(layout="wide")
|
| 10 |
|
| 11 |
### WANDB
|
| 12 |
|
|
|
|
| 26 |
|
| 27 |
# Define available projects (bookmarks)
|
| 28 |
projects = {
|
| 29 |
+
"Melanoma TestNet": {
|
| 30 |
+
"entity": "safe-scan-ai",
|
| 31 |
+
"project": "melanoma-testnet",
|
| 32 |
+
"description": "This is a testnet competition for melanoma detection."
|
| 33 |
+
},
|
| 34 |
+
|
| 35 |
# Add more projects as needed
|
| 36 |
}
|
| 37 |
|
|
|
|
| 68 |
leader_info[competition]["UID"] = best_model["ID"]
|
| 69 |
leader_info[competition]["Days on Top"] = 1
|
| 70 |
return leader_info[competition]
|
|
|
|
|
|
|
| 71 |
@st.cache_data()
|
| 72 |
def load_competition_data(last_update_time=None):
|
| 73 |
+
competition_summaries = {}
|
| 74 |
+
model_evaluations = {}
|
| 75 |
+
for competition in projects:
|
| 76 |
+
competition_summaries[competition] = fetch_competition_summary(api, projects, competition)
|
| 77 |
+
model_evaluations[competition] = fetch_models_evaluation(api, projects, competition)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
|
|
|
| 79 |
last_update_time = time.time()
|
| 80 |
+
return competition_summaries, model_evaluations, last_update_time
|
|
|
|
| 81 |
|
| 82 |
# Streamlit app main function
|
| 83 |
def main():
|
|
|
|
|
|
|
| 84 |
st.title("LaUltimate Dashboard")
|
| 85 |
+
st.title("JEDZIESZMALINA")
|
| 86 |
st.subheader("Welcome to the Competition Dashboard!")
|
| 87 |
st.write("Explore the various AI competitions and their respective rankings. Select a competition to view more details and rankings.")
|
| 88 |
|
| 89 |
+
update_interval = 20 * 60 # 20 minutes in seconds
|
|
|
|
| 90 |
|
|
|
|
| 91 |
if 'last_update_time' not in st.session_state:
|
| 92 |
st.session_state.last_update_time = None
|
|
|
|
| 93 |
if "leader_info" not in st.session_state:
|
| 94 |
st.session_state.leader_info = {}
|
| 95 |
|
|
|
|
| 96 |
if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > update_interval):
|
| 97 |
+
competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
|
| 98 |
+
|
| 99 |
+
for competition in projects:
|
| 100 |
+
if not model_evaluations[competition].empty:
|
| 101 |
+
best_model = model_evaluations[competition].iloc[0]
|
| 102 |
+
st.session_state.leader_info[competition] = update_leader_info(st.session_state.leader_info, competition, best_model)
|
| 103 |
+
else:
|
| 104 |
+
st.session_state.leader_info[competition] = {
|
| 105 |
+
"Username": "N/A", "Model Name": "N/A", "Hotkey": "N/A",
|
| 106 |
+
"Date": "N/A", "UID": "N/A", "Days on Top": "N/A"
|
| 107 |
+
}
|
| 108 |
else:
|
| 109 |
+
competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
|
| 110 |
|
|
|
|
| 111 |
st.write(f"Last updated: {time.ctime(st.session_state.last_update_time)}")
|
| 112 |
|
| 113 |
st.markdown("### Competitions")
|
| 114 |
|
| 115 |
st.write("### Select Competition")
|
| 116 |
|
| 117 |
+
# Create a header for the table
|
| 118 |
+
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 119 |
cols[0].write("Index")
|
| 120 |
cols[1].write("Competition Name")
|
| 121 |
cols[2].write("Leader")
|
|
|
|
| 125 |
cols[6].write("Hotkey")
|
| 126 |
cols[7].write("Days on Top")
|
| 127 |
|
|
|
|
|
|
|
| 128 |
for index, (competition, details) in enumerate(projects.items(), start=1):
|
| 129 |
+
leader_info = st.session_state.get("leader_info", {}).get(competition, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
|
| 132 |
cols[0].write(index)
|
| 133 |
if cols[1].button(competition):
|
| 134 |
+
st.query_params["comp"] = competition
|
| 135 |
+
cols[2].write(leader_info.get("Username", "N/A"))
|
| 136 |
+
cols[3].write(leader_info.get("Model Name", "N/A"))
|
| 137 |
+
cols[4].write(leader_info.get("Date", "N/A"))
|
| 138 |
+
cols[5].write(leader_info.get("UID", "N/A"))
|
| 139 |
+
cols[6].write(leader_info.get("Hotkey", "N/A"))
|
| 140 |
+
cols[7].write(leader_info.get("Days on Top", "N/A"))
|
| 141 |
+
|
| 142 |
+
query_params = st.query_params
|
|
|
|
|
|
|
|
|
|
| 143 |
if "comp" in query_params:
|
| 144 |
+
competition_name = query_params["comp"]
|
| 145 |
st.write(f"Selected competition: {competition_name}")
|
| 146 |
competition_details = projects.get(competition_name, {})
|
| 147 |
description = competition_details.get("description", "No description available.")
|
|
|
|
| 149 |
st.header(f"Competition: {competition_name}")
|
| 150 |
st.write(description)
|
| 151 |
|
| 152 |
+
st.subheader("Competition Summary")
|
| 153 |
+
competition_summary_df = competition_summaries.get(competition_name, pd.DataFrame())
|
| 154 |
+
if not competition_summary_df.empty:
|
| 155 |
+
st.dataframe(competition_summary_df)
|
| 156 |
+
else:
|
| 157 |
+
st.warning("No competition summary data available.")
|
| 158 |
+
|
| 159 |
+
st.subheader("Models Evaluation")
|
| 160 |
+
models_evaluation_df = model_evaluations.get(competition_name, pd.DataFrame())
|
| 161 |
+
if not models_evaluation_df.empty:
|
| 162 |
+
st.dataframe(models_evaluation_df)
|
| 163 |
else:
|
| 164 |
+
st.warning("No models evaluation data available.")
|
| 165 |
else:
|
| 166 |
st.write("Please select a competition to view details.")
|
| 167 |
|
| 168 |
|
| 169 |
# Run the app
|
| 170 |
if __name__ == "__main__":
|
| 171 |
+
main()
|
utils.py
CHANGED
|
@@ -1,109 +1,97 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import wandb
|
|
|
|
| 4 |
|
| 5 |
-
def fetch_runs_to_df(api, projects, selected_project):
|
| 6 |
-
data = []
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
data.append({
|
| 16 |
-
"Run Name": run.name,
|
| 17 |
"ID": run.id,
|
|
|
|
|
|
|
|
|
|
| 18 |
"Created At": run.created_at,
|
| 19 |
-
"State": run.state,
|
| 20 |
-
"Tags": ", ".join(run.tags) # Join tags into a single string
|
| 21 |
})
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
data.append({
|
| 31 |
-
"Run Name": run.name,
|
| 32 |
-
"ID": run.id,
|
| 33 |
-
"Created At": run.created_at,
|
| 34 |
-
"State": run.state,
|
| 35 |
-
"Tags": ", ".join(run.tags) # Join tags into a single string
|
| 36 |
-
})
|
| 37 |
-
df = pd.DataFrame(data)
|
| 38 |
-
|
| 39 |
return df
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
# Fetch run details based on the selected project
|
| 43 |
-
if selected_project == "All":
|
| 44 |
-
# Find the project for the selected run_id
|
| 45 |
-
for project_name, details in projects.items():
|
| 46 |
-
entity = details["entity"]
|
| 47 |
-
project = details["project"]
|
| 48 |
-
try:
|
| 49 |
-
run = api.run(f"{entity}/{project}/{selected_run_id}")
|
| 50 |
-
break
|
| 51 |
-
except wandb.errors.CommError:
|
| 52 |
-
continue
|
| 53 |
-
else:
|
| 54 |
-
st.error(f"Run ID {selected_run_id} not found in any project.")
|
| 55 |
-
else:
|
| 56 |
-
entity = projects[selected_project]["entity"]
|
| 57 |
-
project = projects[selected_project]["project"]
|
| 58 |
-
run = api.run(f"{entity}/{project}/{selected_run_id}")
|
| 59 |
-
|
| 60 |
-
return run
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
def fetch_models_to_df(api, projects, selected_project, df):
|
| 64 |
data = []
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
try:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
if artifact.type == "model": # Assuming the artifact type is "model"
|
| 90 |
-
model_name = artifact.name # Use the artifact's name as the model name
|
| 91 |
-
break
|
| 92 |
-
|
| 93 |
-
data.append({
|
| 94 |
-
"Username": run.user.username,
|
| 95 |
-
"Model Name": metrics.get("model_name"), # Add model name to the table
|
| 96 |
-
"Hotkey": metrics.get("hotkey"), # Add model name to the table
|
| 97 |
-
# "Run Name": row["Run Name"],
|
| 98 |
-
"ID": row["ID"],
|
| 99 |
-
"Number of tested entries": metrics.get("tested_entries"),
|
| 100 |
-
# "Run Time": metrics.get("model_test_run_time"),
|
| 101 |
-
"Accuracy": metrics.get("accuracy"), # Example metric
|
| 102 |
-
"Recall": metrics.get("recall"), # Example metric
|
| 103 |
-
"ROC AUC": metrics.get("roc_auc"), # Example metric
|
| 104 |
-
})
|
| 105 |
-
except wandb.errors.CommError:
|
| 106 |
-
continue
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import wandb
|
| 4 |
+
import datetime
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def fetch_competition_summary(api, projects, selected_project):
|
| 8 |
+
data = []
|
| 9 |
+
st.write(f"Fetching competition summary for {selected_project}")
|
| 10 |
+
|
| 11 |
+
entity = projects[selected_project]["entity"]
|
| 12 |
+
project = projects[selected_project]["project"]
|
| 13 |
+
|
| 14 |
+
runs = api.runs(f"{entity}/{project}")
|
| 15 |
+
st.write(f"Number of runs to process: {len(runs)}")
|
| 16 |
+
|
| 17 |
+
for run in runs:
|
| 18 |
+
try:
|
| 19 |
+
summary = run.summary
|
| 20 |
+
if summary.get("validator_id") and summary.get("winning_hotkey"):
|
| 21 |
data.append({
|
|
|
|
| 22 |
"ID": run.id,
|
| 23 |
+
"Validator ID": summary.get("validator_id"),
|
| 24 |
+
"Winning Hotkey": summary.get("winning_hotkey"),
|
| 25 |
+
"Run Time (s)": summary.get("run_time_s"),
|
| 26 |
"Created At": run.created_at,
|
|
|
|
|
|
|
| 27 |
})
|
| 28 |
+
except Exception as e:
|
| 29 |
+
st.write(f"Error processing run {run.id}: {str(e)}")
|
| 30 |
|
| 31 |
+
df = pd.DataFrame(data)
|
| 32 |
+
if not df.empty:
|
| 33 |
+
df['Created At'] = pd.to_datetime(df['Created At'])
|
| 34 |
+
df = df.sort_values(by="Created At", ascending=False)
|
| 35 |
+
|
| 36 |
+
st.write(f"Competition summary data: {len(df)} rows")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return df
|
| 38 |
|
| 39 |
+
def fetch_models_evaluation(api, projects, selected_project):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
data = []
|
| 41 |
+
st.write(f"Fetching models evaluation for {selected_project}")
|
| 42 |
+
|
| 43 |
+
entity = projects[selected_project]["entity"]
|
| 44 |
+
project = projects[selected_project]["project"]
|
| 45 |
+
|
| 46 |
+
runs = api.runs(f"{entity}/{project}")
|
| 47 |
+
st.write(f"Number of runs to process: {len(runs)}")
|
| 48 |
+
|
| 49 |
+
for run in runs:
|
| 50 |
try:
|
| 51 |
+
summary = run.summary
|
| 52 |
+
if summary.get("accuracy") is not None: # Assuming runs with accuracy are model evaluations
|
| 53 |
+
data.append({
|
| 54 |
+
"ID": run.id,
|
| 55 |
+
"Username": run.user.username,
|
| 56 |
+
"Model Name": summary.get("model_name", "N/A"),
|
| 57 |
+
"Hotkey": summary.get("hotkey", "N/A"),
|
| 58 |
+
"Accuracy": summary.get("accuracy"),
|
| 59 |
+
"Recall": summary.get("recall"),
|
| 60 |
+
"ROC AUC": summary.get("roc_auc"),
|
| 61 |
+
"Created At": run.created_at,
|
| 62 |
+
})
|
| 63 |
+
except Exception as e:
|
| 64 |
+
st.write(f"Error processing run {run.id}: {str(e)}")
|
| 65 |
+
|
| 66 |
+
df = pd.DataFrame(data)
|
| 67 |
+
if not df.empty:
|
| 68 |
+
df['Created At'] = pd.to_datetime(df['Created At'])
|
| 69 |
+
df = df.sort_values(by="Created At", ascending=False)
|
| 70 |
+
|
| 71 |
+
st.write(f"Models evaluation data: {len(df)} rows")
|
| 72 |
+
return df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
def update_leader_info(leader_info, competition, best_model):
|
| 75 |
+
current_date = datetime.now().strftime("%Y-%m-%d")
|
| 76 |
+
if leader_info.get(competition) is None:
|
| 77 |
+
leader_info[competition] = {
|
| 78 |
+
"Username": best_model["Username"],
|
| 79 |
+
"Model Name": best_model["Model Name"],
|
| 80 |
+
"Hotkey": best_model["Hotkey"],
|
| 81 |
+
"Date": current_date,
|
| 82 |
+
"UID": best_model["ID"],
|
| 83 |
+
"Days on Top": 1
|
| 84 |
+
}
|
| 85 |
+
else:
|
| 86 |
+
if leader_info[competition]["UID"] == best_model["ID"]:
|
| 87 |
+
leader_info[competition]["Days on Top"] += 1
|
| 88 |
+
else:
|
| 89 |
+
leader_info[competition] = {
|
| 90 |
+
"Username": best_model["Username"],
|
| 91 |
+
"Model Name": best_model["Model Name"],
|
| 92 |
+
"Hotkey": best_model["Hotkey"],
|
| 93 |
+
"Date": current_date,
|
| 94 |
+
"UID": best_model["ID"],
|
| 95 |
+
"Days on Top": 1
|
| 96 |
+
}
|
| 97 |
+
return leader_info[competition]
|