bulubula commited on
Commit
d772529
1 Parent(s): d9e7892

dnisąpoliczone

Browse files
Files changed (1) hide show
  1. app.py +176 -172
app.py CHANGED
@@ -1,172 +1,176 @@
1
- import streamlit as st
2
- import wandb
3
- import pandas as pd
4
- import os
5
- import time
6
- from utils import fetch_runs_to_df, fetch_run, fetch_models_to_df
7
-
8
- ### WANDB
9
-
10
- # Access the API key from the environment variable
11
- wandb_api_key = os.getenv('WANDB_API_KEY')
12
-
13
- # Log in to wandb using the API key
14
- if wandb_api_key:
15
- wandb.login(key=wandb_api_key)
16
- else:
17
- st.error("WANDB_API_KEY not found in environment variables.")
18
-
19
- # Initialize W&B API
20
- api = wandb.Api()
21
-
22
- ### STREAMLIT APP
23
-
24
- # Define available projects (bookmarks)
25
- projects = {
26
- "Competition 1": {"entity": "urbaniak-bruno-safescanai", "project": "pytorch-intro", "description": "This is a beginner-friendly competition using PyTorch."},
27
- "Competition 2": {"entity": "urbaniak-bruno-safescanai", "project": "basic-intro", "description": "This competition focuses on basic introduction to AI models."},
28
- "Competition 3 (mamymodelexd)": {"entity": "urbaniak-bruno-safescanai", "project": "simple-cnn", "description": "This is an advanced competition for CNN model training."},
29
- "Competition 4": {"entity": "urbaniak-bruno-safescanai", "project": "model-validation", "description": "This competition covers techniques for model validation."},
30
- "Competition 5": {"entity": "safe-scan-ai", "project": "melanoma-1", "description": "This competition focuses on melanoma detection."},
31
- # Add more projects as needed
32
- }
33
-
34
- # Initialize leader info
35
- @st.cache_data
36
- def update_leader_info(leader_info, competition, best_model):
37
- if leader_info.get(competition) is None:
38
- leader_info[competition] = {
39
- "Username": best_model["Username"],
40
- "Model Name": best_model["Model Name"],
41
- "Hotkey": best_model["Hotkey"],
42
- "Date": time.strftime("%Y-%m-%d"),
43
- "UID": "xd",
44
- "Days on Top": 1
45
- }
46
- else:
47
- if leader_info[competition]["UID"] == "xd": #best_model["ID"]:
48
- leader_info[competition]["Days on Top"] += 1
49
- else:
50
- leader_info[competition]["Username"] = best_model["Username"]
51
- leader_info[competition]["Model Name"] = best_model["Model Name"]
52
- leader_info[competition]["Hotkey"] = best_model["Hotkey"]
53
- leader_info[competition]["Date"] = time.strftime("%Y-%m-%d")
54
- leader_info[competition]["UID"] = best_model["ID"]
55
- leader_info[competition]["Days on Top"] = 1
56
- return leader_info[competition]
57
-
58
-
59
- @st.cache_data()
60
- def load_competition_data(last_update_time=None):
61
- ranking_dfs = {}
62
- for competition, details in projects.items():
63
- df = fetch_runs_to_df(api, projects, competition)
64
- if not df.empty:
65
- # Convert to DataFrame
66
- ranking_df = fetch_models_to_df(api, projects, competition, df)
67
-
68
- # Rank the models by accuracy, then recall, then ROC AUC
69
- rank_by = ["Recall", "Accuracy", "ROC AUC"]
70
- ascending = [False, False, False]
71
- ranking_df = ranking_df.sort_values(by=rank_by, ascending=ascending)
72
-
73
- ranking_dfs[competition] = ranking_df
74
-
75
- # Update the timestamp of the last update
76
- last_update_time = time.time()
77
- return ranking_dfs, last_update_time
78
-
79
-
80
- # Streamlit app main function
81
- def main():
82
- # Set Streamlit page configuration to wide
83
- st.set_page_config(layout="wide")
84
- st.title("LaUltimate Dashboard")
85
- st.subheader("Welcome to the Competition Dashboard!")
86
- st.write("Explore the various AI competitions and their respective rankings. Select a competition to view more details and rankings.")
87
-
88
- # Define the update interval (e.g., 10 minutes)
89
- update_interval = 4 * 60 # 10 minutes in seconds
90
-
91
- # Initialize session state to track the last update time
92
- if 'last_update_time' not in st.session_state:
93
- st.session_state.last_update_time = None
94
- # Initialize or update leader_info
95
- if "leader_info" not in st.session_state:
96
- st.session_state.leader_info = {}
97
-
98
- # Check if we need to refresh the data
99
- if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > update_interval):
100
- ranking_dfs, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
101
-
102
- # Update leader info for each competition
103
- for competition in ranking_dfs:
104
- best_model = ranking_dfs[competition].iloc[0]
105
- st.session_state.leader_info[competition] = update_leader_info(st.session_state.leader_info, competition, best_model)
106
-
107
- else:
108
- ranking_dfs, _ = load_competition_data(st.session_state.last_update_time)
109
-
110
- # Display the time of the last update
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 with additional columns
118
- cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2]) # Adjust column width ratios if needed
119
- cols[0].write("Index")
120
- cols[1].write("Competition Name")
121
- cols[2].write("Leader")
122
- cols[3].write("Model")
123
- cols[4].write("Date")
124
- cols[5].write("UID")
125
- cols[6].write("Hotkey")
126
- cols[7].write("Days on Top")
127
-
128
-
129
- # Display the project names in a table-like structure with buttons and placeholders for additional data
130
- for index, (competition, details) in enumerate(projects.items(), start=1):
131
- best_model = ranking_dfs[competition].iloc[0]
132
-
133
- # Use the leader_info from session_state
134
- leader_info = st.session_state.get("leader_info")
135
-
136
-
137
- cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
138
- cols[0].write(index)
139
- if cols[1].button(competition):
140
- st.experimental_set_query_params(comp=competition)
141
- cols[2].write(leader_info[competition]["Username"])
142
- cols[3].write(leader_info[competition]["Model Name"])
143
- cols[4].write(leader_info[competition]["Date"])
144
- cols[5].write(leader_info[competition]["UID"])
145
- cols[6].write(leader_info[competition]["Hotkey"])
146
- cols[7].write(leader_info[competition]["Days on Top"])
147
-
148
-
149
- # Get query parameters to identify which competition page to show
150
- query_params = st.experimental_get_query_params()
151
-
152
- if "comp" in query_params:
153
- competition_name = query_params["comp"][0]
154
- st.write(f"Selected competition: {competition_name}")
155
- competition_details = projects.get(competition_name, {})
156
- description = competition_details.get("description", "No description available.")
157
-
158
- st.header(f"Competition: {competition_name}")
159
- st.write(description)
160
-
161
- df = ranking_dfs[competition_name]
162
- if not df.empty:
163
- st.dataframe(df)
164
- else:
165
- st.warning("No runs available for ranking.")
166
- else:
167
- st.write("Please select a competition to view details.")
168
-
169
-
170
- # Run the app
171
- if __name__ == "__main__":
172
- main()
 
 
 
 
 
