loubnabnl HF staff commited on
Commit
6fb458c
1 Parent(s): eb8b030

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

Browse files
Files changed (1) hide show
  1. app.py +79 -28
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,37 @@ 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 +114,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 +168,14 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False):
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(
@@ -175,7 +201,9 @@ def id_review_submission():
175
  st.subheader("🔍 Review of requests")
176
  st.markdown(REVIEW_TEXT)
177
 
178
- id_to_review = st.number_input("Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1)
 
 
179
  reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
180
  if st.button("Submit / أرسل"):
181
  if reason_for_review == "":
@@ -190,7 +218,9 @@ def id_review_submission():
190
  repo_id="nt3awnou/review_requests",
191
  repo_type="dataset",
192
  )
193
- st.success("Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال")
 
 
194
 
195
 
196
  # Logo and Title
@@ -215,14 +245,10 @@ options = [
215
  ]
216
  selected_options = []
217
 
218
- # with tab_en:
219
- # st.markdown("👉 **Choose request type**")
220
- # with tab_ar:
221
- # st.markdown("👉 **اختر نوع الطلب**")
222
- # with tab_fr:
223
- # st.markdown("👉 **Choisissez le type de demande**")
224
 
225
- st.markdown("👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**")
 
 
226
  col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
227
  cols = [col1, col2, col3, col4, col5]
228
 
@@ -241,8 +267,32 @@ show_interventions = st.checkbox(
241
  value=True,
242
  )
243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  if show_interventions:
245
- # print(interventions_df.columns)
 
 
 
 
246
  display_interventions(interventions_df, m)
247
 
248
  # Show requests
@@ -269,6 +319,7 @@ drop_cols = [
269
  "GeoCode",
270
  "GeoAddress",
271
  "Status",
 
272
  ]
273
  display_dataframe(filtered_df, drop_cols, REQUESTS_URL, search_id=True)
274
 
@@ -277,7 +328,7 @@ st.divider()
277
  st.subheader("📝 **Table of interventions / جدول التدخلات**")
278
  display_dataframe(
279
  interventions_df,
280
- [], # We show NGOs contact information
281
  INTERVENTIONS_URL,
282
  search_id=False,
283
  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
  status = (
59
  "Done ✅"
60
+ if row[interventions_df.columns[5]]
61
+ != "Intervention prévue dans le futur / Planned future intervention"
62
+ and village_status
63
+ != "Critique, Besoin d'aide en urgence / Critical, in urgent need of help"
64
  else "Planned ⌛"
65
  )
66
+ if (
67
+ row[interventions_df.columns[5]]
68
+ != "Intervention prévue dans le futur / Planned future intervention"
69
+ and village_status
70
+ != "Critique, Besoin d'aide en urgence / Critical, in urgent need of help"
71
+ ):
72
+ color_mk = "green"
73
+ elif (
74
+ row[interventions_df.columns[5]]
75
+ != "Intervention prévue dans le futur / Planned future intervention"
76
+ and village_status
77
+ == "Critique, Besoin d'aide en urgence / Critical, in urgent need of help"
78
+ ):
79
+ color_mk = "darkgreen"
80
+ else:
81
+ color_mk = "pink"
82
+
83
  intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
84
  org = row[interventions_df.columns[1]]
85
  city = row[interventions_df.columns[9]]
86
  date = row[interventions_df.columns[4]]
87
+ 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>📅 Date:</b> {date}"
88
  if row["latlng"] is None:
89
  continue
90
  folium.Marker(
 
114
  if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
115
  else None,
116
  popup=folium.Popup(display_text, max_width=300),
117
+ icon=folium.Icon(
118
+ color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
119
+ ),
120
  ).add_to(m)
121
 
122
 
 
168
  if status:
169
  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"
170
  if selected_status == "Done / تم":
171
+ display_df = display_df[
172
+ display_df[target] == "Intervention déjà passée / Past intevention"
173
+ ]
174
 
175
  elif selected_status == "Planned / مخطط لها":
176
+ display_df = display_df[
177
+ display_df[target] != "Intervention déjà passée / Past intevention"
178
+ ]
179
 
180
  st.dataframe(display_df, height=500)
181
  st.markdown(
 
201
  st.subheader("🔍 Review of requests")
202
  st.markdown(REVIEW_TEXT)
203
 
204
+ id_to_review = st.number_input(
205
+ "Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1
206
+ )
207
  reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
208
  if st.button("Submit / أرسل"):
209
  if reason_for_review == "":
 
218
  repo_id="nt3awnou/review_requests",
219
  repo_type="dataset",
220
  )
221
+ st.success(
222
+ "Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
223
+ )
224
 
225
 
226
  # Logo and Title
 
245
  ]
246
  selected_options = []
247
 
 
 
 
 
 
 
248
 
249
+ st.markdown(
250
+ "👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**"
251
+ )
252
  col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
253
  cols = [col1, col2, col3, col4, col5]
254
 
 
267
  value=True,
268
  )
269
 
270
+ # Categories of villages
271
+
272
+ st.markdown(
273
+ "<br>👉 **State of villages visited by NGOs| Etat de villages visités par les ONGs | اختر نوع القرى التي زارتها الجمعيات**",
274
+ unsafe_allow_html=True,
275
+ )
276
+
277
+ village_types = ["Critique", "Partiellement satisfait", "Entièrement satisfait "]
278
+ selected_village_types = st.multiselect(
279
+ " ",
280
+ village_types,
281
+ default=village_types,
282
+ )
283
+ status_mapping = {
284
+ "Critique": "Critique, Besoin d'aide en urgence / Critical, in urgent need of help",
285
+ "Partiellement satisfait": "Partiellement satisfait / Partially Served",
286
+ "Entièrement satisfait ": "Entièrement satisfait / Fully served",
287
+ }
288
+ selected_statuses = [status_mapping[status] for status in selected_village_types]
289
+
290
  if show_interventions:
291
+ interventions_df = interventions_df.loc[
292
+ interventions_df[
293
+ "Etat de la région actuel | Current situation of the area "
294
+ ].isin(selected_statuses)
295
+ ]
296
  display_interventions(interventions_df, m)
297
 
298
  # Show requests
 
319
  "GeoCode",
320
  "GeoAddress",
321
  "Status",
322
+ "id",
323
  ]
324
  display_dataframe(filtered_df, drop_cols, REQUESTS_URL, search_id=True)
325
 
 
328
  st.subheader("📝 **Table of interventions / جدول التدخلات**")
329
  display_dataframe(
330
  interventions_df,
331
+ [], # We show NGOs contact information
332
  INTERVENTIONS_URL,
333
  search_id=False,
334
  status=True,