#!/usr/bin/env python3 """Demo of pip-style training progress bar""" import sys import time def format_time(seconds): """Format seconds into HH:MM:SS or MM:SS format""" hours = int(seconds // 3600) minutes = int((seconds % 3600) // 60) secs = int(seconds % 60) if hours > 0: return f"{hours:02d}:{minutes:02d}:{secs:02d}" return f"{minutes:02d}:{secs:02d}" def create_bar(filled, total, width=30): """Create a visual progress bar""" ratio = filled / total if total > 0 else 0 filled_width = int(width * ratio) bar = "█" * filled_width + "░" * (width - filled_width) return bar # Demo: simulate training progress print("Demo: Pip-style training progress bar\n") start_time = time.time() EPOCHS = 100 for epoch in range(0, EPOCHS + 1, 10): completed = epoch total = EPOCHS percentage = (completed / total * 100) if total > 0 else 0 elapsed = time.time() - start_time if completed > 0: per_epoch_time = elapsed / completed remaining_epochs = total - completed eta = per_epoch_time * remaining_epochs else: eta = 0 bar = create_bar(completed, total) loss = 0.5 - (epoch * 0.003) speed = 24.5 progress_line = ( f"\rtraining: {percentage:5.1f}%|{bar}| " f"{completed}/{total} " f"[{format_time(elapsed)}<{format_time(eta)}, " f"{(completed/elapsed) if elapsed > 0 else 0:.2f} epoch/s] " f"loss={loss:.4f} {speed:.2f}img/s" ) sys.stdout.write(progress_line) sys.stdout.flush() time.sleep(0.3) # Final elapsed = time.time() - start_time bar = create_bar(EPOCHS, EPOCHS) percentage = 100.0 loss = 0.2 speed = 24.5 progress_line = ( f"\rtraining: {percentage:5.1f}%|{bar}| " f"{EPOCHS}/{EPOCHS} " f"[{format_time(elapsed)}<00:00, " f"{(EPOCHS/elapsed) if elapsed > 0 else 0:.2f} epoch/s] " f"loss={loss:.4f} {speed:.2f}img/s\n" ) sys.stdout.write(progress_line) sys.stdout.flush() print("✓ Progress bar demo completed!")