Overview
The UI components API provides pre-built, reusable Streamlit components for building consistent and interactive ML training interfaces, including headers, sidebars, model cards, and experiment rows.
Render the persistent header section shown on all pages. Contains app title, session selector, configuration status indicators, and session controls.
from components.header import render_header
render_header()
Features:
- App title and branding
- Configuration status indicators (Dataset, Model, Training)
- Session selector dropdown (with past sessions)
- New session button
File reference: app/components/header.py:23
Configuration Status Indicators:
- ✅ Green checkmark = Step completed
- ⬜ Gray box = Step not completed
import streamlit as st
from components.header import render_header
st.set_page_config(page_title="My ML App", layout="wide")
render_header()
Render the persistent sidebar shown on all pages. Displays system resources, theme settings, and session actions.
from components.sidebar import render_sidebar
render_sidebar()
Features:
- Compute device information (CUDA/MPS/CPU)
- GPU memory usage
- System RAM usage
- CPU cores and threads
- Platform information
- Theme customization settings
- Delete session button
File reference: app/components/sidebar.py:18
Example:
import streamlit as st
from components.sidebar import render_sidebar
st.set_page_config(layout="wide")
with st.sidebar:
render_sidebar()
Model Card Component
render_model_card(model, on_edit, on_delete, is_selected)
Render a single model card with actions.
Model dictionary with id, name, model_type, created_at, and config
Callback function when edit button is clicked (receives model_id)
Callback function when delete button is clicked (receives model_id)
Whether this card is currently selected
from components.model_card import render_model_card
model = {
"id": "model_a3f8b2c1",
"name": "ResNet50 Transfer",
"model_type": "Transfer Learning",
"created_at": "2026-03-04T10:30:00",
"config": {
"transfer_config": {
"base_model": "ResNet50",
"strategy": "Fine-tuning"
}
}
}
def handle_edit(model_id):
print(f"Editing model: {model_id}")
def handle_delete(model_id):
print(f"Deleting model: {model_id}")
clicked = render_model_card(
model,
on_edit=handle_edit,
on_delete=handle_delete,
is_selected=True
)
if clicked:
print("Card was clicked for selection")
Returns: bool - True if the card was clicked (for selection)
File reference: app/components/model_card.py:17
Model Card Visual Features:
- Model type icon (🔧 Custom CNN, 🎯 Transfer Learning, 🧪 Transformer)
- Model name and type
- Creation date
- Configuration summary subtitle
- Select, Edit, and Delete buttons
- Green border when selected
render_model_library(models, selected_id, on_select, on_edit, on_delete, cards_per_row)
Render the full model library as a grid of cards.
List of model dictionaries
Currently selected model ID
Callback when a model is selected (receives model_id)
Callback when edit button is clicked (receives model_id)
Callback when delete button is clicked (receives model_id)
Number of cards to display per row
from components.model_card import render_model_library
from state.workflow import get_model_library
models = get_model_library()
def handle_select(model_id):
st.session_state.selected_model = model_id
st.rerun()
render_model_library(
models=models,
selected_id=st.session_state.get("selected_model"),
on_select=handle_select,
cards_per_row=3
)
File reference: app/components/model_card.py:116
Experiment Row Component
render_experiment_row(experiment, models, trainings, callbacks…)
Render a single experiment row with status, metrics, and action buttons.
Experiment dictionary with id, name, model_id, training_id, status, and metrics
List of available model configurations
List of available training configurations
Callback when experiment configuration changes (receives exp_id, updates)
Callback to delete experiment (receives exp_id)
Callback to start/resume training (receives exp_id)
Callback to pause training (receives exp_id)
Callback to stop training (receives exp_id)
Callback to view results (receives exp_id)
from components.experiment_row import render_experiment_row
from state.workflow import get_experiments, get_model_library, get_training_library
experiments = get_experiments()
models = get_model_library()
trainings = get_training_library()
def handle_start(exp_id):
# Start training logic
pass
def handle_delete(exp_id):
from state.workflow import delete_experiment
delete_experiment(exp_id)
st.rerun()
for exp in experiments:
render_experiment_row(
experiment=exp,
models=models,
trainings=trainings,
on_start=handle_start,
on_delete=handle_delete
)
File reference: app/components/experiment_row.py:18
Experiment Status Icons:
- ⚪ Ready - Ready to start training
- 🔄 Training - Currently training
- ⏸️ Paused - Training paused
- ✅ Completed - Training finished successfully
- ❌ Failed - Training failed with error
Dynamic Features by Status:
Ready Status:
- Model and training config dropdowns
- START TRAINING button
- Delete button
Training Status:
- Progress bars (epoch and batch)
- Live metrics (train loss, train acc, val loss, val acc)
- Delta indicators showing improvement
- Pause, Stop, and Save buttons
Completed Status:
- Final metrics display
- Best epoch indicator
- Training duration
- View Results button
- Delete button
Theme Component
render_theme_settings()
Render theme customization settings in an expander.
from components.theme import render_theme_settings
with st.sidebar:
render_theme_settings()
Features:
- Color pickers for primary, secondary, and background colors
- Preset themes (Soft Green, Soft Blue, Soft Pink, Soft Orange)
- Live preview with automatic page rerun
File reference: app/components/theme.py:18
Example with Custom Colors:
from state.ui import set_theme_colors
# Set custom theme programmatically
set_theme_colors(
primary="#FF6B6B",
secondary="#4ECDC4",
background="#1A1A2E"
)
Utility Functions
get_compute_device()
Detect available compute device with detailed information.
from components.utils import get_compute_device
device = get_compute_device()
print(f"Type: {device['type']}") # "CUDA", "MPS", or "CPU"
print(f"Name: {device['name']}") # "NVIDIA RTX 3080", "Apple M1", etc.
print(f"Available: {device['available']}") # True/False
Returns: dict with keys:
type: str - Device type (“CUDA”, “MPS”, or “CPU”)
name: str - Device name
available: bool - Whether device is available
File reference: app/components/utils.py:15
get_gpu_memory()
Get GPU memory information if available.
from components.utils import get_gpu_memory
memory = get_gpu_memory()
print(memory) # "4.2/8.0 GB" or "Unified" (MPS) or "N/A"
Returns: str - Formatted memory string
File reference: app/components/utils.py:61
get_system_memory()
Get system RAM information.
from components.utils import get_system_memory
memory = get_system_memory()
print(memory) # "8.4/16.0 GB"
Returns: str - Formatted memory string (used/total GB)
File reference: app/components/utils.py:77
get_cpu_info()
Get CPU information including cores, threads, and usage.
from components.utils import get_cpu_info
info = get_cpu_info()
print(f"Cores: {info['cores']}") # Physical cores
print(f"Threads: {info['threads']}") # Logical processors
print(f"Usage: {info['usage']}%") # Current CPU usage
Returns: dict with keys:
cores: int - Physical CPU cores
threads: int - Logical processors
usage: float - Current CPU usage percentage
File reference: app/components/utils.py:88
Get platform/OS information.
from components.utils import get_platform_info
platform = get_platform_info()
print(platform) # "macOS 14.0", "Linux", "Windows 11", etc.
Returns: str - Platform string
File reference: app/components/utils.py:100
clear_session()
Clear all session state (workflow + cache) while preserving UI preferences. Saves the current session to disk before clearing.
from components.utils import clear_session
clear_session()
# Session saved, state cleared, and reinitialized
File reference: app/components/utils.py:124
Pre-defined tooltip messages for UI components:
from components.tooltips import HEADER_TOOLTIPS, SIDEBAR_TOOLTIPS
# Header tooltips
HEADER_TOOLTIPS = {
"new_session": "Create a new session and start fresh"
}
# Sidebar tooltips
SIDEBAR_TOOLTIPS = {
"system_resources": "Hardware resources available for training",
"gpu_memory": "GPU memory usage (allocated/total)",
"system_ram": "System RAM usage",
"cpu_info": "CPU cores and threads",
"platform": "Operating system information"
}
Usage Example:
import streamlit as st
from components.tooltips import SIDEBAR_TOOLTIPS
st.caption("GPU Memory", help=SIDEBAR_TOOLTIPS["gpu_memory"])
Model Icons
Icon mappings for different model types:
from components.model_card import MODEL_ICONS
# Available model icons
MODEL_ICONS = {
"Custom CNN": "🔧",
"Transformer": "🧪",
"Transfer Learning": "🎯",
}
# Usage
icon = MODEL_ICONS.get(model_type, "🧠") # Default to brain emoji
Experiment Status Configuration
Status configuration for experiment rows:
from components.experiment_row import STATUS_CONFIG
# Available status configurations
STATUS_CONFIG = {
"ready": {"icon": "⚪", "label": "Ready", "color": "gray"},
"training": {"icon": "🔄", "label": "Training", "color": "blue"},
"paused": {"icon": "⏸️", "label": "Paused", "color": "orange"},
"completed": {"icon": "✅", "label": "Completed", "color": "green"},
"failed": {"icon": "❌", "label": "Failed", "color": "red"},
}
# Usage
status = "training"
config = STATUS_CONFIG.get(status)
st.markdown(f"{config['icon']} {config['label']}")