1- import json
21import os
32
43import gradio as gr
54import pandas as pd
6- import plotly .express as px
75
8- TRACKIO_DIR = " trackio"
6+ from trackio . utils import RESERVED_KEYS , TRACKIO_DIR
97
108
119def get_projects ():
@@ -31,68 +29,56 @@ def get_runs(project):
3129
3230def load_run_data (project , run ):
3331 run_dir = os .path .join (TRACKIO_DIR , project , run )
34- run_path = os .path .join (run_dir , "run.parquet" )
35- config_path = os .path .join (run_dir , "config.json" )
32+ csv_path = os .path .join (run_dir , "run.csv" )
3633 df = None
37- config = {}
38- if os .path .exists (run_path ):
39- df = pd .read_parquet (run_path )
40- if os .path .exists (config_path ):
41- with open (config_path ) as f :
42- config = json .load (f )
43- return df , config
44-
45-
46- def plot_metrics (df ):
47- if df is None or df .empty :
48- return None
49- plots = []
50- numeric_cols = df .select_dtypes (include = "number" ).columns
51- for col in numeric_cols :
52- fig = px .line (df , y = col , title = col )
53- plots .append (fig )
54- return plots
34+ if os .path .exists (csv_path ):
35+ df = pd .read_csv (csv_path )
36+ df ["step" ] = range (len (df ))
37+ return df
5538
5639
5740def update_runs (project ):
58- return gr .Dropdown (choices = get_runs (project ), value = None )
59-
60-
61- def update_dashboard (project , run ):
62- if not project or not run :
63- return (
64- gr .update (visible = False ),
65- gr .update (visible = False ),
66- gr .update (visible = False ),
67- )
68- df , config = load_run_data (project , run )
69- plots = plot_metrics (df )
70- return plots , gr .JSON (value = config ), gr .update (visible = True )
41+ runs = get_runs (project )
42+ return gr .Dropdown (choices = runs , value = runs )
7143
7244
7345def launch_ui ():
74- with gr .Blocks () as demo :
75- gr .Markdown ( "# Trackio Dashboard" )
76- with gr .Row ():
46+ with gr .Blocks (theme = "citrus" ) as demo :
47+ with gr .Sidebar ():
48+ gr .Markdown ( "# 🎯 Trackio Dashboard" )
7749 project_dd = gr .Dropdown (label = "Project" , choices = get_projects ())
78- run_dd = gr .Dropdown (label = "Run" , choices = [])
7950 with gr .Row ():
80- plot_output = gr .LinePlot (
81- label = "Metrics" ,
82- visible = False ,
83- show_label = True ,
84- elem_id = "metrics-plot" ,
85- interactive = True ,
86- scale = 2 ,
87- )
88- config_output = gr .JSON (label = "Config" , visible = False )
89- # Events
90- project_dd .change (
91- fn = lambda p : update_runs (p ), inputs = project_dd , outputs = run_dd
51+ run_dd = gr .Dropdown (label = "Run" , choices = [], multiselect = True )
52+
53+ gr .on (
54+ [demo .load , project_dd .change ],
55+ fn = update_runs ,
56+ inputs = project_dd ,
57+ outputs = run_dd ,
9258 )
93- run_dd .change (
94- fn = lambda p , r : update_dashboard (p , r ),
59+
60+ @gr .render (
61+ triggers = [run_dd .change ],
9562 inputs = [project_dd , run_dd ],
96- outputs = [plot_output , config_output , plot_output ],
9763 )
98- demo .launch ()
64+ def update_dashboard (project , runs ):
65+ dfs = []
66+ for run in runs :
67+ df = load_run_data (project , run )
68+ if df is not None :
69+ df ["run" ] = run
70+ dfs .append (df )
71+ if dfs :
72+ master_df = pd .concat (dfs , ignore_index = True )
73+ else :
74+ master_df = pd .DataFrame ()
75+ numeric_cols = master_df .select_dtypes (include = "number" ).columns
76+ numeric_cols = [c for c in numeric_cols if c not in RESERVED_KEYS ]
77+ for col in numeric_cols :
78+ gr .LinePlot (master_df , x = "step" , y = col , color = "run" if "run" in master_df .columns else None , title = col )
79+
80+ demo .launch (show_api = False )
81+
82+
83+ if __name__ == "__main__" :
84+ launch_ui ()
0 commit comments