# utils.py import numpy as np from pathlib import Path from typing import List, Tuple, Optional import torch import config def get_available_models() -> List[str]: """Lấy danh sách tất cả model trong folder models""" models_dir = Path(config.CONFIG['models_dir']) model_files = list(models_dir.glob("*.pth")) return sorted([f.name for f in model_files]) def validate_model_file(model_path: str) -> bool: """Kiểm tra xem file model có hợp lệ không""" path = Path(model_path) if not path.exists(): return False if path.suffix != '.pth': return False if path.stat().st_size < 1000: # File quá nhỏ return False return True def format_time(seconds: float) -> str: """Format thời gian từ giây sang HH:MM:SS""" hours = int(seconds // 3600) minutes = int((seconds % 3600) // 60) secs = int(seconds % 60) if hours > 0: return f"{hours}h {minutes}m {secs}s" elif minutes > 0: return f"{minutes}m {secs}s" else: return f"{secs}s" def get_color_for_value(color_val: int) -> str: """Lấy màu hex từ giá trị color""" return config.COLORS_MAP.get(color_val, '#ffffff') def create_bottle_html(bottle_state: np.ndarray, bottle_idx: int, selected: bool = False) -> str: """Tạo HTML cho một chai""" border_color = '#FFD700' if selected else '#333' border_width = '3' if selected else '2' html = f'
Chai {bottle_idx}
' html += '