Skip to content

Commit f9cb3c0

Browse files
committed
changes
1 parent d7d7d8b commit f9cb3c0

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

trackio/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
import contextvars
12
import logging
23
from pathlib import Path
34

4-
from trackio.run import Run, current_run
5+
from trackio.run import Run
56
from trackio.ui import launch_ui
67

78
__version__ = Path(__file__).parent.joinpath("version.txt").read_text().strip()
89

910

10-
def init(project, name=None, config=None):
11+
current_run: contextvars.ContextVar[Run | None] = contextvars.ContextVar(
12+
"current_run", default=None
13+
)
14+
15+
current_ui: contextvars.ContextVar[bool] = contextvars.ContextVar(
16+
"ui_running", default=False
17+
)
18+
19+
20+
def init(project, name=None, config=None, ui=True):
1121
logging.info(f"Initializing run | Project: {project} | Name: {name}")
22+
if ui and not current_ui.get():
23+
launch_ui()
24+
current_ui.set(True)
1225
current_run.set(Run(project, name, config))
1326

1427

trackio/run.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import contextvars
2-
31
from trackio.storage import TrackioStorage
42
from trackio.utils import generate_readable_name
53

@@ -20,6 +18,3 @@ def finish(self):
2018
self.storage.finish()
2119

2220

23-
current_run: contextvars.ContextVar[Run | None] = contextvars.ContextVar(
24-
"current_run", default=None
25-
)

trackio/ui.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
def get_projects():
1010
if not os.path.exists(TRACKIO_DIR):
1111
return []
12-
return [
12+
projects = sorted([
1313
d
1414
for d in os.listdir(TRACKIO_DIR)
1515
if os.path.isdir(os.path.join(TRACKIO_DIR, d))
16-
]
16+
])
17+
return gr.Dropdown(label="Project", choices=projects, value=projects[0] if projects else None)
1718

1819

1920
def get_runs(project):
@@ -38,25 +39,48 @@ def load_run_data(project, run):
3839

3940

4041
def update_runs(project):
41-
runs = get_runs(project)
42+
if project is None:
43+
runs = []
44+
else:
45+
runs = get_runs(project)
4246
return gr.Dropdown(choices=runs, value=runs)
4347

4448

49+
def toggle_timer(cb_value):
50+
if cb_value:
51+
return gr.Timer(active=True)
52+
else:
53+
return gr.Timer(active=False)
54+
55+
4556
def launch_ui():
4657
with gr.Blocks(theme="citrus") as demo:
4758
with gr.Sidebar():
4859
gr.Markdown("# 🎯 Trackio Dashboard")
49-
project_dd = gr.Dropdown(label="Project", choices=get_projects())
60+
project_dd = gr.Dropdown(label="Project")
61+
realtime_cb = gr.Checkbox(label="Realtime", value=True)
5062
with gr.Row():
5163
run_dd = gr.Dropdown(label="Run", choices=[], multiselect=True)
5264

5365
timer = gr.Timer(value=1)
5466

5567
gr.on(
56-
[demo.load, project_dd.change],
68+
[demo.load, timer.tick],
69+
fn=get_projects,
70+
outputs=project_dd,
71+
show_progress=False,
72+
)
73+
gr.on(
74+
[demo.load, project_dd.change, timer.tick],
5775
fn=update_runs,
5876
inputs=project_dd,
5977
outputs=run_dd,
78+
show_progress=False,
79+
)
80+
realtime_cb.change(
81+
fn=toggle_timer,
82+
inputs=realtime_cb,
83+
outputs=timer,
6084
)
6185

6286
@gr.render(

0 commit comments

Comments
 (0)