diff html_structure.py @ 17:db9be962dc13 draft default tip

planemo upload for repository https://github.com/goeckslab/gleam.git commit 9db874612b0c3e4f53d639459fe789b762660cd6
author goeckslab
date Wed, 10 Dec 2025 00:24:13 +0000
parents d17e3a1b8659
children
line wrap: on
line diff
--- a/html_structure.py	Wed Dec 03 01:28:52 2025 +0000
+++ b/html_structure.py	Wed Dec 10 00:24:13 2025 +0000
@@ -1,6 +1,6 @@
 import base64
 import json
-from typing import Any, Dict, Optional
+from typing import Any, Dict, List, Optional
 
 from constants import METRIC_DISPLAY_NAMES
 from utils import detect_output_type, extract_metrics_from_json
@@ -23,6 +23,7 @@
 ) -> str:
     display_keys = [
         "architecture",
+        "image_size",
         "pretrained",
         "trainable",
         "target_column",
@@ -58,6 +59,15 @@
         else:
             if key == "task_type":
                 val_str = val.title() if isinstance(val, str) else "N/A"
+            elif key == "image_size":
+                if val is None:
+                    val_str = "N/A"
+                elif isinstance(val, (list, tuple)) and len(val) == 2:
+                    val_str = f"{val[0]}x{val[1]}"
+                elif isinstance(val, str) and val.lower() == "original":
+                    val_str = "Original (no resize)"
+                else:
+                    val_str = str(val)
             elif key == "batch_size":
                 if isinstance(val, (int, float)):
                     val_str = int(val)
@@ -115,6 +125,11 @@
                             "Ludwig Trainer Parameters</a> for details."
                             "</span>"
                         )
+            elif key == "validation_metric":
+                if val is not None:
+                    val_str = METRIC_DISPLAY_NAMES.get(str(val), str(val))
+                else:
+                    val_str = "N/A"
             elif key == "epochs":
                 if val is None:
                     val_str = "N/A"
@@ -729,6 +744,64 @@
     )
     return modal_html + modal_js
 
+
+def format_dataset_overview_table(rows: List[Dict[str, Any]], regression_mode: bool = False) -> str:
+    """Render a dataset overview table.
+
+    - Classification: per-label distribution across train/val/test.
+    - Regression: split counts (train/val/test).
+    """
+    heading = "<h2 style='text-align: center;'>Dataset Overview</h2>"
+    if not rows:
+        return heading + "<p style='text-align: center; color: #666;'>Dataset overview unavailable.</p><br>"
+
+    if regression_mode:
+        headers = ["Split", "Count"]
+        html = (
+            heading
+            + "<div style='display: flex; justify-content: center;'>"
+            + "<table class='performance-summary' style='border-collapse: collapse; table-layout: fixed;'>"
+            + "<thead><tr>"
+            + "".join(
+                f"<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>{h}</th>"
+                for h in headers
+            )
+            + "</tr></thead><tbody>"
+        )
+        for row in rows:
+            html += generate_table_row(
+                [
+                    row.get("split", "N/A"),
+                    row.get("count", 0),
+                ],
+                "padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;",
+            )
+        html += "</tbody></table></div><br>"
+    else:
+        html = (
+            heading
+            + "<div style='display: flex; justify-content: center;'>"
+            + "<table class='performance-summary' style='border-collapse: collapse; table-layout: fixed;'>"
+            + "<thead><tr>"
+            + "<th style='padding: 10px; border: 1px solid #ccc; text-align: left; white-space: nowrap;'>Label</th>"
+            + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Train</th>"
+            + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Validation</th>"
+            + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Test</th>"
+            + "</tr></thead><tbody>"
+        )
+        for row in rows:
+            html += generate_table_row(
+                [
+                    row.get("label", "N/A"),
+                    row.get("train", 0),
+                    row.get("validation", 0),
+                    row.get("test", 0),
+                ],
+                "padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;",
+            )
+        html += "</tbody></table></div><br>"
+    return html
+
 # -----------------------------------------
 # MODEL PERFORMANCE (Train/Val/Test) TABLE
 # -----------------------------------------