Spaces:
Sleeping
Sleeping
Commit
•
4b6607c
1
Parent(s):
023bf00
update embed
Browse files- app.py +36 -4
- src/utils.py +26 -17
app.py
CHANGED
@@ -13,7 +13,7 @@ from src.text_content import (
|
|
13 |
ICON_MAPPING,
|
14 |
REVIEW_TEXT,
|
15 |
)
|
16 |
-
from src.utils import add_latlng_col, init_map, parse_gg_sheet
|
17 |
|
18 |
|
19 |
import os
|
@@ -109,12 +109,16 @@ def show_requests(filtered_df):
|
|
109 |
"""Display victim requests on the map"""
|
110 |
for index, row in filtered_df.iterrows():
|
111 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
|
|
|
|
|
|
112 |
long_lat = row[
|
113 |
"هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً \n31.01837503440344, -6.781405948842175"
|
114 |
]
|
115 |
maps_url = f"https://maps.google.com/?q={long_lat}"
|
|
|
116 |
display_text = f'<b>Request Type:</b> {request_type}<br><b>Id:</b> {row["id"]}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>Google Maps</b></a>'
|
117 |
-
icon_name = ICON_MAPPING.get(
|
118 |
if row["latlng"] is None:
|
119 |
continue
|
120 |
|
@@ -125,7 +129,7 @@ def show_requests(filtered_df):
|
|
125 |
else None,
|
126 |
popup=folium.Popup(display_text, max_width=300),
|
127 |
icon=folium.Icon(
|
128 |
-
color=COLOR_MAPPING.get(
|
129 |
),
|
130 |
))
|
131 |
|
@@ -232,6 +236,12 @@ def id_review_submission():
|
|
232 |
"Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
|
233 |
)
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
# Load data and initialize map with plugins
|
236 |
df = parse_gg_sheet(REQUESTS_URL)
|
237 |
df = add_latlng_col(df, process_column=15)
|
@@ -250,8 +260,30 @@ options = [
|
|
250 |
]
|
251 |
selected_options = []
|
252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
df["id"] = df.index
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
display_interventions(interventions_df)
|
257 |
|
|
|
13 |
ICON_MAPPING,
|
14 |
REVIEW_TEXT,
|
15 |
)
|
16 |
+
from src.utils import add_latlng_col, init_map, parse_gg_sheet, is_request_in_list, marker_request
|
17 |
|
18 |
|
19 |
import os
|
|
|
109 |
"""Display victim requests on the map"""
|
110 |
for index, row in filtered_df.iterrows():
|
111 |
request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
|
112 |
+
displayed_request = marker_request(request_type)
|
113 |
+
if pd.isna(request_type):
|
114 |
+
continue
|
115 |
long_lat = row[
|
116 |
"هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً \n31.01837503440344, -6.781405948842175"
|
117 |
]
|
118 |
maps_url = f"https://maps.google.com/?q={long_lat}"
|
119 |
+
# we display all requests in popup text and use the first one for the icon/color
|
120 |
display_text = f'<b>Request Type:</b> {request_type}<br><b>Id:</b> {row["id"]}<br><a href="{maps_url}" target="_blank" rel="noopener noreferrer"><b>Google Maps</b></a>'
|
121 |
+
icon_name = ICON_MAPPING.get(displayed_request, None)
|
122 |
if row["latlng"] is None:
|
123 |
continue
|
124 |
|
|
|
129 |
else None,
|
130 |
popup=folium.Popup(display_text, max_width=300),
|
131 |
icon=folium.Icon(
|
132 |
+
color=COLOR_MAPPING.get(displayed_request, "blue"), icon=icon_name
|
133 |
),
|
134 |
))
|
135 |
|
|
|
236 |
"Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
|
237 |
)
|
238 |
|
239 |
+
|
240 |
+
# # Logo and Title
|
241 |
+
# st.markdown(LOGO, unsafe_allow_html=True)
|
242 |
+
# # st.title("Nt3awnou نتعاونو")
|
243 |
+
# st.markdown(SLOGAN, unsafe_allow_html=True)
|
244 |
+
|
245 |
# Load data and initialize map with plugins
|
246 |
df = parse_gg_sheet(REQUESTS_URL)
|
247 |
df = add_latlng_col(df, process_column=15)
|
|
|
260 |
]
|
261 |
selected_options = []
|
262 |
|
263 |
+
|
264 |
+
|
265 |
+
# st.markdown(
|
266 |
+
# "👉 **Choose request type | Choissisez le type de demande | اختر نوع الطلب**"
|
267 |
+
# )
|
268 |
+
# col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
|
269 |
+
# cols = [col1, col2, col3, col4, col5]
|
270 |
+
|
271 |
+
# for i, option in enumerate(options):
|
272 |
+
# checked = cols[i].checkbox(HEADERS_MAPPING[option], value=True)
|
273 |
+
# if checked:
|
274 |
+
# selected_options.append(option)
|
275 |
+
|
276 |
+
|
277 |
df["id"] = df.index
|
278 |
+
# keep rows with at least one request in selected_options
|
279 |
+
filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(
|
280 |
+
lambda x: is_request_in_list(x, selected_options)
|
281 |
+
)]
|
282 |
+
|
283 |
+
# # keep rows with at least one request in selected_options
|
284 |
+
# filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].apply(
|
285 |
+
# lambda x: is_request_in_list(x, selected_options)
|
286 |
+
# )]
|
287 |
|
288 |
display_interventions(interventions_df)
|
289 |
|
src/utils.py
CHANGED
@@ -12,19 +12,26 @@ def parse_gg_sheet(url):
|
|
12 |
df = pd.read_csv(url, on_bad_lines="warn")
|
13 |
return df
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def add_latlng_col(df, process_column):
|
30 |
"""Add a latlng column to the dataframe"""
|
@@ -109,19 +116,21 @@ def init_map():
|
|
109 |
max_bounds=True,
|
110 |
)
|
111 |
# Add a search bar to the map
|
112 |
-
plugins.Geocoder(
|
113 |
collapsed=False,
|
114 |
position="topright",
|
115 |
placeholder="Search | البحث",
|
116 |
-
)
|
|
|
117 |
|
118 |
# Add Fullscreen button to the map
|
119 |
-
plugins.Fullscreen(
|
120 |
position="topright",
|
121 |
title="Expand me | تكبير الخريطة",
|
122 |
title_cancel="Exit me | تصغير الخريطة",
|
123 |
force_separate_button=True,
|
124 |
-
)
|
|
|
125 |
|
126 |
# Satellite View from Mapbox
|
127 |
tileurl = "https://marocmap.ikiker.com/maroc/{z}/{x}/{y}.png"
|
|
|
12 |
df = pd.read_csv(url, on_bad_lines="warn")
|
13 |
return df
|
14 |
|
15 |
+
|
16 |
+
def is_request_in_list(request, selection_list):
|
17 |
+
if isinstance(request, float): # Check if the input is a float (like NaN)
|
18 |
+
return False
|
19 |
+
if "," in request:
|
20 |
+
all_requests = [r.strip() for r in request.split(",")]
|
21 |
+
else:
|
22 |
+
all_requests = [request]
|
23 |
+
return any([r in selection_list for r in all_requests])
|
24 |
+
|
25 |
+
|
26 |
+
def marker_request(request):
|
27 |
+
# in case of multiple requests we use the first one for the marker's icon
|
28 |
+
# requests are already sorted by priority from the form
|
29 |
+
try:
|
30 |
+
displayed_request = request.split(',')[0]
|
31 |
+
except:
|
32 |
+
displayed_request = request
|
33 |
+
return displayed_request
|
34 |
+
|
35 |
|
36 |
def add_latlng_col(df, process_column):
|
37 |
"""Add a latlng column to the dataframe"""
|
|
|
116 |
max_bounds=True,
|
117 |
)
|
118 |
# Add a search bar to the map
|
119 |
+
geocoder = plugins.Geocoder(
|
120 |
collapsed=False,
|
121 |
position="topright",
|
122 |
placeholder="Search | البحث",
|
123 |
+
)
|
124 |
+
m.add_child(geocoder)
|
125 |
|
126 |
# Add Fullscreen button to the map
|
127 |
+
fullscreen = plugins.Fullscreen(
|
128 |
position="topright",
|
129 |
title="Expand me | تكبير الخريطة",
|
130 |
title_cancel="Exit me | تصغير الخريطة",
|
131 |
force_separate_button=True,
|
132 |
+
)
|
133 |
+
m.add_child(fullscreen)
|
134 |
|
135 |
# Satellite View from Mapbox
|
136 |
tileurl = "https://marocmap.ikiker.com/maroc/{z}/{x}/{y}.png"
|