Spaces:
Sleeping
Sleeping
config fetch
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import os
|
|
| 5 |
import time
|
| 6 |
import datetime
|
| 7 |
from typing import Dict, Any
|
| 8 |
-
from utils import fetch_competition_summary, fetch_models_evaluation, highlight_score_column
|
| 9 |
# from dotenv import load_dotenv
|
| 10 |
from cfg import *
|
| 11 |
# load_dotenv()
|
|
@@ -58,9 +58,11 @@ def update_leader_info(
|
|
| 58 |
def load_competition_data(last_update_time=None):
|
| 59 |
competition_summaries = {}
|
| 60 |
model_evaluations = {}
|
|
|
|
| 61 |
for competition in COMPETITIONS:
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
last_update_time = time.time()
|
| 66 |
return competition_summaries, model_evaluations, last_update_time
|
|
@@ -79,31 +81,33 @@ def main():
|
|
| 79 |
if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > UPDATE_INTERVAL):
|
| 80 |
competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
|
| 81 |
|
|
|
|
| 82 |
for competition in COMPETITIONS:
|
| 83 |
-
if
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
| 107 |
else:
|
| 108 |
competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
|
| 109 |
|
|
|
|
| 5 |
import time
|
| 6 |
import datetime
|
| 7 |
from typing import Dict, Any
|
| 8 |
+
from utils import fetch_competition_summary, fetch_models_evaluation, highlight_score_column, get_competition_id
|
| 9 |
# from dotenv import load_dotenv
|
| 10 |
from cfg import *
|
| 11 |
# load_dotenv()
|
|
|
|
| 58 |
def load_competition_data(last_update_time=None):
|
| 59 |
competition_summaries = {}
|
| 60 |
model_evaluations = {}
|
| 61 |
+
competitions_id = get_competition_id(CONFIG_URL)
|
| 62 |
for competition in COMPETITIONS:
|
| 63 |
+
if COMPETITIONS[competition]["project"] in competitions_id:
|
| 64 |
+
competition_summaries[competition] = fetch_competition_summary(wandb_api, COMPETITIONS, competition)
|
| 65 |
+
model_evaluations[competition] = fetch_models_evaluation(wandb_api, COMPETITIONS, competition)
|
| 66 |
|
| 67 |
last_update_time = time.time()
|
| 68 |
return competition_summaries, model_evaluations, last_update_time
|
|
|
|
| 81 |
if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > UPDATE_INTERVAL):
|
| 82 |
competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
|
| 83 |
|
| 84 |
+
competitions_id = get_competition_id(CONFIG_URL)
|
| 85 |
for competition in COMPETITIONS:
|
| 86 |
+
if COMPETITIONS[competition]["project"] in competitions_id:
|
| 87 |
+
if not competition_summaries[competition].empty:
|
| 88 |
+
# get all winning hotkeys and number of wins
|
| 89 |
+
winning_hotkeys = competition_summaries[competition]["Winning Hotkey"].value_counts()
|
| 90 |
+
|
| 91 |
+
# if not empty, get the best hotkey
|
| 92 |
+
if not winning_hotkeys.empty:
|
| 93 |
+
best_hotkey = winning_hotkeys.idxmax()
|
| 94 |
+
|
| 95 |
+
# Filter models for the best hotkey
|
| 96 |
+
best_model_filtered = model_evaluations[competition][model_evaluations[competition]["Miner hotkey"] == best_hotkey]
|
| 97 |
+
|
| 98 |
+
# Check if the filtered DataFrame is not empty
|
| 99 |
+
if not best_model_filtered.empty:
|
| 100 |
+
best_model = best_model_filtered.iloc[0]
|
| 101 |
+
st.session_state.leader_info[competition] = update_leader_info(st.session_state.leader_info, competition, best_model)
|
| 102 |
+
else:
|
| 103 |
+
st.warning(f"No model found for the best hotkey: {best_hotkey} in competition {competition}.")
|
| 104 |
+
|
| 105 |
+
else:
|
| 106 |
+
st.session_state.leader_info[competition] = {
|
| 107 |
+
"Miner hotkey": "N/A",
|
| 108 |
+
"Date": "N/A",
|
| 109 |
+
"Days on Top": "N/A"
|
| 110 |
+
}
|
| 111 |
else:
|
| 112 |
competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
|
| 113 |
|
cfg.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
UPDATE_INTERVAL = 2 * 60 # 20 minutes in seconds
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
COMPETITIONS = {
|
| 6 |
"Melanoma-1": {
|
|
|
|
| 1 |
UPDATE_INTERVAL = 2 * 60 # 20 minutes in seconds
|
| 2 |
|
| 3 |
+
CONFIG_URL = "https://raw.githubusercontent.com/safe-scan-ai/cancer-ai/main/config/competition_config.json"
|
| 4 |
|
| 5 |
COMPETITIONS = {
|
| 6 |
"Melanoma-1": {
|
utils.py
CHANGED
|
@@ -3,6 +3,21 @@ import pandas as pd
|
|
| 3 |
import wandb
|
| 4 |
import time
|
| 5 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def fetch_competition_summary(api, projects, selected_project):
|
|
|
|
| 3 |
import wandb
|
| 4 |
import time
|
| 5 |
from datetime import datetime
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_competition_id(CONFIG_URL):
|
| 10 |
+
"""
|
| 11 |
+
Get competition names from the config URL.
|
| 12 |
+
"""
|
| 13 |
+
competition_names = []
|
| 14 |
+
try:
|
| 15 |
+
config = requests.get(CONFIG_URL).json()
|
| 16 |
+
for competition in config:
|
| 17 |
+
competition_names.append(competition["competition_id"])
|
| 18 |
+
except Exception as e:
|
| 19 |
+
st.write(f"Error loading competition names: {str(e)}")
|
| 20 |
+
return competition_names
|
| 21 |
|
| 22 |
|
| 23 |
def fetch_competition_summary(api, projects, selected_project):
|