loubnabnl HF staff nouamanetazi HF staff commited on
Commit
467b4df
0 Parent(s):

Duplicate from nt3awnou/Nt3awnou-rescue-map

Browse files

Co-authored-by: Nouamane Tazi <nouamanetazi@users.noreply.huggingface.co>

Files changed (7) hide show
  1. .gitattributes +35 -0
  2. README.md +12 -0
  3. app.py +253 -0
  4. requirements.txt +2 -0
  5. src/map_utils.py +102 -0
  6. src/text_content.py +82 -0
  7. src/utils.py +110 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Nt3awnu Map
3
+ emoji: ❤️
4
+ colorFrom: white
5
+ colorTo: white
6
+ sdk: streamlit
7
+ sdk_version: 1.26.0
8
+ app_file: app.py
9
+ duplicated_from: nt3awnou/Nt3awnou-rescue-map
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import time
3
+ from datetime import datetime
4
+
5
+ import folium
6
+ import pandas as pd
7
+ import requests
8
+ import streamlit as st
9
+ from folium import plugins
10
+ from huggingface_hub import HfApi
11
+ from streamlit_folium import st_folium
12
+
13
+ from src.text_content import (
14
+ COLOR_MAPPING,
15
+ CREDITS_TEXT,
16
+ HEADERS_MAPPING,
17
+ ICON_MAPPING,
18
+ INTRO_TEXT_AR,
19
+ INTRO_TEXT_EN,
20
+ INTRO_TEXT_FR,
21
+ LOGO,
22
+ REVIEW_TEXT,
23
+ REVIEW_TEXT_2,
24
+ SLOGAN,
25
+ )
26
+ from src.utils import init_map, parse_gg_sheet
27
+
28
+ TOKEN = os.environ.get("HF_TOKEN", None)
29
+ REQUESTS_URL = "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
30
+ INTERVENTIONS_URL = "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
31
+ api = HfApi(TOKEN)
32
+
33
+
34
+ # Initialize Streamlit Config
35
+ st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
36
+
37
+ # Initialize States
38
+ if "sleep_time" not in st.session_state:
39
+ st.session_state.sleep_time = 2
40
+ if "auto_refresh" not in st.session_state:
41
+ st.session_state.auto_refresh = False
42
+
43
+ # Session for Requests
44
+ session = requests.Session()
45
+
46
+ auto_refresh = st.sidebar.checkbox("Auto Refresh?", st.session_state.auto_refresh)
47
+ if auto_refresh:
48
+ number = st.sidebar.number_input(
49
+ "Refresh rate in seconds", value=st.session_state.sleep_time
50
+ )
51
+ st.session_state.sleep_time = number
52
+
53
+
54
+ # Utility functions
55
+ @st.cache_data(persist=True)
56
+ def parse_latlng_from_link(url):
57
+ try:
58
+ # extract latitude and longitude from gmaps link
59
+ if "@" not in url:
60
+ resp = session.head(url, allow_redirects=True)
61
+ url = resp.url
62
+ latlng = url.split("@")[1].split(",")[0:2]
63
+ return [float(latlng[0]), float(latlng[1])]
64
+ except Exception as e:
65
+ return None
66
+
67
+
68
+ def parse_gg_sheet_interventions(url):
69
+ url = url.replace("edit#gid=", "export?format=csv&gid=")
70
+ print(url)
71
+ df = pd.read_csv(url, on_bad_lines="skip")
72
+ return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
73
+
74
+
75
+ # Streamlit functions
76
+ def display_interventions(interventions_df, m):
77
+ """Display NGO interventions on the map"""
78
+ for index, row in interventions_df.iterrows():
79
+ status = (
80
+ "Done ✅"
81
+ if row[interventions_df.columns[5]]
82
+ != "Intervention prévue dans le futur / Planned future intervention"
83
+ else "Planned ⌛"
84
+ )
85
+ color_mk = (
86
+ "green"
87
+ if row[interventions_df.columns[5]]
88
+ != "Intervention prévue dans le futur / Planned future intervention"
89
+ else "pink"
90
+ )
91
+ intervention_type = row[interventions_df.columns[6]].split("/")[0].strip()
92
+ org = row[interventions_df.columns[1]]
93
+ city = row[interventions_df.columns[9]]
94
+ date = row[interventions_df.columns[4]]
95
+ intervention_info = f"<b>Status:</b> {status}<br><b>Org:</b> {org}<br><b>Intervention:</b> {intervention_type}<br><b>📅 Date:</b> {date}"
96
+ if row["latlng"] is None:
97
+ continue
98
+ folium.Marker(
99
+ location=row["latlng"],
100
+ tooltip=city,
101
+ popup=folium.Popup(intervention_info, max_width=300),
102
+ icon=folium.Icon(color=color_mk),
103
+ ).add_to(m)
104
+
105
+
106
+ def show_requests(filtered_df, m):
107
+ """Display victim requests on the map"""
108
+ for index, row in filtered_df.iterrows():
109
+ request_type = row["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"]
110
+ long_lat = row[
111
+ "هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً \n31.01837503440344, -6.781405948842175"
112
+ ]
113
+ maps_url = f"https://maps.google.com/?q={long_lat}"
114
+ 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>'
115
+ icon_name = ICON_MAPPING.get(request_type, "info-sign")
116
+ if row["latlng"] is None:
117
+ continue
118
+
119
+ folium.Marker(
120
+ location=row["latlng"],
121
+ tooltip=row[" لأي جماعة / قيادة / دوار تنتمون ؟"]
122
+ if not pd.isna(row[" لأي جماعة / قيادة / دوار تنتمون ؟"])
123
+ else None,
124
+ popup=folium.Popup(display_text, max_width=300),
125
+ icon=folium.Icon(
126
+ color=COLOR_MAPPING.get(request_type, "blue"), icon=icon_name
127
+ ),
128
+ ).add_to(m)
129
+
130
+
131
+ def display_google_sheet_tables():
132
+ """Display the google sheet tables for requests and interventions"""
133
+ st.subheader("📝 **Table of requests / جدول الطلبات**")
134
+ st.markdown(
135
+ f"""<iframe src="{REQUESTS_URL}" width="100%" height="600px"></iframe>""",
136
+ unsafe_allow_html=True,
137
+ )
138
+
139
+ st.subheader("📝 **Table of interventions / جدول التدخل��ت**")
140
+ st.markdown(
141
+ f"""<iframe src="{INTERVENTIONS_URL}" width="100%" height="600px"></iframe>""",
142
+ unsafe_allow_html=True,
143
+ )
144
+
145
+
146
+ def id_review_submission():
147
+ """Id review submission form"""
148
+ st.subheader("🔍 Review of requests")
149
+ st.markdown(REVIEW_TEXT)
150
+ st.markdown(REVIEW_TEXT_2)
151
+
152
+ id_to_review = st.number_input(
153
+ "Enter id / أدخل الرقم", min_value=0, max_value=len(df), value=0, step=1
154
+ )
155
+ reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة")
156
+ if st.button("Submit / أرسل"):
157
+ if reason_for_review == "":
158
+ st.error("Please enter a reason / الرجاء إدخال سبب")
159
+ else:
160
+ filename = f"review_id_{id_to_review}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.txt"
161
+ with open(filename, "w") as f:
162
+ f.write(f"id: {id_to_review}, explanation: {reason_for_review}\n")
163
+ api.upload_file(
164
+ path_or_fileobj=filename,
165
+ path_in_repo=filename,
166
+ repo_id="nt3awnou/review_requests",
167
+ repo_type="dataset",
168
+ )
169
+ st.success(
170
+ "Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال"
171
+ )
172
+
173
+
174
+ # Logo and Title
175
+ st.markdown(LOGO, unsafe_allow_html=True)
176
+ st.title("Nt3awnou نتعاونو ")
177
+ st.markdown(SLOGAN, unsafe_allow_html=True)
178
+
179
+ # Language tabs
180
+ st.sidebar.title("Language / اللغة")
181
+ tab_ar, tab_en, tab_fr = st.tabs(["العربية", "English", "Français"])
182
+
183
+ with tab_en:
184
+ st.markdown(INTRO_TEXT_EN, unsafe_allow_html=True)
185
+ with tab_ar:
186
+ st.markdown(INTRO_TEXT_AR, unsafe_allow_html=True)
187
+ with tab_fr:
188
+ st.markdown(INTRO_TEXT_FR, unsafe_allow_html=True)
189
+
190
+
191
+ # Load data and initialize map with plugins
192
+ df = parse_gg_sheet(REQUESTS_URL)
193
+ interventions_df = parse_gg_sheet_interventions(INTERVENTIONS_URL)
194
+ m = init_map()
195
+
196
+ # Selection of requests
197
+ options = [
198
+ "إغاثة",
199
+ "مساعدة طبية",
200
+ "مأوى",
201
+ "طعام وماء",
202
+ "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)",
203
+ ]
204
+ selected_options = []
205
+
206
+ with tab_en:
207
+ st.markdown("👉 **Choose request type**")
208
+ with tab_ar:
209
+ st.markdown("👉 **اختر نوع الطلب**")
210
+ with tab_fr:
211
+ st.markdown("👉 **Choisissez le type de demande**")
212
+
213
+ col1, col2, col3, col4, col5 = st.columns([2, 3, 2, 3, 4])
214
+ cols = [col1, col2, col3, col4, col5]
215
+
216
+ for i, option in enumerate(options):
217
+ checked = cols[i].checkbox(HEADERS_MAPPING[option], value=True)
218
+ if checked:
219
+ selected_options.append(option)
220
+
221
+ df["id"] = df.index
222
+ filtered_df = df[df["ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)"].isin(selected_options)]
223
+ selected_headers = [HEADERS_MAPPING[request] for request in selected_options]
224
+
225
+ # Selection of interventions
226
+ show_interventions = st.checkbox(
227
+ "Display Interventions | عرض عمليات المساعدة | Afficher les interventions",
228
+ value=True,
229
+ )
230
+
231
+ if show_interventions:
232
+ display_interventions(interventions_df, m)
233
+
234
+ # Show requests
235
+ show_requests(filtered_df, m)
236
+
237
+ st_data = st_folium(m, use_container_width=True)
238
+
239
+ # Google Sheet Tables
240
+ display_google_sheet_tables()
241
+
242
+ # Submit an id for review
243
+ id_review_submission()
244
+
245
+
246
+ # Credits
247
+ st.markdown(
248
+ CREDITS_TEXT,
249
+ unsafe_allow_html=True,
250
+ )
251
+ if auto_refresh:
252
+ time.sleep(number)
253
+ st.experimental_rerun()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ folium
2
+ streamlit_folium
src/map_utils.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from branca.element import Template, MacroElement
2
+
3
+
4
+ template = """
5
+ {% macro html(this, kwargs) %}
6
+
7
+ <!doctype html>
8
+ <html lang="en">
9
+ <head>
10
+ <meta charset="utf-8">
11
+ <meta name="viewport" content="width=device-width, initial-scale=1">
12
+ <title>jQuery UI Draggable - Default functionality</title>
13
+ <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
14
+
15
+ <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
16
+ <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
17
+
18
+ <script>
19
+ $( function() {
20
+ $( "#maplegend" ).draggable({
21
+ start: function (event, ui) {
22
+ $(this).css({
23
+ right: "auto",
24
+ top: "auto",
25
+ bottom: "auto"
26
+ });
27
+ }
28
+ });
29
+ });
30
+
31
+ </script>
32
+ </head>
33
+ <body>
34
+
35
+
36
+ <div id='maplegend' class='maplegend'
37
+ style='position: absolute; z-index:9999; border:2px solid grey; background-color:rgba(255, 255, 255, 0.8);
38
+ border-radius:6px; padding: 10px; font-size:14px; right: 20px; bottom: 20px;'>
39
+
40
+ <div class='legend-title'>Legend / مفتاح الخريطة</div>
41
+ <div class='legend-scale'>
42
+ <ul class='legend-labels'>
43
+ <li><span style='background:#CE3C28;opacity:0.7;'></span>Rescue / إغاثة</li>
44
+ <li><span style='background:#ED922E;opacity:0.7;'></span>Medical Assistance / مساعدة طبية</li>
45
+ <li><span style='background:#FFCA92;opacity:0.7;'></span>Shelter / مأوى</li>
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>
52
+ </div>
53
+
54
+ </body>
55
+ </html>
56
+
57
+ <style type='text/css'>
58
+ .maplegend .legend-title {
59
+ text-align: left;
60
+ margin-bottom: 5px;
61
+ font-weight: bold;
62
+ font-size: 90%;
63
+ color: #333;
64
+ }
65
+ .maplegend .legend-scale ul {
66
+ margin: 0;
67
+ margin-bottom: 5px;
68
+ padding: 0;
69
+ float: left;
70
+ list-style: none;
71
+ }
72
+ .maplegend .legend-scale ul li {
73
+ font-size: 80%;
74
+ list-style: none;
75
+ margin-left: 0;
76
+ line-height: 18px;
77
+ margin-bottom: 2px;
78
+ color: #111;
79
+ }
80
+ .maplegend ul.legend-labels li span {
81
+ display: block;
82
+ float: left;
83
+ height: 16px;
84
+ width: 30px;
85
+ margin-right: 5px;
86
+ margin-left: 0;
87
+ border: 1px solid #999;
88
+ }
89
+ .maplegend .legend-source {
90
+ font-size: 80%;
91
+ color: #777;
92
+ clear: both;
93
+ }
94
+ .maplegend a {
95
+ color: #777;
96
+ }
97
+ </style>
98
+ {% endmacro %}"""
99
+ legend_macro = MacroElement()
100
+ legend_macro._template = Template(template)
101
+
102
+ __all__ = ["legend_macro"]
src/text_content.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ INTRO_TEXT_EN = """
2
+ <div style="text-align: left;">
3
+ Nt3awnou نتعاونو is a collaborative platform dedicated to aiding individuals impacted by the recent earthquake in Morocco. Our core mission is to streamline and coordinate timely assistance for everyone affected. How do we achieve this? We assist those in need by allowing them to communicate their location and the specific aid they require, either by completing a form or sending a voice message via WhatsApp to a designated number. Once we receive and process this information, it can be viewed in our dashboard, which allows NGOs to organize and precisely target their interventions, ensuring swift assistance reaches those in need. Any organization that has taken initiative in a particular area can notify us by completing a dedicated form. This data is also incorporated into the dashboard so that other NGOs can help affected areas that still haven't received help.
4
+ Warning : There are still rocks falling down the mountains, making the roads to the affected areas very dangerous. We advise volunteers to donate directly to specialized NGOs.<br>
5
+ ✉️ You can contact us via email at <a href="mailto:nt3awnou@annarabic.com">nt3awnou@annarabic.com</a> <br>
6
+ 📝 Help us report more people in need by filling this form <a href="https://forms.gle/nZNCUVog9ka2Vdqu6">https://forms.gle/nZNCUVog9ka2Vdqu6</a> <br>
7
+ 📝 NGOs can report their interventions by filling this form <a href="https://forms.gle/PsNSuHHjTTgwQMmVA">https://forms.gle/PsNSuHHjTTgwQMmVA</a>
8
+ </div>
9
+ """
10
+
11
+ INTRO_TEXT_AR = """
12
+ <div style="text-align: right;">
13
+
14
+ نتعاونو هي منصة تعاونية لمساعدة الأفراد المتضررين من الزلزال الأخير في المغرب. مهمتنا هي تسهيل تقديم المساعدة في الوقت المناسب و بفاعلية و تنظيم لجميع المتضررين. كيفاش؟ كنعاونو الناس لي محتاجين للمساعدة إعلمونا بمكانهم و نوع المساعدة لي محتاجين ليها سواء عن طريق ملأ الاستمارة أو عن طريق إرسال تسجيل صوتي عبر واتساب إلى رقم مخصص. بعد معالجة هاد المعلومات، كنجمعوهم فخريطة كتمكن الجمعيات من تنظيم و استهداف تدخلاتهم بدقة باش توصل المساعدة للناس لي محتاجين في وقت أسرع. و كل جمعية قامت باللازم في منطقة معينة تقدر تعلمنا عن طريق ملأ استمارة مخصصة لهاد الأمر. هاد المعلومات كذلك كتضاف للخريطة باش باقي الجمعيات يتاجهو لمناطق أخرى مازال ماوصلاتهم مساعدة.
15
+ تحذير : نظرا لخطورة الطرقان بسبب الحجر اللي كيطيح من الجبال، ننصح المتطوعين اللي بغاو يساعدو المناطق المتضررة يتبرعو عن طريق الجمعيات المختصة.
16
+
17
+ nt3awnou@annarabic.com المتطوعين ليبغاو يعاونوا يقدرو يتصلوا معنا عبر البريد ✉️
18
+ https://forms.gle/nZNCUVog9ka2Vdqu6 : ساعدونا نبلغو الناس ليمحتاجين فهاد الاستمارة 📝<br>
19
+ https://forms.gle/PsNSuHHjTTgwQMmVA : الجمعيات لي عندهم تدخلات يقدرو يبلغونا عبر هاد الاستمار ة📝
20
+ </div>
21
+ """
22
+
23
+ INTRO_TEXT_FR = """
24
+ <div style="text-align: left;">
25
+ Nt3awnou نتعاونو est une plateforme collaborative dédiée à l'aide aux personnes touchées par le récent tremblement de terre au Maroc. Notre mission principale est de rationaliser et de coordonner une assistance rapide pour toutes les personnes touchées. Comment y parvenons-nous ? Nous aidons les personnes dans le besoin en leur permettant de communiquer leur localisation et l'aide spécifique dont elles ont besoin, soit en remplissant un formulaire, soit en envoyant un message vocal via WhatsApp à un numéro désigné. Une fois reçues et traitées, ces informations peuvent être consultées dans notre tableau de bord, qui permet aux associations d'organiser et de cibler précisément leurs interventions, afin que l'aide parvienne rapidement à ceux qui en ont besoin. Toute organisation ayant pris une initiative dans une zone particulière peut nous en informer en remplissant un formulaire prévu à cet effet. Ces données sont également intégrées au tableau de bord afin que d'autres associations puissent aider les zones touchées qui n'ont pas encore reçu d'aide.
26
+ Avertissement : Il y a encore des chutes de pierres dans les montagnes, ce qui rend les routes vers les zones touchées très dangereuses. Nous conseillons aux volontaires de faire des dons directement aux associations spécialisées.
27
+
28
+ Vous pouvez nous contacter par courrier électronique à l'adresse suivante : nt3awnou@annarabic.com
29
+ Aidez-nous à signaler plus de personnes dans le besoin en remplissant ce formulaire : https://forms.gle/nZNCUVog9ka2Vdqu6
30
+ Les associations peuvent signaler leurs interventions en remplissant ce formulaire : https://forms.gle/PsNSuHHjTTgwQMmVA
31
+ </div>
32
+ """
33
+
34
+ SLOGAN = """
35
+ <div style="text-align: center;">
36
+ <h4>وَمَنْ أَحْيَاهَا فَكَأَنَّمَا أَحْيَا النَّاسَ جَمِيعاً</h4>
37
+ </div>
38
+ """
39
+
40
+ HEADERS_MAPPING = {
41
+ "إغاثة" : "Rescue | إغاثة | Secours",
42
+ "مساعدة طبية": "Medical Assistance | مساعدة طبية | Assistance médicale",
43
+ "مأوى": "Shelter | مأوى | Abri",
44
+ "طعام وماء": "Food & Water | طعام وماء | Nourriture et eau",
45
+ "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "Danger | مخاطر (تسرب الغاز، تلف في الخدمات العامة...) | Danger",
46
+ }
47
+
48
+ COLOR_MAPPING = {
49
+ "إغاثة": "red",
50
+ "مساعدة طبية": "orange",
51
+ "مأوى": "beige",
52
+ "طعام وماء": "blue",
53
+ "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "gray",
54
+ }
55
+
56
+ ICON_MAPPING = {
57
+ "إغاثة": "bell", # life ring icon for rescue
58
+ "مساعدة طبية": "heart", # medical kit for medical assistance
59
+ "مأوى": "home", # home icon for shelter
60
+ "طعام وماء": "cutlery", # cutlery (fork and knife) for food & water
61
+ "مخاطر (تسرب الغاز، تلف في الخدمات العامة...)": "Warning" # warning triangle for dangers
62
+ }
63
+
64
+ CREDITS_TEXT = """
65
+ <hr>
66
+ <div style="text-align: center;">
67
+ <p>By <b>Moroccans</b> for <b>Moroccans</b> 🤝</p>
68
+ <p>Bot powered by <a href="https://www.annarabic.com/">Annarabic</a></p>
69
+ <p>Collaboration made possible thanks to <a href="https://summerschool.morocco.ai/">AI Summer School</a></p>
70
+ """
71
+
72
+ LOGO = """
73
+ <div style="text-align: center;">
74
+ <img src="https://storage.googleapis.com/storage-annarabic/Nt3awnou(1).png" width="200" height="200">
75
+ </div>
76
+ """
77
+
78
+ REVIEW_TEXT = """
79
+ If you intervened to solve a request, please fill this [form](https://docs.google.com/forms/d/e/1FAIpQLSe8D6T__DJDTVGMrIWMT-H-hQ0qDUWVOncKnrSXgv4NbwHCrQ/viewform)\n\n
80
+ إذا تدخلت لحل طلب، يرجى ملء هذا [النموذج](https://docs.google.com/forms/d/e/1FAIpQLSe8D6T__DJDTVGMrIWMT-H-hQ0qDUWVOncKnrSXgv4NbwHCrQ/viewform)
81
+ """
82
+ REVIEW_TEXT_2 = """**If a request should be reviewed or dropped submit its id here/ إذا كان يجب مراجعة أو حذف طلب، أدخل رقمه هنا:**"""
src/utils.py ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import folium
2
+ import pandas as pd
3
+ from folium import plugins
4
+ from src.map_utils import legend_macro
5
+
6
+
7
+ EPICENTER_LOCATION = [31.12210171476489, -8.42945837915193]
8
+ BORDER_COLOR = "black"
9
+
10
+ def parse_gg_sheet(url):
11
+ url = url.replace("edit#gid=", "export?format=csv&gid=")
12
+ print(url)
13
+ df = pd.read_csv(url, on_bad_lines="warn")
14
+
15
+ # parse latlng (column 4) to [lat, lng]
16
+ def parse_latlng(latlng):
17
+ try:
18
+ lat, lng = latlng.split(",")
19
+ return [float(lat), float(lng)]
20
+ except Exception as e:
21
+ print(f"Error parsing latlng: {e}")
22
+ return None
23
+
24
+ if df.shape[1] > 4:
25
+ df = df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
26
+ return df
27
+
28
+
29
+ def add_epicentre_to_map(map_obj):
30
+ icon_epicentre = folium.plugins.BeautifyIcon(
31
+ icon='spinner',
32
+ spin=True,
33
+ border_color='#b3334f',
34
+ background_color='#b3334f',
35
+ text_color='white'
36
+ )
37
+ folium.Marker(location=EPICENTER_LOCATION,
38
+ popup="Epicenter مركز الزلزال",
39
+ icon=icon_epicentre).add_to(map_obj)
40
+
41
+
42
+ def add_danger_distances_to_map(map_obj):
43
+ Danger_Distances_group = folium.FeatureGroup(name='Danger distances - earthquake magnitude 7 | مسافات الخطر - قوة الزلازل 7').add_to(map_obj)
44
+
45
+ zones = [
46
+ {"radius": 100000, "fill_opacity": 0.1, "weight": 1, "fill_color": "yellow", "tooltip": "50 to 100 km - Moderate risk area | منطقة خطر معتدلة"},
47
+ {"radius": 50000, "fill_opacity": 0.1, "weight": 1, "fill_color": "orange", "tooltip": "30 to 50 km - High risk zone | منطقة عالية المخاطر"},
48
+ {"radius": 30000, "fill_opacity": 0.2, "weight": 1, "fill_color": "#FF0000", "tooltip": "10 to 30 km - Very high risk zone | منطقة شديدة الخطورة"},
49
+ {"radius": 10000, "fill_opacity": 0.2, "weight": 0.2, "fill_color": "#8B0000", "tooltip": "0 to 10km - direct impact zone | منطقة التأثير المباشر"}
50
+ ]
51
+
52
+ for zone in zones:
53
+ folium.Circle(
54
+ location=EPICENTER_LOCATION,
55
+ radius=zone["radius"],
56
+ color=BORDER_COLOR,
57
+ weight=zone["weight"],
58
+ fill_opacity=zone["fill_opacity"],
59
+ opacity=zone["fill_opacity"], # Assuming border opacity should match fill_opacity
60
+ fill_color=zone["fill_color"],
61
+ tooltip=zone["tooltip"],
62
+ ).add_to(Danger_Distances_group)
63
+
64
+
65
+ def init_map():
66
+ m = folium.Map(
67
+ location=[31.228674, -7.992047],
68
+ zoom_start=8.5,
69
+ min_zoom=8.5,
70
+ max_lat=35.628674,
71
+ min_lat=29.628674,
72
+ max_lon=-4.992047,
73
+ min_lon=-10.992047,
74
+ max_bounds=True,
75
+ )
76
+ # Add a search bar to the map
77
+ plugins.Geocoder(
78
+ collapsed=False,
79
+ position="topright",
80
+ placeholder="Search | البحث",
81
+ ).add_to(m)
82
+
83
+ # Add Fullscreen button to the map
84
+ plugins.Fullscreen(
85
+ position="topright",
86
+ title="Expand me | تكبير الخريطة",
87
+ title_cancel="Exit me | تصغير الخريطة",
88
+ force_separate_button=True,
89
+ ).add_to(m)
90
+
91
+ # Satellite View from Mapbox
92
+ tileurl = "https://api.mapbox.com/styles/v1/phd2020/clmer2mra01d001pbgjkictpt/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoicGhkMjAyMCIsImEiOiJja29lZzFwZmUwNHkzMm5wMjZnYjVvcGltIn0.tE0ritrelQOyLdKUH6hgOw"
93
+ folium.TileLayer(
94
+ tiles=tileurl,
95
+ attr="Satellite View",
96
+ name="Satellite View | عرض القمر الصناعي",
97
+ overlay=False,
98
+ control=True,
99
+ ).add_to(m)
100
+
101
+ # Add danger zones
102
+ add_epicentre_to_map(m)
103
+ add_danger_distances_to_map(m)
104
+
105
+ # Add a LayerControl to the map to toggle between layers (Satellite View and Default One)
106
+ folium.LayerControl().add_to(m)
107
+
108
+ # Macro to add legend
109
+ m.get_root().add_child(legend_macro)
110
+ return m