1
+ import streamlit as st
2
+ import wandb
3
+ import pandas as pd
4
+ import os
5
+ import time
6
+ from utils import fetch_runs_to_df, fetch_run, fetch_models_to_df
7
+
8
+ ### WANDB
9
+
10
+ # Access the API key from the environment variable
11
+ wandb_api_key = os.getenv('WANDB_API_KEY')
12
+
13
+ # Log in to wandb using the API key
14
+ if wandb_api_key:
15
+ wandb.login(key=wandb_api_key)
16
+ else:
17
+ st.error("WANDB_API_KEY not found in environment variables.")
18
+
19
+ # Initialize W&B API
20
+ api = wandb.Api()
21
+
22
+ ### STREAMLIT APP
23
+
24
+ # Define available projects (bookmarks)
25
+ projects = {
26
+ "Competition 1": {"entity": "urbaniak-bruno-safescanai", "project": "pytorch-intro", "description": "This is a beginner-friendly competition using PyTorch."},
27
+ "Competition 2": {"entity": "urbaniak-bruno-safescanai", "project": "basic-intro", "description": "This competition focuses on basic introduction to AI models."},
28
+ "Competition 3 (mamymodelexd)": {"entity": "urbaniak-bruno-safescanai", "project": "simple-cnn", "description": "This is an advanced competition for CNN model training."},
29
+ "Competition 4": {"entity": "urbaniak-bruno-safescanai", "project": "model-validation", "description": "This competition covers techniques for model validation."},
30
+ "Competition 5": {"entity": "safe-scan-ai", "project": "melanoma-1", "description": "This competition focuses on melanoma detection."},
31
+ # Add more projects as needed
32
+ }
33
+
34
+ # Initialize leader info
35
+ @st.cache_data
36
+ def update_leader_info(leader_info, competition, best_model):
37
+ if leader_info.get(competition) is None:
38
+ leader_info[competition] = {
39
+ "Username": best_model["Username"],
40
+ "Model Name": best_model["Model Name"],
41
+ "Hotkey": best_model["Hotkey"],
42
+ "Date": time.strftime("%Y-%m-%d"),
43
+ "UID": "xd",
44
+ "Days on Top": 1
45
+ }
46
+ else:
47
+ if leader_info[competition]["UID"] == "xd": #best_model["ID"]:
48
+ # update the days on top to the difference between the current date and the date of the last update
49
+ current_date = time.strftime("%Y-%m-%d")
50
+ last_update_date = leader_info[competition]["Date"]
51
+ days_on_top = (current_date - last_update_date).days
52
+ leader_info[competition]["Days on Top"] = days_on_top
53
+ else:
54
+ leader_info[competition]["Username"] = best_model["Username"]
55
+ leader_info[competition]["Model Name"] = best_model["Model Name"]
56
+ leader_info[competition]["Hotkey"] = best_model["Hotkey"]
57
+ leader_info[competition]["Date"] = time.strftime("%Y-%m-%d")
58
+ leader_info[competition]["UID"] = best_model["ID"]
59
+ leader_info[competition]["Days on Top"] = 1
60
+ return leader_info[competition]
61
+
62
+
63
+ @st.cache_data()
64
+ def load_competition_data(last_update_time=None):
65
+ ranking_dfs = {}
66
+ for competition, details in projects.items():
67
+ df = fetch_runs_to_df(api, projects, competition)
68
+ if not df.empty:
69
+ # Convert to DataFrame
70
+ ranking_df = fetch_models_to_df(api, projects, competition, df)
71
+
72
+ # Rank the models by accuracy, then recall, then ROC AUC
73
+ rank_by = ["Recall", "Accuracy", "ROC AUC"]
74
+ ascending = [False, False, False]
75
+ ranking_df = ranking_df.sort_values(by=rank_by, ascending=ascending)
76
+
77
+ ranking_dfs[competition] = ranking_df
78
+
79
+ # Update the timestamp of the last update
80
+ last_update_time = time.time()
81
+ return ranking_dfs, last_update_time
82
+
83
+
84
+ # Streamlit app main function
85
+ def main():
86
+ # Set Streamlit page configuration to wide
87
+ st.set_page_config(layout="wide")
88
+ st.title("LaUltimate Dashboard")
89
+ st.subheader("Welcome to the Competition Dashboard!")
90
+ st.write("Explore the various AI competitions and their respective rankings. Select a competition to view more details and rankings.")
91
+
92
+ # Define the update interval (e.g., 10 minutes)
93
+ update_interval = 4 * 60 # 10 minutes in seconds
94
+
95
+ # Initialize session state to track the last update time
96
+ if 'last_update_time' not in st.session_state:
97
+ st.session_state.last_update_time = None
98
+ # Initialize or update leader_info
99
+ if "leader_info" not in st.session_state:
100
+ st.session_state.leader_info = {}
101
+
102
+ # Check if we need to refresh the data
103
+ if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > update_interval):
104
+ ranking_dfs, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
105
+
106
+ # Update leader info for each competition
107
+ for competition in ranking_dfs:
108
+ best_model = ranking_dfs[competition].iloc[0]
109
+ st.session_state.leader_info[competition] = update_leader_info(st.session_state.leader_info, competition, best_model)
110
+
111
+ else:
112
+ ranking_dfs, _ = load_competition_data(st.session_state.last_update_time)
113
+
114
+ # Display the time of the last update
115
+ st.write(f"Last updated: {time.ctime(st.session_state.last_update_time)}")
116
+
117
+ st.markdown("### Competitions")
118
+
119
+ st.write("### Select Competition")
120
+
121
+ # Create a header for the table with additional columns
122
+ cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2]) # Adjust column width ratios if needed
123
+ cols[0].write("Index")
124
+ cols[1].write("Competition Name")
125
+ cols[2].write("Leader")
126
+ cols[3].write("Model")
127
+ cols[4].write("Date")
128
+ cols[5].write("UID")
129
+ cols[6].write("Hotkey")
130
+ cols[7].write("Days on Top")
131
+
132
+
133
+ # Display the project names in a table-like structure with buttons and placeholders for additional data
134
+ for index, (competition, details) in enumerate(projects.items(), start=1):
135
+ best_model = ranking_dfs[competition].iloc[0]
136
+
137
+ # Use the leader_info from session_state
138
+ leader_info = st.session_state.get("leader_info")
139
+
140
+
141
+ cols = st.columns([1, 3, 2, 2, 2, 2, 1, 2])
142
+ cols[0].write(index)
143
+ if cols[1].button(competition):
144
+ st.experimental_set_query_params(comp=competition)
145
+ cols[2].write(leader_info[competition]["Username"])
146
+ cols[3].write(leader_info[competition]["Model Name"])
147
+ cols[4].write(leader_info[competition]["Date"])
148
+ cols[5].write(leader_info[competition]["UID"])
149
+ cols[6].write(leader_info[competition]["Hotkey"])
150
+ cols[7].write(leader_info[competition]["Days on Top"])
151
+
152
+
153
+ # Get query parameters to identify which competition page to show
154
+ query_params = st.experimental_get_query_params()
155
+
156
+ if "comp" in query_params:
157
+ competition_name = query_params["comp"][0]
158
+ st.write(f"Selected competition: {competition_name}")
159
+ competition_details = projects.get(competition_name, {})
160
+ description = competition_details.get("description", "No description available.")
161
+
162
+ st.header(f"Competition: {competition_name}")
163
+ st.write(description)
164
+
165
+ df = ranking_dfs[competition_name]
166
+ if not df.empty:
167
+ st.dataframe(df)
168
+ else:
169
+ st.warning("No runs available for ranking.")
170
+ else:
171
+ st.write("Please select a competition to view details.")
172
+
173
+
174
+ # Run the app
175
+ if __name__ == "__main__":
176
+ main()