cheikhaidev-ui Claude Sonnet 4.6 commited on
Commit
554fba2
·
1 Parent(s): 6273b40

fix(critical): align saison/peak_hour encoding + restore TensorFlow on HF

Browse files

- utils_simple.create_time_features(): fix saison from binary {0,1} to
3-season Dakar encoding {0,1,2} matching data_generator.get_season()
- utils_simple.create_time_features(): fix is_peak_hour to include 7-9h
morning peak matching data_generator.is_peak_hour()
- requirements-hf.txt: restore tensorflow-cpu==2.17.1 so LSTM loads on
HF Spaces (previously removed to avoid build timeout)
- Dockerfile: remove outdated comment about missing TensorFlow
- CLAUDE.md: document correct saison and is_peak_hour invariants

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

CLAUDE.md CHANGED
@@ -68,4 +68,5 @@ The LSTM expects shape `(1, 1, 9)` — single sample, single timestep, 9 feature
68
  - Models must be loaded from the project root (paths like `'models/lgbm_model.pkl'`). Always run the app from the repo root.
69
  - LSTM is loaded with `compile=False` then recompiled manually to avoid Keras serialization compatibility issues.
70
  - The app degrades gracefully: if LSTM fails to load, LightGBM prediction is used for both model slots.
71
- - `saison` encoding differs between `data_generator.py` (0/1/2 for Dakar's three seasons) and `utils_simple.py` (1/2/3/4 for four calendar seasons). Training data uses the 3-season encoding.
 
 
68
  - Models must be loaded from the project root (paths like `'models/lgbm_model.pkl'`). Always run the app from the repo root.
69
  - LSTM is loaded with `compile=False` then recompiled manually to avoid Keras serialization compatibility issues.
70
  - The app degrades gracefully: if LSTM fails to load, LightGBM prediction is used for both model slots.
71
+ - `saison` uses the 3-season Dakar encoding (0 = sèche fraîche Nov-Fév, 1 = sèche chaude Mar-Mai, 2 = pluies Jun-Oct) in both `data_generator.py` and `utils_simple.py`. Both must stay in sync.
72
+ - `is_peak_hour` = 1 for hours 7–9 and 18–21 (matching `data_generator.is_peak_hour()`). Both files must stay in sync.
Dockerfile CHANGED
@@ -13,7 +13,7 @@ COPY data ./data
13
  COPY src ./src
14
  COPY .streamlit ./.streamlit
15
 
16
- # Installer les dependances (sans TensorFlow pour eviter le timeout HF)
17
  RUN pip install --no-cache-dir -r requirements-hf.txt
18
 
19
  # Exposer le port
 
13
  COPY src ./src
14
  COPY .streamlit ./.streamlit
15
 
16
+ # Installer les dependances
17
  RUN pip install --no-cache-dir -r requirements-hf.txt
18
 
19
  # Exposer le port
requirements-hf.txt CHANGED
@@ -4,4 +4,5 @@ numpy==1.26.3
4
  plotly==5.18.0
5
  lightgbm==4.1.0
6
  scikit-learn==1.3.2
 
7
  requests
 
4
  plotly==5.18.0
5
  lightgbm==4.1.0
6
  scikit-learn==1.3.2
7
+ tensorflow-cpu==2.17.1
8
  requests
streamlit_app/utils_simple.py CHANGED
@@ -55,10 +55,15 @@ def load_models_cached():
55
  def create_time_features(date_time: datetime, hour_override: int = None) -> dict:
56
  hour = hour_override if hour_override is not None else date_time.hour
57
  month = date_time.month
58
- # Encodage binaire calé sur synthetic_data_v2.csv : saison pluies (Jun-Août) = 1, reste = 0
59
- saison = 1 if month in [6, 7, 8] else 0
60
- # is_peak_hour calé sur le CSV : heures 18-22 = 1 (soir uniquement)
61
- is_peak_hour = 1 if 18 <= hour <= 22 else 0
 
 
 
 
 
62
  return {
63
  'hour': hour,
64
  'day_of_week': date_time.weekday(),
 
55
  def create_time_features(date_time: datetime, hour_override: int = None) -> dict:
56
  hour = hour_override if hour_override is not None else date_time.hour
57
  month = date_time.month
58
+ # Encodage 3 saisons Dakar — doit correspondre exactement à data_generator.get_season()
59
+ if month in [11, 12, 1, 2]:
60
+ saison = 0 # Saison sèche fraîche
61
+ elif month in [3, 4, 5]:
62
+ saison = 1 # Saison sèche chaude
63
+ else:
64
+ saison = 2 # Saison des pluies (Jun-Oct)
65
+ # Heures de pointe — doit correspondre à data_generator.is_peak_hour()
66
+ is_peak_hour = 1 if (7 <= hour <= 9 or 18 <= hour <= 21) else 0
67
  return {
68
  'hour': hour,
69
  'day_of_week': date_time.weekday(),