Skip to content

Commit efc149a

Browse files
authored
Merge pull request #5 from gradio-app/print-proj
Now includes a direct link to the project when run:
2 parents 9b487b2 + 9b0ae77 commit efc149a

6 files changed

Lines changed: 132 additions & 109 deletions

File tree

README.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,8 @@
1111
- *Local-first* design: dashboard runs locally by default. You can also host it on Spaces by changing a single parameter.
1212
- Everything here, including hosting on Spaces, is **free**!
1313

14-
## Example Usage
15-
```python
16-
import random
17-
import math
18-
import trackio
19-
import time
20-
21-
sleep_time = 0.5
22-
23-
# Launch 5 simulated experiments
24-
total_runs = 5
25-
for run in range(total_runs):
26-
27-
trackio.init(
28-
project="basic-intro-4",
29-
name=f"experiment_{run}",
30-
config={
31-
"learning_rate": 0.02,
32-
"architecture": "CNN",
33-
"dataset": "CIFAR-100",
34-
"epochs": 10,
35-
},
36-
)
37-
time.sleep(sleep_time)
38-
39-
epochs = 10
40-
offset = random.random() / 5
41-
for epoch in range(2, epochs):
42-
time.sleep(sleep_time)
43-
acc = 1 - 2**-epoch - random.random() / epoch - offset
44-
loss = 2**-epoch + random.random() / epoch + offset
45-
trackio.log({"acc": acc, "loss": loss})
46-
```
47-
4814
Trackio is designed to be lightweight (<500 lines of code total), not fully-featured. It is designed in a modular way so that developers can easily fork the repository and add functionality that they care about.
4915

50-
## Data Storage
51-
- Logs are saved in `./trackio/{project}/{run_name}/run.parquet`
52-
- Config is saved as `config.json` in the same directory
53-
54-
## Visualization
55-
- Run `trackio.ui()` to launch the Gradio dashboard and explore your experiments
5616

5717
## Installation
5818

tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
def test_version():
5-
assert trackio.__version__ == "0.0.4"
5+
assert trackio.__version__ == "0.0.5"

trackio/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
def init(project, name=None, config=None):
2424
if not current_server.get():
25-
url = launch_gradio()
25+
url = launch_gradio(show_api=False, inline=False, quiet=True)
2626
print(f"* Trackio server launched at: {url}")
27+
print(f"** View project dashboard at: {url}?project={project}")
2728
current_server.set(url)
2829
else:
2930
url = current_server.get()

trackio/examples/fake-training.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import random
2+
3+
from tqdm import tqdm
4+
5+
import trackio as wandb
6+
7+
wandb.init(
8+
project="fake-training",
9+
name="test-run",
10+
config=dict(
11+
epochs=5,
12+
learning_rate=0.001,
13+
batch_size=32,
14+
),
15+
)
16+
17+
EPOCHS = 5
18+
NUM_TRAIN_BATCHES = 100
19+
NUM_VAL_BATCHES = 20
20+
21+
for epoch in range(EPOCHS):
22+
train_loss = 0
23+
train_accuracy = 0
24+
val_loss = 0
25+
val_accuracy = 0
26+
27+
for _ in tqdm(range(NUM_TRAIN_BATCHES), desc=f"Epoch {epoch + 1} - Training"):
28+
loss = random.uniform(0.2, 1.0)
29+
accuracy = random.uniform(0.6, 0.95)
30+
train_loss += loss
31+
train_accuracy += accuracy
32+
33+
for _ in tqdm(range(NUM_VAL_BATCHES), desc=f"Epoch {epoch + 1} - Validation"):
34+
loss = random.uniform(0.2, 0.9)
35+
accuracy = random.uniform(0.65, 0.98)
36+
val_loss += loss
37+
val_accuracy += accuracy
38+
39+
train_loss /= NUM_TRAIN_BATCHES
40+
train_accuracy /= NUM_TRAIN_BATCHES
41+
val_loss /= NUM_VAL_BATCHES
42+
val_accuracy /= NUM_VAL_BATCHES
43+
44+
wandb.log(
45+
{
46+
"epoch": epoch + 1,
47+
"train_loss": train_loss,
48+
"train_accuracy": train_accuracy,
49+
"val_loss": val_loss,
50+
"val_accuracy": val_accuracy,
51+
}
52+
)
53+
54+
wandb.finish()

trackio/ui.py

Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
from trackio.utils import RESERVED_KEYS
88

99

10-
def get_projects():
10+
def get_projects(request: gr.Request):
1111
storage = SQLiteStorage("", "", {})
1212
projects = storage.get_projects()
13+
if project := request.query_params.get("project"):
14+
pass
15+
else:
16+
project = projects[0] if projects else None
1317
return gr.Dropdown(
14-
label="Project", choices=projects, value=projects[0] if projects else None
18+
label="Project",
19+
choices=projects,
20+
value=project,
21+
allow_custom_value=True,
1522
)
1623

