nakas commited on
Commit
3af972c
·
verified ·
1 Parent(s): e109717

Update air_quality_map.py

Browse files
Files changed (1) hide show
  1. air_quality_map.py +7 -21
air_quality_map.py CHANGED
@@ -3,7 +3,6 @@ import requests
3
  import pandas as pd
4
  import folium
5
  from folium.plugins import MarkerCluster
6
- from branca.element import Figure
7
  import tempfile
8
  import os
9
  import json
@@ -212,10 +211,8 @@ class AirQualityApp:
212
  center_lat = df["latitude"].mean()
213
  center_lon = df["longitude"].mean()
214
 
215
- # Create a figure with a specific size
216
- fig = Figure(width=800, height=600)
217
- m = folium.Map(location=[center_lat, center_lon], zoom_start=7)
218
- fig.add_child(m)
219
 
220
  # Add a marker cluster
221
  marker_cluster = MarkerCluster().add_to(m)
@@ -275,10 +272,8 @@ class AirQualityApp:
275
  legend_html += "</div>"
276
  m.get_root().html.add_child(folium.Element(legend_html))
277
 
278
- # Save the map to a temporary file and return its path
279
- with tempfile.NamedTemporaryFile(delete=False, suffix='.html') as tmp:
280
- m.save(tmp.name)
281
- return tmp.name
282
 
283
  def get_aqi_category(self, aqi_value):
284
  """Determine AQI category based on value"""
@@ -525,19 +520,10 @@ def create_air_quality_map_ui():
525
  parameter_code = parameter.split(":")[0].strip()
526
 
527
  # Generate the map
528
- map_path = app.create_map(state, county_code, parameter_code)
529
 
530
- if isinstance(map_path, str) and map_path.endswith('.html'):
531
- # Read the HTML file
532
- with open(map_path, 'r', encoding='utf-8') as f:
533
- html_content = f.read()
534
-
535
- # Clean up the temporary file
536
- os.unlink(map_path)
537
-
538
- return html_content
539
- else:
540
- return map_path # Return error message
541
 
542
  # Create the UI
543
  with gr.Blocks(title="Air Quality Monitoring Stations") as interface:
 
3
  import pandas as pd
4
  import folium
5
  from folium.plugins import MarkerCluster
 
6
  import tempfile
7
  import os
8
  import json
 
211
  center_lat = df["latitude"].mean()
212
  center_lon = df["longitude"].mean()
213
 
214
+ # Create a map with a specific width and height
215
+ m = folium.Map(location=[center_lat, center_lon], zoom_start=7, width='100%', height=500)
 
 
216
 
217
  # Add a marker cluster
218
  marker_cluster = MarkerCluster().add_to(m)
 
272
  legend_html += "</div>"
273
  m.get_root().html.add_child(folium.Element(legend_html))
274
 
275
+ # Return the HTML directly instead of saving to a file
276
+ return m._repr_html_()
 
 
277
 
278
  def get_aqi_category(self, aqi_value):
279
  """Determine AQI category based on value"""
 
520
  parameter_code = parameter.split(":")[0].strip()
521
 
522
  # Generate the map
523
+ result = app.create_map(state, county_code, parameter_code)
524
 
525
+ # Return the HTML directly
526
+ return result
 
 
 
 
 
 
 
 
 
527
 
528
  # Create the UI
529
  with gr.Blocks(title="Air Quality Monitoring Stations") as interface: