loubnabnl HF staff commited on
Commit
b7d0cb0
1 Parent(s): af8a251

Add village status selection and description to the markers, change marker color if village was visited but is in critical condition (#15)

Browse files

- Add village status selection and description to the markers, change marker color if village was visited but is in critical condition (6fb458c6d43ded517186e461d0dd7b879c4d550a)
- use checkboxes instead (8cfd7ce99e7a437d8d5227cf36dfe9ed87285896)
- add new color (5ded0278b146b60333177f752543dac9d28c0445)

Files changed (2) hide show
  1. app.py +106 -32
  2. src/map_utils.py +1 -0
app.py CHANGED
@@ -7,7 +7,6 @@ import pandas as pd
7
  import streamlit as st
8
  from huggingface_hub import HfApi
9
  from streamlit_folium import st_folium
10
- from src.utils import add_latlng_col
11
 
12
  from src.text_content import (
13
  COLOR_MAPPING,
@@ -21,18 +20,21 @@ from src.text_content import (
21
  REVIEW_TEXT,
22
  SLOGAN,
23
  )
24
- from src.utils import init_map, parse_gg_sheet
25
 
26
  TOKEN = os.environ.get("HF_TOKEN", None)
27
  REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
28
- INTERVENTIONS_URL = (
29
- "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
30
- )
31
  api = HfApi(TOKEN)
32
 
33
 
34
  # Initialize Streamlit Config
35
- st.set_page_config(layout="wide", initial_sidebar_state="collapsed", page_icon="🤝", page_title="Nt3awnou نتعاونو")
 
 
 
 
 
36
 
37
  # Initialize States
38
  if "sleep_time" not in st.session_state:
@@ -42,7 +44,9 @@ if "auto_refresh" not in st.session_state:
42
 
43
  auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh)
44
  if auto_refresh:
45
- number = st.sidebar.number_input("Refresh rate in seconds", value=st.session_state.sleep_time)
 
 
46
  st.session_state.sleep_time = number
47
 
48
 
@@ -50,21 +54,34 @@ if auto_refresh:
50
  def display_interventions(interventions_df, m):
51
  """Display NGO interventions on the map"""
52
  for index, row in interventions_df.iterrows():
53
- status = (
54
- "Done ✅"
55
- if row[interventions_df.columns[5]] != "Intervention prévue dans le futur / Planned future intervention"
56
- else "Planned "
57
- )
58
- color_mk = (
59
- "green"
60
- if row[interventions_df.columns[5]] != "Intervention prévue dans le futur / Planned future intervention"
61
- else "pink"
62
- )
 
 
 
 
 
 
 
 
 
 
 
 
63
  intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
64
  org = row[interventions_df.columns[1]]
65
  city = row[interventions_df.columns[9]]
66
  date = row[interventions_df.columns[4]]
67
- intervention_info = f"<b>Status:</b> {status}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>📅 Date:</b> {date}"
 
68
  if row["latlng"] is None:
69
  continue
70
  folium.Marker(
@@ -94,7 +111,9 @@ def show_requests(filtered_df, m):
94
  if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
95
  else None,
96
  popup=folium.Popup(display_text, max_width=300),
97
- icon=folium.Icon(color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name),
 
 
98
  ).add_to(m)
99
 
100
 
@@ -146,10 +165,14 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for
146
  if status:
147
  target = "Pouvez-vous nous préciser si vous êtes déjà intervenus ou si vous prévoyez de le faire | Tell us if you already made the intervention, or if you're planning to do it"
148
  if selected_status == "Done / تم":
149
- display_df = display_df[display_df[target] == "Intervention déjà passée / Past intevention"]
 
 
150
 
151
  elif selected_status == "Planned / مخطط لها":
152
- display_df = display_df[display_df[target] != "Intervention déjà passée / Past intevention"]
 
 
153
 
154
  st.dataframe(display_df, height=500)
155
  st.markdown(
@@ -176,7 +199,9 @@ def id_review_submission():
176
  st.subheader("🔍 Review of requests")
177
  st.markdown(REVIEW_TEXT)
178
 
179
- id_to_review = st.number_input("Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1)
 
 
180
  reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
181
  if st.button("Submit / أرسل"):
182
  if reason_for_review == "":
@@ -191,7 +216,9 @@ def id_review_submission():
191
  repo_id="nt3awnou/review_requests",
192
  repo_type="dataset",
193
  )
194
- st.success("Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال")
 
 
195
 
196
 
197
  # Logo and Title
@@ -216,14 +243,10 @@ options = [
216
  ]
217
  selected_options = []
218
 
219
- # with tab_en:
220
- # st.markdown("👉 **Choose request type**")
221
- # with tab_ar:
222
- # st.markdown("👉 **اختر نوع الطلب**")
223
- # with tab_fr:
224
- # st.markdown("👉 **Choisissez le type de demande**")
225
 
226
- st.markdown("👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**")
 
 
227
  col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
228
  cols = [col1, col2, col3, col4, col5]
229
 
@@ -242,8 +265,58 @@ show_interventions = st.checkbox(
242
  value=True,
243
  )
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  if show_interventions:
246
- # print(interventions_df.columns)
 
 
 
 
247
  display_interventions(interventions_df, m)
248
 
249
  # Show requests
@@ -270,6 +343,7 @@ drop_cols = [
270
  "GeoCode",
271
  "GeoAddress",
272
  "Status",
 
273
  ]
274
  display_dataframe(filtered_df, drop_cols, REQUESTS_URL, search_id=True, for_help_requests=True)
275
 
@@ -278,7 +352,7 @@ st.divider()
278
  st.subheader("📝 **Table of interventions / جدول التدخلات**")
279
  display_dataframe(
280
  interventions_df,
281
- [], # We show NGOs contact information
282
  INTERVENTIONS_URL,
283
  search_id=False,
284
  status=True,
 
7
  import streamlit as st
8
  from huggingface_hub import HfApi
9
  from streamlit_folium import st_folium
 
10
 
11
  from src.text_content import (
12
  COLOR_MAPPING,
 
20
  REVIEW_TEXT,
21
  SLOGAN,
22
  )
23
+ from src.utils import add_latlng_col, init_map, parse_gg_sheet
24
 
25
  TOKEN = os.environ.get("HF_TOKEN", None)
26
  REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
27
+ INTERVENTIONS_URL = "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
 
 
28
  api = HfApi(TOKEN)
29
 
30
 
31
  # Initialize Streamlit Config
32
+ st.set_page_config(
33
+ layout="wide",
34
+ initial_sidebar_state="collapsed",
35
+ page_icon="🤝",
36
+ page_title="Nt3awnou نتعاونو",
37
+ )
38
 
39
  # Initialize States
40
  if "sleep_time" not in st.session_state:
 
44
 
45
  auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh)
46
  if auto_refresh:
47
+ number = st.sidebar.number_input(
48
+ "Refresh rate in seconds", value=st.session_state.sleep_time
49
+ )
50
  st.session_state.sleep_time = number
51
 
52
 
 
54
  def display_interventions(interventions_df, m):
55
  """Display NGO interventions on the map"""
56
  for index, row in interventions_df.iterrows():
57
+ village_status = row[interventions_df.columns[7]]
58
+ if (
59
+ row[interventions_df.columns[5]]
60
+ == "Intervention prévue dans le futur / Planned future intervention"
61
+ ):
62
+ # future intervention
63
+ color_mk = "pink"
64
+ status = "Planned "
65
+ elif (
66
+ row[interventions_df.columns[5]]
67
+ != "Intervention prévue dans le futur / Planned future intervention"
68
+ and village_status
69
+ != "Critique, Besoin d'aide en urgence / Critical, in urgent need of help"
70
+ ):
71
+ # past intervention and village not in a critical condition
72
+ color_mk = "green"
73
+ status = "Done ✅"
74
+
75
+ else:
76
+ color_mk = "darkgreen"
77
+ status = "Partial ⚠️"
78
+
79
  intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
80
  org = row[interventions_df.columns[1]]
81
  city = row[interventions_df.columns[9]]
82
  date = row[interventions_df.columns[4]]
83
+ population = row[interventions_df.columns[11]]
84
+ intervention_info = f"<b>Intervention Status:</b> {status}<br><b>Village Status:</b> {village_status.split('/')[0]}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>Population:</b> {population}<br><b>📅 Date:</b> {date}"
85
  if row["latlng"] is None:
86
  continue
87
  folium.Marker(
 
111
  if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
112
  else None,
113
  popup=folium.Popup(display_text, max_width=300),
114
+ icon=folium.Icon(
115
+ color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
116
+ ),
117
  ).add_to(m)
118
 
119
 
 
165
  if status:
166
  target = "Pouvez-vous nous préciser si vous êtes déjà intervenus ou si vous prévoyez de le faire | Tell us if you already made the intervention, or if you're planning to do it"
167
  if selected_status == "Done / تم":
168
+ display_df = display_df[
169
+ display_df[target] == "Intervention déjà passée / Past intevention"
170
+ ]
171
 
172
  elif selected_status == "Planned / مخطط لها":
173
+ display_df = display_df[
174
+ display_df[target] != "Intervention déjà passée / Past intevention"
175
+ ]
176
 
177
  st.dataframe(display_df, height=500)
178
  st.markdown(
 
199
  st.subheader("🔍 Review of requests")
200
  st.markdown(REVIEW_TEXT)
201
 
202
+ id_to_review = st.number_input(
203
+ "Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1
204
+ )
205
  reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
206
  if st.button("Submit / أرسل"):
207
  if reason_for_review == "":
 
216
  repo_id="nt3awnou/review_requests",
217
  repo_type="dataset",
218
  )
219
+ st.success(
220
+ "Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
221
+ )
222
 
223
 
224
  # Logo and Title
 
243
  ]
244
  selected_options = []
245
 
 
 
 
 
 
 
246
 
247
+ st.markdown(
248
+ "👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**"
249
+ )
250
  col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
251
  cols = [col1, col2, col3, col4, col5]
252
 
 
265
  value=True,
266
  )
