Mercurial > repos > goeckslab > image_learner
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 16:8729f69e9207 | 17:db9be962dc13 |
|---|---|
| 1 import base64 | 1 import base64 |
| 2 import json | 2 import json |
| 3 from typing import Any, Dict, Optional | 3 from typing import Any, Dict, List, Optional |
| 4 | 4 |
| 5 from constants import METRIC_DISPLAY_NAMES | 5 from constants import METRIC_DISPLAY_NAMES |
| 6 from utils import detect_output_type, extract_metrics_from_json | 6 from utils import detect_output_type, extract_metrics_from_json |
| 7 | 7 |
| 8 | 8 |
| 21 training_progress: dict = None, | 21 training_progress: dict = None, |
| 22 output_type: Optional[str] = None, | 22 output_type: Optional[str] = None, |
| 23 ) -> str: | 23 ) -> str: |
| 24 display_keys = [ | 24 display_keys = [ |
| 25 "architecture", | 25 "architecture", |
| 26 "image_size", | |
| 26 "pretrained", | 27 "pretrained", |
| 27 "trainable", | 28 "trainable", |
| 28 "target_column", | 29 "target_column", |
| 29 "task_type", | 30 "task_type", |
| 30 "validation_metric", | 31 "validation_metric", |
| 56 if val == 0.5: | 57 if val == 0.5: |
| 57 val_str += " (default)" | 58 val_str += " (default)" |
| 58 else: | 59 else: |
| 59 if key == "task_type": | 60 if key == "task_type": |
| 60 val_str = val.title() if isinstance(val, str) else "N/A" | 61 val_str = val.title() if isinstance(val, str) else "N/A" |
| 62 elif key == "image_size": | |
| 63 if val is None: | |
| 64 val_str = "N/A" | |
| 65 elif isinstance(val, (list, tuple)) and len(val) == 2: | |
| 66 val_str = f"{val[0]}x{val[1]}" | |
| 67 elif isinstance(val, str) and val.lower() == "original": | |
| 68 val_str = "Original (no resize)" | |
| 69 else: | |
| 70 val_str = str(val) | |
| 61 elif key == "batch_size": | 71 elif key == "batch_size": |
| 62 if isinstance(val, (int, float)): | 72 if isinstance(val, (int, float)): |
| 63 val_str = int(val) | 73 val_str = int(val) |
| 64 else: | 74 else: |
| 65 val = "auto" | 75 val = "auto" |
| 113 "See <a href='https://ludwig.ai/latest/configuration/trainer/" | 123 "See <a href='https://ludwig.ai/latest/configuration/trainer/" |
| 114 "#trainer-parameters' target='_blank'>" | 124 "#trainer-parameters' target='_blank'>" |
| 115 "Ludwig Trainer Parameters</a> for details." | 125 "Ludwig Trainer Parameters</a> for details." |
| 116 "</span>" | 126 "</span>" |
| 117 ) | 127 ) |
| 128 elif key == "validation_metric": | |
| 129 if val is not None: | |
| 130 val_str = METRIC_DISPLAY_NAMES.get(str(val), str(val)) | |
| 131 else: | |
| 132 val_str = "N/A" | |
| 118 elif key == "epochs": | 133 elif key == "epochs": |
| 119 if val is None: | 134 if val is None: |
| 120 val_str = "N/A" | 135 val_str = "N/A" |
| 121 else: | 136 else: |
| 122 if ( | 137 if ( |
| 727 "});" | 742 "});" |
| 728 "</script>" | 743 "</script>" |
| 729 ) | 744 ) |
| 730 return modal_html + modal_js | 745 return modal_html + modal_js |
| 731 | 746 |
| 747 | |
| 748 def format_dataset_overview_table(rows: List[Dict[str, Any]], regression_mode: bool = False) -> str: | |
| 749 """Render a dataset overview table. | |
| 750 | |
| 751 - Classification: per-label distribution across train/val/test. | |
| 752 - Regression: split counts (train/val/test). | |
| 753 """ | |
| 754 heading = "<h2 style='text-align: center;'>Dataset Overview</h2>" | |
| 755 if not rows: | |
| 756 return heading + "<p style='text-align: center; color: #666;'>Dataset overview unavailable.</p><br>" | |
| 757 | |
| 758 if regression_mode: | |
| 759 headers = ["Split", "Count"] | |
| 760 html = ( | |
| 761 heading | |
| 762 + "<div style='display: flex; justify-content: center;'>" | |
| 763 + "<table class='performance-summary' style='border-collapse: collapse; table-layout: fixed;'>" | |
| 764 + "<thead><tr>" | |
| 765 + "".join( | |
| 766 f"<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>{h}</th>" | |
| 767 for h in headers | |
| 768 ) | |
| 769 + "</tr></thead><tbody>" | |
| 770 ) | |
| 771 for row in rows: | |
| 772 html += generate_table_row( | |
| 773 [ | |
| 774 row.get("split", "N/A"), | |
| 775 row.get("count", 0), | |
| 776 ], | |
| 777 "padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;", | |
| 778 ) | |
| 779 html += "</tbody></table></div><br>" | |
| 780 else: | |
| 781 html = ( | |
| 782 heading | |
| 783 + "<div style='display: flex; justify-content: center;'>" | |
| 784 + "<table class='performance-summary' style='border-collapse: collapse; table-layout: fixed;'>" | |
| 785 + "<thead><tr>" | |
| 786 + "<th style='padding: 10px; border: 1px solid #ccc; text-align: left; white-space: nowrap;'>Label</th>" | |
| 787 + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Train</th>" | |
| 788 + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Validation</th>" | |
| 789 + "<th style='padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;'>Test</th>" | |
| 790 + "</tr></thead><tbody>" | |
| 791 ) | |
| 792 for row in rows: | |
| 793 html += generate_table_row( | |
| 794 [ | |
| 795 row.get("label", "N/A"), | |
| 796 row.get("train", 0), | |
| 797 row.get("validation", 0), | |
| 798 row.get("test", 0), | |
| 799 ], | |
| 800 "padding: 10px; border: 1px solid #ccc; text-align: center; white-space: nowrap;", | |
| 801 ) | |
| 802 html += "</tbody></table></div><br>" | |
| 803 return html | |
| 804 | |
| 732 # ----------------------------------------- | 805 # ----------------------------------------- |
| 733 # MODEL PERFORMANCE (Train/Val/Test) TABLE | 806 # MODEL PERFORMANCE (Train/Val/Test) TABLE |
| 734 # ----------------------------------------- | 807 # ----------------------------------------- |
| 735 | 808 |
| 736 | 809 |
