Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
•
99b0a9f
1
Parent(s):
8229b59
use FeatureGroup
Browse files- app.py +13 -11
- src/utils.py +5 -3
app.py
CHANGED
@@ -51,7 +51,7 @@ if auto_refresh:
|
|
51 |
|
52 |
|
53 |
# Streamlit functions
|
54 |
-
def display_interventions(interventions_df
|
55 |
"""Display NGO interventions on the map"""
|
56 |
for index, row in interventions_df.iterrows():
|
57 |
village_status = row[interventions_df.columns[7]]
|
@@ -84,15 +84,16 @@ def display_interventions(interventions_df, m):
|
|
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 |
-
|
|
|
88 |
location=row["latlng"],
|
89 |
tooltip=city,
|
90 |
popup=folium.Popup(intervention_info, max_width=300),
|
91 |
icon=folium.Icon(color=color_mk),
|
92 |
-
)
|
93 |
|
94 |
|
95 |
-
def show_requests(filtered_df
|
96 |
"""Display victim requests on the map"""
|
97 |
for index, row in filtered_df.iterrows():
|
98 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
@@ -105,7 +106,7 @@ def show_requests(filtered_df, m):
|
|
105 |
if row["latlng"] is None:
|
106 |
continue
|
107 |
|
108 |
-
folium.Marker(
|
109 |
location=row["latlng"],
|
110 |
tooltip=row[" لأي جماعة / قيادة / دوار تنتمون ؟"]
|
111 |
if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
|
@@ -114,7 +115,7 @@ def show_requests(filtered_df, m):
|
|
114 |
icon=folium.Icon(
|
115 |
color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
|
116 |
),
|
117 |
-
)
|
118 |
|
119 |
|
120 |
def display_google_sheet_tables(data_url):
|
@@ -181,11 +182,11 @@ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for
|
|
181 |
# if we want to check hidden contact information
|
182 |
if for_help_requests:
|
183 |
st.markdown(
|
184 |
-
|
185 |
)
|
186 |
# arabic needs rtl
|
187 |
st.markdown(
|
188 |
-
|
189 |
<div style="text-align: left;">
|
190 |
<a href="mailto:[email protected]">[email protected]</a> نحن نخفي معلومات الاتصال لحماية خصوصية الضحايا. إذا كنت جمعية وتريد الاتصال بالضحايا، يرجى الاتصال بنا على
|
191 |
</div>
|
@@ -232,6 +233,7 @@ df = add_latlng_col(df, process_column=15)
|
|
232 |
interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
|
233 |
interventions_df = add_latlng_col(interventions_df, process_column=12)
|
234 |
m = init_map()
|
|
|
235 |
|
236 |
# Selection of requests
|
237 |
options = [
|
@@ -317,12 +319,12 @@ if show_interventions:
|
|
317 |
"Etat de la région actuel | Current situation of the area "
|
318 |
].isin(selected_statuses)
|
319 |
]
|
320 |
-
display_interventions(interventions_df
|
321 |
|
322 |
# Show requests
|
323 |
-
show_requests(filtered_df
|
324 |
|
325 |
-
st_folium(m, use_container_width=True, returned_objects=[])
|
326 |
tab_ar, tab_en, tab_fr = st.tabs(["العربية", "English", "Français"])
|
327 |
|
328 |
|
|
|
51 |
|
52 |
|
53 |
# Streamlit functions
|
54 |
+
def display_interventions(interventions_df):
|
55 |
"""Display NGO interventions on the map"""
|
56 |
for index, row in interventions_df.iterrows():
|
57 |
village_status = row[interventions_df.columns[7]]
|
|
|
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 |
+
|
88 |
+
fg.add_child(folium.Marker(
|
89 |
location=row["latlng"],
|
90 |
tooltip=city,
|
91 |
popup=folium.Popup(intervention_info, max_width=300),
|
92 |
icon=folium.Icon(color=color_mk),
|
93 |
+
))
|
94 |
|
95 |
|
96 |
+
def show_requests(filtered_df):
|
97 |
"""Display victim requests on the map"""
|
98 |
for index, row in filtered_df.iterrows():
|
99 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
|
|
106 |
if row["latlng"] is None:
|
107 |
continue
|
108 |
|
109 |
+
fg.add_child(folium.Marker(
|
110 |
location=row["latlng"],
|
111 |
tooltip=row[" لأي جماعة / قيادة / دوار تنتمون ؟"]
|
112 |
if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
|
|
|
115 |
icon=folium.Icon(
|
116 |
color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
|
117 |
),
|
118 |
+
))
|
119 |
|
120 |
|
121 |
def display_google_sheet_tables(data_url):
|
|
|
182 |
# if we want to check hidden contact information
|
183 |
if for_help_requests:
|
184 |
st.markdown(
|
185 |
+
"We are hiding contact information to protect the privacy of the victims. If you are an NGO and want to contact the victims, please contact us at [email protected]",
|
186 |
)
|
187 |
# arabic needs rtl
|
188 |
st.markdown(
|
189 |
+
"""
|
190 |
<div style="text-align: left;">
|
191 |
<a href="mailto:[email protected]">[email protected]</a> نحن نخفي معلومات الاتصال لحماية خصوصية الضحايا. إذا كنت جمعية وتريد الاتصال بالضحايا، يرجى الاتصال بنا على
|
192 |
</div>
|
|
|
233 |
interventions_df = parse_gg_sheet(INTERVENTIONS_URL)
|
234 |
interventions_df = add_latlng_col(interventions_df, process_column=12)
|
235 |
m = init_map()
|
236 |
+
fg = folium.FeatureGroup(name="Markers")
|
237 |
|
238 |
# Selection of requests
|
239 |
options = [
|
|
|
319 |
"Etat de la région actuel | Current situation of the area "
|
320 |
].isin(selected_statuses)
|
321 |
]
|
322 |
+
display_interventions(interventions_df)
|
323 |
|
324 |
# Show requests
|
325 |
+
show_requests(filtered_df)
|
326 |
|
327 |
+
st_folium(m, use_container_width=True, returned_objects=[], feature_group_to_add=fg, key="map")
|
328 |
tab_ar, tab_en, tab_fr = st.tabs(["العربية", "English", "Français"])
|
329 |
|
330 |
|
src/utils.py
CHANGED
@@ -58,7 +58,7 @@ def parse_latlng(latlng):
|
|
58 |
print(f"Error parsing latlng: {latlng}")
|
59 |
return None
|
60 |
|
61 |
-
def add_epicentre_to_map(
|
62 |
# Removed the spinner to not confuse the users as the map is already loaded
|
63 |
icon_epicentre = folium.plugins.BeautifyIcon(
|
64 |
icon='star',
|
@@ -66,9 +66,11 @@ def add_epicentre_to_map(map_obj):
|
|
66 |
background_color='#b3334f',
|
67 |
text_color='white'
|
68 |
)
|
69 |
-
|
|
|
70 |
popup="Epicenter مركز الزلزال",
|
71 |
-
icon=icon_epicentre)
|
|
|
72 |
|
73 |
|
74 |
def add_danger_distances_to_map(map_obj):
|
|
|
58 |
print(f"Error parsing latlng: {latlng}")
|
59 |
return None
|
60 |
|
61 |
+
def add_epicentre_to_map(fg):
|
62 |
# Removed the spinner to not confuse the users as the map is already loaded
|
63 |
icon_epicentre = folium.plugins.BeautifyIcon(
|
64 |
icon='star',
|
|
|
66 |
background_color='#b3334f',
|
67 |
text_color='white'
|
68 |
)
|
69 |
+
|
70 |
+
fg.add_child(folium.Marker(location=EPICENTER_LOCATION,
|
71 |
popup="Epicenter مركز الزلزال",
|
72 |
+
icon=icon_epicentre))
|
73 |
+
|
74 |
|
75 |
|
76 |
def add_danger_distances_to_map(map_obj):
|