267
 
268
+ # Categories of villages
269
+
270
+ st.markdown(
271
+ "👉 **State of villages visited by NGOs| Etat de villages visités par les ONGs | اختر نوع القرى التي زارتها الجمعيات**",
272
+ unsafe_allow_html=True,
273
+ )
274
+
275
+
276
+ # use checkboxes
277
+ col_1, col_2, col_3 = st.columns([1, 1, 1])
278
+
279
+ critical_villages = col_1.checkbox(
280
+ "🚨 Critical, in urgent need of help / وضع حرج، في حاجة عاجلة للمساعدة",
281
+ value=True,
282
+ )
283
+ partially_satisfied_villages = col_2.checkbox(
284
+ "⚠️ Partially served / مساعدة جزئية، بحاجة للمزيد من التدخلات",
285
+ value=True,
286
+ )
287
+ fully_satisfied_villages = col_3.checkbox(
288
+ "✅ Fully served / تمت المساعدة بشكل كامل",
289
+ value=True,
290
+ )
291
+
292
+ selected_village_types = []
293
+
294
+ if critical_villages:
295
+ selected_village_types.append(
296
+ "🚨 Critical, in urgent need of help / وضع حرج، في حاجة عاجلة للمساعدة"
297
+ )
298
+
299
+ if partially_satisfied_villages:
300
+ selected_village_types.append(
301
+ "⚠️ Partially served / مساعدة جزئية، بحاجة للمزيد من التدخلات"
302
+ )
303
+
304
+ if fully_satisfied_villages:
305
+ selected_village_types.append("✅ Fully served / تمت المساعدة بشكل كامل")
306
+
307
+ status_mapping = {
308
+ "🚨 Critical, in urgent need of help / وضع حرج، في حاجة عاجلة للمساعدة": "Critique, Besoin d'aide en urgence / Critical, in urgent need of help",
309
+ "⚠️ Partially served / مساعدة جزئية، بحاجة للمزيد من التدخلات": "Partiellement satisfait / Partially Served",
310
+ "✅ Fully served / تمت المساعدة بشكل كامل": "Entièrement satisfait / Fully served",
311
+ }
312
+ selected_statuses = [status_mapping[status] for status in selected_village_types]
313
+
314
  if show_interventions:
315
+ interventions_df = interventions_df.loc[
316
+ interventions_df[
317
+ "Etat de la région actuel | Current situation of the area "
318
+ ].isin(selected_statuses)
319
+ ]
320
  display_interventions(interventions_df, m)
321
 
322
  # Show requests
 
343
  "GeoCode",
344
  "GeoAddress",
345
  "Status",
346
+ "id",
347
  ]
348
  display_dataframe(filtered_df, drop_cols, REQUESTS_URL, search_id=True, for_help_requests=True)
349
 
 
352
  st.subheader("📝 **Table of interventions / جدول التدخلات**")
353
  display_dataframe(
354
  interventions_df,
355
+ [], # We show NGOs contact information
356
  INTERVENTIONS_URL,
357
  search_id=False,
358
  status=True,
src/map_utils.py CHANGED
@@ -46,6 +46,7 @@ template = """
46
  <li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / طعام وماء</li>
47
  <li><span style='background:#575757;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
48
  <li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
 
49
  <li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
50
  </ul>
51
  </div>
 
46
  <li><span style='background:#37A8DA;opacity:0.7;'></span>Food & Water / طعام وماء</li>
47
  <li><span style='background:#575757;opacity:0.7;'></span>Danger / مخاطر (تسرب الغاز، تلف في الخدمات العامة...)</li>
48
  <li><span style='background:#6EAA25;opacity:0.7;'></span>Done / تم</li>
49
+ <li><span style='background:#023020;opacity:0.7;'></span>Partial / تم جزئيا</li>
50
  <li><span style='background:#FF91E8;opacity:0.7;'></span>Planned / مخطط لها</li>
51
  </ul>
52
  </div>