notbulubula commited on
Commit
f7832ad
·
1 Parent(s): 2181a15

mocne zmiany

Browse files
Files changed (2) hide show
  1. app.py +24 -46
  2. utils.py +37 -0
app.py CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
4
  import os
5
  import matplotlib.pyplot as plt
6
 
7
- # import utils.py
8
 
9
  # Access the API key from the environment variable
10
  wandb_api_key = os.getenv('WANDB_API_KEY')
@@ -25,64 +25,42 @@ projects = {
25
  "Competition 2": {"entity": "urbaniak-bruno-safescanai", "project": "basic-intro"},
26
  # Add more projects as needed
27
  }
 
28
 
29
  # Sidebar for project selection
30
  st.sidebar.title("Bookmarks")
31
- selected_project = st.sidebar.selectbox("Select a competition:", list(projects.keys()))
32
-
33
- # Get the selected project's details
34
- entity = projects[selected_project]["entity"]
35
- project = projects[selected_project]["project"]
36
 
37
 
38
  # Sidebar with buttons
39
  st.sidebar.title("Iluzja wyboru")
40
  option = st.sidebar.radio(
41
  "Select an option:",
42
- ["Overview", "Metrics", "Graphs", "Other"]
43
  )
44
 
 
45
 
46
  # Streamlit UI
47
  st.title("W&B Data in Streamlit")
48
 
49
- # Fetch all runs from the project
50
- runs = api.runs(f"{entity}/{project}")
51
-
52
- # Create a dropdown
53
- run_names = [run.name for run in runs]
54
- selected_run_name = st.selectbox("Select a run:", run_names)
55
-
56
- # Find the selected run
57
- selected_run = next(run for run in runs if run.name == selected_run_name)
58
-
59
- # Fetch the run data as a pandas DataFrame
60
- run_df = selected_run.history()
61
-
62
- if run_df.empty:
63
- st.warning("The selected run has no data available.")
64
- else:
65
-
66
- st.write(f"Displaying data for run: {selected_run.name}")
 
67
  st.dataframe(run_df)
68
-
69
- # Example of creating a simple line plot
70
- st.subheader("Run Metrics Over Time")
71
-
72
- # Select columns to plot
73
- metrics = st.multiselect("Select metrics to plot", run_df.columns, default=run_df.columns[0])
74
-
75
- if metrics:
76
- plt.figure(figsize=(10, 5))
77
- for metric in metrics:
78
- plt.plot(run_df['_step'], run_df[metric], label=metric)
79
-
80
- plt.xlabel("Step")
81
- plt.ylabel("Value")
82
- plt.legend()
83
- plt.title("Metrics Over Time")
84
-
85
- # Display the plot in Streamlit
86
- st.pyplot(plt)
87
- else:
88
- st.info("Please select at least one metric to plot.")
 
4
  import os
5
  import matplotlib.pyplot as plt
6
 
7
+ from utils import fetch_runs_to_df
8
 
9
  # Access the API key from the environment variable
10
  wandb_api_key = os.getenv('WANDB_API_KEY')
 
25
  "Competition 2": {"entity": "urbaniak-bruno-safescanai", "project": "basic-intro"},
26
  # Add more projects as needed
27
  }
28
+ bookmarks = ["All", "Competition 1", "Competition 2"]
29
 
30
  # Sidebar for project selection
31
  st.sidebar.title("Bookmarks")
32
+ selected_project = st.sidebar.selectbox("Select a competition:", bookmarks)
 
 
 
 
33
 
34
 
35
  # Sidebar with buttons
36
  st.sidebar.title("Iluzja wyboru")
37
  option = st.sidebar.radio(
38
  "Select an option:",
39
+ ["General", "Researchers", "Validators", "Models"]
40
  )
41
 
42
+ df = fetch_runs_to_df(api, projects, selected_project)
43
 
44
  # Streamlit UI
45
  st.title("W&B Data in Streamlit")
46
 
47
+ st.sidebar.header("Filter Options")
48
+ run_name_filter = st.sidebar.text_input("Filter by Run Name")
49
+ state_filter = st.sidebar.selectbox("Filter by State", ["All"] + df["State"].unique().tolist())
50
+
51
+ # Apply filters
52
+ if run_name_filter:
53
+ df = df[df["Run Name"].str.contains(run_name_filter, case=False, na=False)]
54
+ if state_filter != "All":
55
+ df = df[df["State"] == state_filter]
56
+
57
+ # Show the filtered DataFrame
58
+ st.dataframe(df)
59
+
60
+ # Display details of selected run
61
+ selected_run_id = st.selectbox("Select a Run ID to see details", df["ID"].tolist())
62
+ if selected_run_id:
63
+ selected_run = api.run(f"{entity}/{project}/{selected_run_id}")
64
+ run_df = selected_run.history()
65
+ st.write(f"Details for run: {selected_run.name}")
66
  st.dataframe(run_df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ def fetch_runs_to_df(api, projects, selected_project):
5
+ if selected_project == "All":
6
+ # return all runs from all projects
7
+ data = []
8
+ for project_name, details in projects.items():
9
+ entity = details["entity"]
10
+ project = details["project"]
11
+ runs = api.runs(f"{entity}/{project}")
12
+ for run in runs:
13
+ data.append({
14
+ "Run Name": run.name,
15
+ "ID": run.id,
16
+ "Created At": run.created_at,
17
+ "State": run.state,
18
+ "Tags": ", ".join(run.tags) # Join tags into a single string
19
+ })
20
+ df = pd.DataFrame(data)
21
+
22
+ else:
23
+ # Get the selected project's details
24
+ entity = projects[selected_project]["entity"]
25
+ project = projects[selected_project]["project"]
26
+ runs = api.runs(f"{entity}/{project}")
27
+ for run in runs:
28
+ data.append({
29
+ "Run Name": run.name,
30
+ "ID": run.id,
31
+ "Created At": run.created_at,
32
+ "State": run.state,
33
+ "Tags": ", ".join(run.tags) # Join tags into a single string
34
+ })
35
+ df = pd.DataFrame(data)
36
+
37
+ return df