|
14 | 14 | try: |
15 | 15 | import trackio.utils as utils |
16 | 16 | from trackio.file_storage import FileStorage |
| 17 | + from trackio.histogram import Histogram |
17 | 18 | from trackio.media import TrackioImage, TrackioVideo |
18 | 19 | from trackio.sqlite_storage import SQLiteStorage |
19 | 20 | from trackio.table import Table |
|
25 | 26 | except ImportError: |
26 | 27 | import utils |
27 | 28 | from file_storage import FileStorage |
| 29 | + from histogram import Histogram |
28 | 30 | from media import TrackioImage, TrackioVideo |
29 | 31 | from sqlite_storage import SQLiteStorage |
30 | 32 | from table import Table |
@@ -1121,6 +1123,71 @@ def update_dashboard( |
1121 | 1123 | f"Column {metric_name} failed to render as a table: {e}" |
1122 | 1124 | ) |
1123 | 1125 |
|
| 1126 | + # Display histograms |
| 1127 | + histogram_cols = set(master_df.columns) - { |
| 1128 | + "run", |
| 1129 | + "step", |
| 1130 | + "timestamp", |
| 1131 | + "data_type", |
| 1132 | + } |
| 1133 | + if metrics_subset: |
| 1134 | + histogram_cols = [c for c in histogram_cols if c in metrics_subset] |
| 1135 | + if metric_filter and metric_filter.strip(): |
| 1136 | + histogram_cols = filter_metrics_by_regex( |
| 1137 | + list(histogram_cols), metric_filter |
| 1138 | + ) |
| 1139 | + |
| 1140 | + actual_histogram_count = sum( |
| 1141 | + 1 |
| 1142 | + for metric_name in histogram_cols |
| 1143 | + if not (metric_df := master_df.dropna(subset=[metric_name])).empty |
| 1144 | + and isinstance(value := metric_df[metric_name].iloc[-1], dict) |
| 1145 | + and value.get("_type") == Histogram.TYPE |
| 1146 | + ) |
| 1147 | + |
| 1148 | + if actual_histogram_count > 0: |
| 1149 | + with gr.Accordion(f"histograms ({actual_histogram_count})", open=True): |
| 1150 | + with gr.Row(key="histogram-row"): |
| 1151 | + for metric_idx, metric_name in enumerate(histogram_cols): |
| 1152 | + metric_df = master_df.dropna(subset=[metric_name]) |
| 1153 | + if not metric_df.empty: |
| 1154 | + value = metric_df[metric_name].iloc[-1] |
| 1155 | + if ( |
| 1156 | + isinstance(value, dict) |
| 1157 | + and "_type" in value |
| 1158 | + and value["_type"] == Histogram.TYPE |
| 1159 | + ): |
| 1160 | + try: |
| 1161 | + bins = value.get("bins", []) |
| 1162 | + values = value.get("values", []) |
| 1163 | + |
| 1164 | + if len(bins) > 0 and len(values) > 0: |
| 1165 | + bin_centers = [ |
| 1166 | + (bins[i] + bins[i + 1]) / 2 |
| 1167 | + for i in range(len(bins) - 1) |
| 1168 | + ] |
| 1169 | + |
| 1170 | + df = pd.DataFrame( |
| 1171 | + {"bin_center": bin_centers, "count": values} |
| 1172 | + ) |
| 1173 | + |
| 1174 | + gr.BarPlot( |
| 1175 | + df, |
| 1176 | + x="bin_center", |
| 1177 | + y="count", |
| 1178 | + title=f"{metric_name} (latest)", |
| 1179 | + x_title="Value", |
| 1180 | + y_title="Count", |
| 1181 | + key=f"histogram-{metric_idx}", |
| 1182 | + show_fullscreen_button=True, |
| 1183 | + min_width=400, |
| 1184 | + show_export_button=True, |
| 1185 | + ) |
| 1186 | + except Exception as e: |
| 1187 | + gr.Warning( |
| 1188 | + f"Column {metric_name} failed to render as a histogram: {e}" |
| 1189 | + ) |
| 1190 | + |
1124 | 1191 | with grouped_runs_panel: |
1125 | 1192 |
|
1126 | 1193 | @gr.render( |
|
0 commit comments