m-ric HF staff commited on
Commit
c9be6b5
1 Parent(s): 2c0c8d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -11,6 +11,7 @@ from huggingface_hub import InferenceClient
11
  from geopy.geocoders import Nominatim
12
  from collections import OrderedDict
13
  from geopy.adapters import AioHTTPAdapter
 
14
  import nest_asyncio
15
  nest_asyncio.apply()
16
 
@@ -160,8 +161,9 @@ def geocode_addresses(addresses):
160
 
161
  def create_map_from_markers(dataframe):
162
  coordinates = geocode_addresses(dataframe["name"])
163
- dataframe["lat"] = [coords['lat'] if coords else None for coords in coordinates]
164
- dataframe["lon"] = [coords['lon'] if coords else None for coords in coordinates]
 
165
 
166
  f_map = Map(
167
  location=[dataframe["lat"].mean(), dataframe["lon"].mean()],
@@ -171,19 +173,17 @@ def create_map_from_markers(dataframe):
171
  for _, row in dataframe.iterrows():
172
  if np.isnan(row["lat"]) or np.isnan(row["lon"]):
173
  continue
174
- marker = folium.CircleMarker(
 
 
 
175
  location=[row["lat"], row["lon"]],
176
- radius=10,
177
- popup=folium.Popup(
178
- f"<h4>{row['name']}</h4><p>{row['description']}</p>", max_width=450
179
- ),
180
- fill=True,
181
- fill_color="blue",
182
- fill_opacity=0.6,
183
- color="blue",
184
- weight=1,
185
  )
186
  marker.add_to(f_map),
 
 
187
 
188
  bounds = [[row["lat"], row["lon"]] for _, row in dataframe.iterrows()]
189
  f_map.fit_bounds(bounds, padding=(100, 100))
 
11
  from geopy.geocoders import Nominatim
12
  from collections import OrderedDict
13
  from geopy.adapters import AioHTTPAdapter
14
+
15
  import nest_asyncio
16
  nest_asyncio.apply()
17
 
 
161
 
162
  def create_map_from_markers(dataframe):
163
  coordinates = geocode_addresses(dataframe["name"])
164
+ print({name: coordinates[i] for i, name in enumerate(dataframe["name"].to_list())})
165
+ dataframe["lat"] = [coords["lat"] if coords else None for coords in coordinates]
166
+ dataframe["lon"] = [coords["lon"] if coords else None for coords in coordinates]
167
 
168
  f_map = Map(
169
  location=[dataframe["lat"].mean(), dataframe["lon"].mean()],
 
173
  for _, row in dataframe.iterrows():
174
  if np.isnan(row["lat"]) or np.isnan(row["lon"]):
175
  continue
176
+ popup_message = f"<h4>{row['name']}</h4><p style='font-weight:500'>{row['description']}</p>"
177
+ popup_message += f"<a href='https://www.google.com/search?q={row['name']}' target='_blank'><b>Learn more about {row['name'].split(',')[0]}</b></a>"
178
+
179
+ marker = folium.Marker(
180
  location=[row["lat"], row["lon"]],
181
+ popup=folium.Popup(popup_message, max_width=300),
182
+ icon=folium.Icon(color="yellow",icon="fa-circle-dot", prefix='fa'),
 
 
 
 
 
 
 
183
  )
184
  marker.add_to(f_map),
185
+
186
+ folium.plugins.Fullscreen(position='topright', title='Expand me', title_cancel='Exit me', force_separate_button=True).add_to(f_map)
187
 
188
  bounds = [[row["lat"], row["lon"]] for _, row in dataframe.iterrows()]
189
  f_map.fit_bounds(bounds, padding=(100, 100))