Spaces:
Sleeping
Sleeping
Update ui.py
Browse filesadd smothing parameters
ui.py
CHANGED
@@ -87,7 +87,13 @@ def get_available_metrics(project: str, runs: list[str]) -> list[str]:
|
|
87 |
return result
|
88 |
|
89 |
|
90 |
-
def load_run_data(
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
if not project or not run:
|
92 |
return None
|
93 |
metrics = SQLiteStorage.get_metrics(project, run)
|
@@ -108,7 +114,7 @@ def load_run_data(project: str | None, run: str | None, smoothing: bool, x_axis:
|
|
108 |
else:
|
109 |
x_column = x_axis
|
110 |
|
111 |
-
if
|
112 |
numeric_cols = df.select_dtypes(include="number").columns
|
113 |
numeric_cols = [c for c in numeric_cols if c not in RESERVED_KEYS]
|
114 |
|
@@ -117,23 +123,32 @@ def load_run_data(project: str | None, run: str | None, smoothing: bool, x_axis:
|
|
117 |
df_original["data_type"] = "original"
|
118 |
|
119 |
df_smoothed = df.copy()
|
120 |
-
|
121 |
-
|
122 |
-
df_smoothed[numeric_cols]
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
df_smoothed["run"] = f"{run}_smoothed"
|
127 |
df_smoothed["data_type"] = "smoothed"
|
128 |
|
129 |
combined_df = pd.concat([df_original, df_smoothed], ignore_index=True)
|
130 |
combined_df["x_axis"] = x_column
|
131 |
return combined_df
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
return df
|
137 |
|
138 |
|
139 |
def update_runs(project, filter_text, user_interacted_with_runs=False):
|
@@ -176,6 +191,28 @@ def toggle_timer(cb_value):
|
|
176 |
return gr.Timer(active=False)
|
177 |
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
def check_auth(hf_token: str | None) -> None:
|
180 |
if os.getenv("SYSTEM") == "spaces": # if we are running in Spaces
|
181 |
# check auth token passed in
|
@@ -308,7 +345,19 @@ with gr.Blocks(theme="citrus", title="Trackio Dashboard", css=css) as demo:
|
|
308 |
)
|
309 |
gr.HTML("<hr>")
|
310 |
realtime_cb = gr.Checkbox(label="Refresh metrics realtime", value=True)
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
x_axis_dd = gr.Dropdown(
|
313 |
label="X-axis",
|
314 |
choices=["step", "time"],
|
@@ -354,6 +403,11 @@ with gr.Blocks(theme="citrus", title="Trackio Dashboard", css=css) as demo:
|
|
354 |
outputs=timer,
|
355 |
api_name="toggle_timer",
|
356 |
)
|
|
|
|
|
|
|
|
|
|
|
357 |
run_cb.input(
|
358 |
fn=lambda: True,
|
359 |
outputs=user_interacted_with_run_cb,
|
@@ -398,19 +452,36 @@ with gr.Blocks(theme="citrus", title="Trackio Dashboard", css=css) as demo:
|
|
398 |
demo.load,
|
399 |
run_cb.change,
|
400 |
last_steps.change,
|
401 |
-
|
|
|
402 |
x_lim.change,
|
403 |
x_axis_dd.change,
|
404 |
],
|
405 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
show_progress="hidden",
|
407 |
)
|
408 |
-
def update_dashboard(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
dfs = []
|
410 |
original_runs = runs.copy()
|
411 |
|
412 |
for run in runs:
|
413 |
-
df = load_run_data(project, run,
|
414 |
if df is not None:
|
415 |
dfs.append(df)
|
416 |
|
@@ -432,7 +503,7 @@ with gr.Blocks(theme="citrus", title="Trackio Dashboard", css=css) as demo:
|
|
432 |
numeric_cols = [c for c in numeric_cols if c in metrics_subset]
|
433 |
|
434 |
numeric_cols = sort_metrics_by_prefix(list(numeric_cols))
|
435 |
-
color_map = get_color_mapping(original_runs,
|
436 |
|
437 |
with gr.Row(key="row"):
|
438 |
for metric_idx, metric_name in enumerate(numeric_cols):
|
@@ -461,4 +532,4 @@ with gr.Blocks(theme="citrus", title="Trackio Dashboard", css=css) as demo:
|
|
461 |
|
462 |
|
463 |
if __name__ == "__main__":
|
464 |
-
demo.launch(allowed_paths=[TRACKIO_LOGO_PATH], show_api=False, show_error=True)
|
|
|
87 |
return result
|
88 |
|
89 |
|
90 |
+
def load_run_data(
|
91 |
+
project: str | None,
|
92 |
+
run: str | None,
|
93 |
+
smoothing_method: str,
|
94 |
+
smoothing_value: float,
|
95 |
+
x_axis: str,
|
96 |
+
) -> pd.DataFrame | None:
|
97 |
if not project or not run:
|
98 |
return None
|
99 |
metrics = SQLiteStorage.get_metrics(project, run)
|
|
|
114 |
else:
|
115 |
x_column = x_axis
|
116 |
|
117 |
+
if smoothing_method != "None":
|
118 |
numeric_cols = df.select_dtypes(include="number").columns
|
119 |
numeric_cols = [c for c in numeric_cols if c not in RESERVED_KEYS]
|
120 |
|
|
|
123 |
df_original["data_type"] = "original"
|
124 |
|
125 |
df_smoothed = df.copy()
|
126 |
+
if smoothing_method == "SMA":
|
127 |
+
window_size = max(1, int(smoothing_value))
|
128 |
+
df_smoothed[numeric_cols] = (
|
129 |
+
df_smoothed[numeric_cols]
|
130 |
+
.rolling(window=window_size, center=True, min_periods=1)
|
131 |
+
.mean()
|
132 |
+
)
|
133 |
+
elif smoothing_method == "EMA":
|
134 |
+
alpha = max(0.0, min(1.0, float(smoothing_value)))
|
135 |
+
df_smoothed[numeric_cols] = (
|
136 |
+
df_smoothed[numeric_cols]
|
137 |
+
.ewm(alpha=alpha, adjust=False)
|
138 |
+
.mean()
|
139 |
+
)
|
140 |
+
else:
|
141 |
+
df_smoothed = df_original.copy()
|
142 |
df_smoothed["run"] = f"{run}_smoothed"
|
143 |
df_smoothed["data_type"] = "smoothed"
|
144 |
|
145 |
combined_df = pd.concat([df_original, df_smoothed], ignore_index=True)
|
146 |
combined_df["x_axis"] = x_column
|
147 |
return combined_df
|
148 |
+
df["run"] = run
|
149 |
+
df["data_type"] = "original"
|
150 |
+
df["x_axis"] = x_column
|
151 |
+
return df
|
|
|
152 |
|
153 |
|
154 |
def update_runs(project, filter_text, user_interacted_with_runs=False):
|
|
|
191 |
return gr.Timer(active=False)
|
192 |
|
193 |
|
194 |
+
def toggle_smoothing_slider(method: str):
|
195 |
+
if method == "SMA":
|
196 |
+
return gr.update(
|
197 |
+
interactive=True,
|
198 |
+
label="SMA window",
|
199 |
+
minimum=1,
|
200 |
+
maximum=100,
|
201 |
+
step=1,
|
202 |
+
value=10,
|
203 |
+
)
|
204 |
+
if method == "EMA":
|
205 |
+
return gr.update(
|
206 |
+
interactive=True,
|
207 |
+
label="EMA alpha",
|
208 |
+
minimum=0.0,
|
209 |
+
maximum=1.0,
|
210 |
+
step=0.01,
|
211 |
+
value=0.5,
|
212 |
+
)
|
213 |
+
return gr.update(interactive=False, label="Smoothing parameter")
|
214 |
+
|
215 |
+
|
216 |
def check_auth(hf_token: str | None) -> None:
|
217 |
if os.getenv("SYSTEM") == "spaces": # if we are running in Spaces
|
218 |
# check auth token passed in
|
|
|
345 |
)
|
346 |
gr.HTML("<hr>")
|
347 |
realtime_cb = gr.Checkbox(label="Refresh metrics realtime", value=True)
|
348 |
+
smoothing_method_dd = gr.Dropdown(
|
349 |
+
label="Smoothing",
|
350 |
+
choices=["None", "SMA", "EMA"],
|
351 |
+
value="None",
|
352 |
+
)
|
353 |
+
smoothing_slider = gr.Slider(
|
354 |
+
label="Smoothing parameter",
|
355 |
+
minimum=1,
|
356 |
+
maximum=100,
|
357 |
+
step=1,
|
358 |
+
value=10,
|
359 |
+
interactive=False,
|
360 |
+
)
|
361 |
x_axis_dd = gr.Dropdown(
|
362 |
label="X-axis",
|
363 |
choices=["step", "time"],
|
|
|
403 |
outputs=timer,
|
404 |
api_name="toggle_timer",
|
405 |
)
|
406 |
+
smoothing_method_dd.change(
|
407 |
+
fn=toggle_smoothing_slider,
|
408 |
+
inputs=smoothing_method_dd,
|
409 |
+
outputs=smoothing_slider,
|
410 |
+
)
|
411 |
run_cb.input(
|
412 |
fn=lambda: True,
|
413 |
outputs=user_interacted_with_run_cb,
|
|
|
452 |
demo.load,
|
453 |
run_cb.change,
|
454 |
last_steps.change,
|
455 |
+
smoothing_method_dd.change,
|
456 |
+
smoothing_slider.change,
|
457 |
x_lim.change,
|
458 |
x_axis_dd.change,
|
459 |
],
|
460 |
+
inputs=[
|
461 |
+
project_dd,
|
462 |
+
run_cb,
|
463 |
+
smoothing_method_dd,
|
464 |
+
smoothing_slider,
|
465 |
+
metrics_subset,
|
466 |
+
x_lim,
|
467 |
+
x_axis_dd,
|
468 |
+
],
|
469 |
show_progress="hidden",
|
470 |
)
|
471 |
+
def update_dashboard(
|
472 |
+
project,
|
473 |
+
runs,
|
474 |
+
smoothing_method,
|
475 |
+
smoothing_value,
|
476 |
+
metrics_subset,
|
477 |
+
x_lim_value,
|
478 |
+
x_axis,
|
479 |
+
):
|
480 |
dfs = []
|
481 |
original_runs = runs.copy()
|
482 |
|
483 |
for run in runs:
|
484 |
+
df = load_run_data(project, run, smoothing_method, smoothing_value, x_axis)
|
485 |
if df is not None:
|
486 |
dfs.append(df)
|
487 |
|
|
|
503 |
numeric_cols = [c for c in numeric_cols if c in metrics_subset]
|
504 |
|
505 |
numeric_cols = sort_metrics_by_prefix(list(numeric_cols))
|
506 |
+
color_map = get_color_mapping(original_runs, smoothing_method != "None")
|
507 |
|
508 |
with gr.Row(key="row"):
|
509 |
for metric_idx, metric_name in enumerate(numeric_cols):
|
|
|
532 |
|
533 |
|
534 |
if __name__ == "__main__":
|
535 |
+
demo.launch(allowed_paths=[TRACKIO_LOGO_PATH], show_api=False, show_error=True)
|