Spaces:
Runtime error
Runtime error
| # filename: utils/helpers.py | |
| import math | |
| def format_bytes(size_bytes: int) -> str: | |
| """Converts a size in bytes to a human-readable string.""" | |
| if not isinstance(size_bytes, int) or size_bytes <= 0: | |
| return "0 B" | |
| size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") | |
| i = min(int(math.log(size_bytes, 1024)), len(size_name) - 1) | |
| p = math.pow(1024, i) | |
| s = round(size_bytes / p, 2) | |
| return f"{s} {size_name[i]}" | |
| def create_progress_bar(progress: float) -> str: | |
| """Creates a text-based progress bar string. | |
| Args: | |
| progress: A float between 0.0 and 1.0. | |
| Returns: | |
| A string representing the progress bar e.g., '[ββββββββββ] 50%' | |
| """ | |
| if not (0.0 <= progress <= 1.0): | |
| progress = 0.0 | |
| bar_length = 10 | |
| filled_length = int(bar_length * progress) | |
| bar = 'β' * filled_length + 'β' * (bar_length - filled_length) | |
| percentage = f"{progress:.0%}" | |
| return f"[{bar}] {percentage}" | |