File size: 2,050 Bytes
5b86813
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/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!")