1724

@@ -55,70 +62,71 @@ def log(project: str, run: str, metrics: dict[str, Any]) -> None:
5562
storage.log(metrics)
5663

5764

58-
def launch_gradio() -> str:
59-
with gr.Blocks(theme="citrus") as demo:
60-
with gr.Sidebar():
61-
gr.Markdown("# 🎯 Trackio Dashboard")
62-
project_dd = gr.Dropdown(label="Project")
63-
gr.Markdown("### ⚙️ Settings")
64-
realtime_cb = gr.Checkbox(label="Refresh realtime", value=True)
65-
with gr.Row():
66-
run_dd = gr.Dropdown(label="Run", choices=[], multiselect=True)
67-
68-
timer = gr.Timer(value=1)
69-
70-
gr.on(
71-
[demo.load, timer.tick],
72-
fn=get_projects,
73-
outputs=project_dd,
74-
show_progress="hidden",
75-
)
76-
gr.on(
77-
[demo.load, project_dd.change, timer.tick],
78-
fn=update_runs,
79-
inputs=project_dd,
80-
outputs=run_dd,
81-
show_progress="hidden",
82-
)
83-
realtime_cb.change(
84-
fn=toggle_timer,
85-
inputs=realtime_cb,
86-
outputs=timer,
87-
api_name="toggle_timer",
88-
)
89-
90-
gr.api(
91-
fn=log,
92-
api_name="log",
93-
)
94-
95-
@gr.render(
96-
triggers=[run_dd.change, timer.tick],
97-
inputs=[project_dd, run_dd],
98-
)
99-
def update_dashboard(project, runs):
100-
dfs = []
101-
for run in runs:
102-
df = load_run_data(project, run)
103-
if df is not None:
104-
df["run"] = run
105-
dfs.append(df)
106-
if dfs:
107-
master_df = pd.concat(dfs, ignore_index=True)
108-
else:
109-
master_df = pd.DataFrame()
110-
numeric_cols = master_df.select_dtypes(include="number").columns
111-
numeric_cols = [c for c in numeric_cols if c not in RESERVED_KEYS]
112-
for col in numeric_cols:
113-
gr.LinePlot(
114-
master_df,
115-
x="step",
116-
y=col,
117-
color="run" if "run" in master_df.columns else None,
118-
title=col,
119-
)
120-
121-
_, url, _ = demo.launch(show_api=False, inline=False, quiet=True)
65+
with gr.Blocks(theme="citrus") as demo:
66+
with gr.Sidebar():
67+
gr.Markdown("# 🎯 Trackio Dashboard")
68+
project_dd = gr.Dropdown(label="Project")
69+
gr.Markdown("### ⚙️ Settings")
70+
realtime_cb = gr.Checkbox(label="Refresh realtime", value=True)
71+
with gr.Row():
72+
run_dd = gr.Dropdown(label="Run", choices=[], multiselect=True)
73+
74+
timer = gr.Timer(value=1)
75+
76+
gr.on(
77+
[demo.load, timer.tick],
78+
fn=get_projects,
79+
outputs=project_dd,
80+
show_progress="hidden",
81+
)
82+
gr.on(
83+
[demo.load, project_dd.change, timer.tick],
84+
fn=update_runs,
85+
inputs=project_dd,
86+
outputs=run_dd,
87+
show_progress="hidden",
88+
)
89+
realtime_cb.change(
90+
fn=toggle_timer,
91+
inputs=realtime_cb,
92+
outputs=timer,
93+
api_name="toggle_timer",
94+
)
95+
96+
gr.api(
97+
fn=log,
98+
api_name="log",
99+
)
100+
101+
@gr.render(
102+
triggers=[run_dd.change, timer.tick],
103+
inputs=[project_dd, run_dd],
104+
)
105+
def update_dashboard(project, runs):
106+
dfs = []
107+
for run in runs:
108+
df = load_run_data(project, run)
109+
if df is not None:
110+
df["run"] = run
111+
dfs.append(df)
112+
if dfs:
113+
master_df = pd.concat(dfs, ignore_index=True)
114+
else:
115+
master_df = pd.DataFrame()
116+
numeric_cols = master_df.select_dtypes(include="number").columns
117+
numeric_cols = [c for c in numeric_cols if c not in RESERVED_KEYS]
118+
for col in numeric_cols:
119+
gr.LinePlot(
120+
master_df,
121+
x="step",
122+
y=col,
123+
color="run" if "run" in master_df.columns else None,
124+
title=col,
125+
)
126+
127+
128+
def launch_gradio(**kwargs) -> str:
129+
_, url, _ = demo.launch(**kwargs)
122130
return url
123131

124132

trackio/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.4
1+
0.0.5

0 commit comments

Comments
 (0)