Kader Kone commited on
Commit
ea72220
·
1 Parent(s): 0877255

\Fix sidebar visibility + map matplotlib (sans plotly)\n\n- CSS sidebar : cible uniquement labels/paragraphes, ne touche plus\n aux selectbox natifs (texte noir sur fond blanc maintenant visible)\n- Carte : remplace plotly par matplotlib scatter (pas de dep externe)\n- Supprime plotly de requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +68 -67
  2. requirements.txt +0 -1
app.py CHANGED
@@ -8,7 +8,6 @@ import pandas as pd
8
  import streamlit as st
9
  import matplotlib.pyplot as plt
10
  import seaborn as sns
11
- import plotly.graph_objects as go
12
 
13
  from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
14
  from sklearn.neural_network import MLPRegressor
@@ -120,11 +119,34 @@ st.markdown("""
120
 
121
  .stAlert { border-radius: 8px; }
122
 
123
- [data-testid="stSidebar"] { background-color: #ffffff !important; }
124
- [data-testid="stSidebar"] * { color: #1a1a1a !important; }
125
- [data-testid="stSidebar"] .stButton > button {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  background-color: #0E5E6F !important;
127
- color: #ffffff !important; border: none !important;
 
128
  }
129
  </style>
130
  """, unsafe_allow_html=True)
@@ -235,68 +257,46 @@ def predict(bundle, soil_moisture, temperature, rainfall, crop_type,
235
  float(nn.predict(X_in_sc)[0]))
236
 
237
 
238
- # ── Carte Burkina Faso ────────────────────────────────────────────────────────
239
  def make_map(selected_region: str, irr_value: float = None):
240
- lats = [v[0] for v in REGION_COORDS.values()]
241
- lons = [v[1] for v in REGION_COORDS.values()]
242
- names = list(REGION_COORDS.keys())
243
-
244
- colors = ["#e74c3c" if n == selected_region else "#0E5E6F" for n in names]
245
- sizes = [22 if n == selected_region else 12 for n in names]
246
-
247
- hover = [f"<b>{n}</b><br>Région sélectionnée" if n == selected_region
248
- else f"<b>{n}</b>" for n in names]
249
-
250
- fig = go.Figure()
251
-
252
- # Toutes les régions
253
- fig.add_trace(go.Scattergeo(
254
- lat=lats, lon=lons,
255
- mode="markers+text",
256
- marker=dict(size=sizes, color=colors, line=dict(width=1, color="white")),
257
- text=names,
258
- textposition="top center",
259
- textfont=dict(size=8, color="#333"),
260
- hovertext=hover,
261
- hoverinfo="text",
262
- name="",
263
- ))
264
-
265
- # Marqueur sélectionné avec anneau
266
- sel_lat, sel_lon = REGION_COORDS[selected_region]
267
- label = f"📍 {selected_region}"
 
 
 
 
268
  if irr_value is not None:
269
- urgency = "🔴 Urgent" if irr_value > 3 else "🟠 Modéré" if irr_value > 1.5 else "🟢 Favorable"
270
- label += f"<br>{urgency} — {irr_value:.2f} mm/j"
271
-
272
- fig.add_trace(go.Scattergeo(
273
- lat=[sel_lat], lon=[sel_lon],
274
- mode="markers",
275
- marker=dict(size=30, color="rgba(231,76,60,0.2)",
276
- line=dict(width=2, color="#e74c3c")),
277
- hovertext=label, hoverinfo="text",
278
- name="",
279
- ))
280
-
281
- fig.update_geos(
282
- scope="africa",
283
- center=dict(lat=12.3, lon=-1.5),
284
- projection_scale=12,
285
- showland=True, landcolor="#f5f0e8",
286
- showocean=True, oceancolor="#d4e9f7",
287
- showlakes=True, lakecolor="#d4e9f7",
288
- showrivers=True, rivercolor="#a8cfe0",
289
- showcountries=True, countrycolor="#cccccc",
290
- showframe=False,
291
- bgcolor="rgba(0,0,0,0)",
292
- )
293
- fig.update_layout(
294
- margin=dict(l=0, r=0, t=0, b=0),
295
- height=280,
296
- showlegend=False,
297
- paper_bgcolor="rgba(0,0,0,0)",
298
- geo_bgcolor="rgba(0,0,0,0)",
299
- )
300
  return fig
301
 
302
 
@@ -375,8 +375,9 @@ with tab1:
375
 
376
  with col_map:
377
  st.markdown("##### 📍 Localisation — " + region_name)
378
- st.plotly_chart(make_map(region_name, irr), use_container_width=True,
379
- config={"displayModeBar": False})
 
380
 
381
  with col_ctx:
382
  st.markdown("##### 📋 Situation analysée")
 
8
  import streamlit as st
9
  import matplotlib.pyplot as plt
