11import gradio as gr
2+ import os
3+ import json
4+ import pandas as pd
5+ import plotly .express as px
6+
7+ TRACKIO_DIR = "trackio"
8+
9+ def get_projects ():
10+ if not os .path .exists (TRACKIO_DIR ):
11+ return []
12+ return [d for d in os .listdir (TRACKIO_DIR ) if os .path .isdir (os .path .join (TRACKIO_DIR , d ))]
13+
14+ def get_runs (project ):
15+ project_dir = os .path .join (TRACKIO_DIR , project )
16+ if not os .path .exists (project_dir ):
17+ return []
18+ return [d for d in os .listdir (project_dir ) if os .path .isdir (os .path .join (project_dir , d ))]
19+
20+ def load_run_data (project , run ):
21+ run_dir = os .path .join (TRACKIO_DIR , project , run )
22+ run_path = os .path .join (run_dir , "run.parquet" )
23+ config_path = os .path .join (run_dir , "config.json" )
24+ df = None
25+ config = {}
26+ if os .path .exists (run_path ):
27+ df = pd .read_parquet (run_path )
28+ if os .path .exists (config_path ):
29+ with open (config_path ) as f :
30+ config = json .load (f )
31+ return df , config
32+
33+ def plot_metrics (df ):
34+ if df is None or df .empty :
35+ return None
36+ plots = []
37+ numeric_cols = df .select_dtypes (include = 'number' ).columns
38+ for col in numeric_cols :
39+ fig = px .line (df , y = col , title = col )
40+ plots .append (fig )
41+ return plots
42+
43+ def update_runs (project ):
44+ return gr .Dropdown .update (choices = get_runs (project ), value = None )
45+
46+ def update_dashboard (project , run ):
47+ if not project or not run :
48+ return gr .update (visible = False ), gr .update (visible = False ), gr .update (visible = False )
49+ df , config = load_run_data (project , run )
50+ plots = plot_metrics (df )
51+ config_str = json .dumps (config , indent = 2 )
52+ return plots , gr .JSON .update (value = config ), gr .update (visible = True )
253
354def launch_ui ():
455 with gr .Blocks () as demo :
5- gr .Markdown ("# Trackio Dashboard\n (Placeholder UI)" )
6- gr .Markdown ("This will show your tracked experiments." )
56+ gr .Markdown ("# Trackio Dashboard" )
57+ with gr .Row ():
58+ project_dd = gr .Dropdown (label = "Project" , choices = get_projects ())
59+ run_dd = gr .Dropdown (label = "Run" , choices = [])
60+ with gr .Row ():
61+ plot_output = gr .Plot (label = "Metrics" , visible = False , show_label = True , elem_id = "metrics-plot" , interactive = True , scale = 2 )
62+ config_output = gr .JSON (label = "Config" , visible = False )
63+ # Events
64+ project_dd .change (fn = lambda p : update_runs (p ), inputs = project_dd , outputs = run_dd )
65+ run_dd .change (fn = lambda p , r : update_dashboard (p , r ), inputs = [project_dd , run_dd ], outputs = [plot_output , config_output , plot_output ])
766 demo .launch ()
0 commit comments