@@ -28,8 +28,32 @@ def get_current_time(timezone_str: str = 'UTC') -> datetime:
2828ERROR_NOT_CONNECTED = 0x407 # 1031
2929ERROR_UNSPECIFIED = 0x500 # 1280
3030
31- # Available cloud conditions from ML model
32- ALL_CLOUD_CONDITIONS = ['Clear' , 'Mostly Cloudy' , 'Overcast' , 'Rain' , 'Snow' , 'Wisps of clouds' ]
31+ # Dynamically load cloud conditions from labels file
32+ def load_labels ():
33+ """Load cloud condition labels from labels.txt file"""
34+ label_path = os .environ .get ('LABEL_PATH' , 'labels.txt' )
35+ try :
36+ if os .path .exists (label_path ):
37+ with open (label_path , 'r' ) as f :
38+ labels = []
39+ for line in f :
40+ clean_line = line .strip ()
41+ # Handle "0 Clear" format if present
42+ if " " in clean_line and clean_line .split (" " , 1 )[0 ].isdigit ():
43+ clean_line = clean_line .split (" " , 1 )[1 ]
44+ if clean_line :
45+ labels .append (clean_line )
46+ logger .info (f"Loaded { len (labels )} classes from { label_path } " )
47+ return labels
48+ except Exception as e :
49+ logger .error (f"Failed to load labels from { label_path } : { e } " )
50+
51+ # Fallback to defaults if file missing or error
52+ logger .warning ("Using fallback default cloud conditions" )
53+ return ['Clear' , 'Mostly Cloudy' , 'Overcast' , 'Rain' , 'Snow' , 'Wisps of clouds' ]
54+
55+ # Available cloud conditions from ML model (loaded dynamically from labels.txt)
56+ ALL_CLOUD_CONDITIONS = load_labels ()
3357
3458
3559@dataclass
0 commit comments