10
  import seaborn as sns
 
11
 
12
  from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor
13
  from sklearn.neural_network import MLPRegressor
 
119
 
120
  .stAlert { border-radius: 8px; }
121
 
122
+ /* Sidebar fond blanc */
123
+ [data-testid="stSidebar"] > div:first-child {
124
+ background-color: #ffffff !important;
125
+ }
126
+ /* Labels des sliders et selectbox */
127
+ [data-testid="stSidebar"] label,
128
+ [data-testid="stSidebar"] .stMarkdown p,
129
+ [data-testid="stSidebar"] .stMarkdown h3,
130
+ [data-testid="stSidebar"] .stMarkdown h4,
131
+ [data-testid="stSidebar"] p {
132
+ color: #1a1a1a !important;
133
+ }
134
+ /* Valeur affichée dans le selectbox (texte sélectionné) */
135
+ [data-testid="stSidebar"] [data-baseweb="select"] [data-baseweb="tag"],
136
+ [data-testid="stSidebar"] [data-baseweb="select"] span {
137
+ color: #1a1a1a !important;
138
+ background-color: transparent !important;
139
+ }
140
+ /* Slider : valeur et trait */
141
+ [data-testid="stSidebar"] .stSlider [data-testid="stTickBarMin"],
142
+ [data-testid="stSidebar"] .stSlider [data-testid="stTickBarMax"] {
143
+ color: #555 !important;
144
+ }
145
+ /* Bouton primaire */
146
+ [data-testid="stSidebar"] .stButton > button[kind="primary"] {
147
  background-color: #0E5E6F !important;
148
+ color: #ffffff !important;
149
+ border: none !important;
150
  }
151
  </style>
152
  """, unsafe_allow_html=True)
 
257
  float(nn.predict(X_in_sc)[0]))
258
 
259
 
260
+ # ── Carte Burkina Faso (matplotlib) ──────────────────────────────────────────
261
  def make_map(selected_region: str, irr_value: float = None):
262
+ fig, ax = plt.subplots(figsize=(5, 4))
263
+ fig.patch.set_facecolor("#EAF4F6")
264
+ ax.set_facecolor("#EAF4F6")
265
+
266
+ urgency_color = "#e74c3c" if (irr_value or 0) > 3 else "#e67e22" if (irr_value or 0) > 1.5 else "#27ae60"
267
+
268
+ for name, (lat, lon) in REGION_COORDS.items():
269
+ is_sel = (name == selected_region)
270
+ ax.scatter(lon, lat,
271
+ s=260 if is_sel else 80,
272
+ c=urgency_color if is_sel else "#0E5E6F",
273
+ zorder=5 if is_sel else 3,
274
+ edgecolors="white", linewidths=1.5)
275
+ offset_y = 0.18 if is_sel else 0.13
276
+ ax.text(lon, lat + offset_y, name,
277
+ ha="center", va="bottom",
278
+ fontsize=7.5 if is_sel else 5.5,
279
+ fontweight="bold" if is_sel else "normal",
280
+ color=urgency_color if is_sel else "#333",
281
+ zorder=6)
282
+
283
+ # Cadre Burkina Faso approx.
284
+ from matplotlib.patches import FancyBboxPatch
285
+ ax.set_xlim(-5.5, 2.4)
286
+ ax.set_ylim(9.4, 15.1)
287
+ ax.set_xlabel("Longitude", fontsize=7, color="#888")
288
+ ax.set_ylabel("Latitude", fontsize=7, color="#888")
289
+ ax.tick_params(labelsize=6, colors="#aaa")
290
+ for spine in ax.spines.values():
291
+ spine.set_edgecolor("#ccc")
292
+
293
+ # Légende urgence
294
  if irr_value is not None:
295
+ urgency_lbl = "Urgent" if irr_value > 3 else "Modéré" if irr_value > 1.5 else "Favorable"
296
+ ax.set_title(f"📍 {selected_region} · {urgency_lbl} ({irr_value:.2f} mm/j)",
297
+ fontsize=8.5, fontweight="bold", color=urgency_color, pad=6)
298
+
299
+ plt.tight_layout(pad=0.5)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  return fig
301
 
302
 
 
375
 
376
  with col_map:
377
  st.markdown("##### 📍 Localisation — " + region_name)
378
+ fig_map = make_map(region_name, irr)
379
+ st.pyplot(fig_map)
380
+ plt.close()
381
 
382
  with col_ctx:
383
  st.markdown("##### 📋 Situation analysée")
requirements.txt CHANGED
@@ -6,4 +6,3 @@ matplotlib>=3.7.0
6
  seaborn>=0.12.0
7
  joblib>=1.3.0
8
  requests>=2.31.0
9
- plotly>=5.18.0
 
6
  seaborn>=0.12.0
7
  joblib>=1.3.0
8
  requests>=2.31.0