Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from io import BytesIO
|
|
7 |
import geopandas as gpd
|
8 |
|
9 |
# Load datasets
|
|
|
10 |
cbg_geographic_data = pd.read_csv("data/cbg_geographic_data.csv")
|
11 |
df_weekly = pd.read_parquet("data/mobility/tn_weekly_mobility_2019.parquet")
|
12 |
largest_counties = cbg_geographic_data.groupby('county')['pop10'].sum().nlargest(10).index
|
@@ -46,15 +47,43 @@ def plot_population_by_county():
|
|
46 |
|
47 |
# Function to create a Folium map with county boundaries
|
48 |
def create_map():
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
counties_geo = gpd.read_file("data/county/01_county-shape-file.shp")
|
51 |
counties_geo = counties_geo[counties_geo['statefp'] == '47'] # Filter for Tennessee
|
52 |
|
|
|
53 |
folium.GeoJson(counties_geo).add_to(m)
|
|
|
|
|
54 |
MousePosition().add_to(m)
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
return m._repr_html_()
|
57 |
|
|
|
58 |
# Gradio Interface
|
59 |
with gr.Blocks() as app:
|
60 |
gr.Markdown("# Kora Customer Map Analysis")
|
|
|
7 |
import geopandas as gpd
|
8 |
|
9 |
# Load datasets
|
10 |
+
df_md_final1=pd.read_csv("data/location-of-auto-businesses.csv")
|
11 |
cbg_geographic_data = pd.read_csv("data/cbg_geographic_data.csv")
|
12 |
df_weekly = pd.read_parquet("data/mobility/tn_weekly_mobility_2019.parquet")
|
13 |
largest_counties = cbg_geographic_data.groupby('county')['pop10'].sum().nlargest(10).index
|
|
|
47 |
|
48 |
# Function to create a Folium map with county boundaries
|
49 |
def create_map():
|
50 |
+
import folium
|
51 |
+
from folium.plugins import MousePosition
|
52 |
+
import geopandas as gpd
|
53 |
+
|
54 |
+
# Create the base map centered on Tennessee
|
55 |
+
m = folium.Map(location=[35.8601, -86.6602], zoom_start=8)
|
56 |
+
|
57 |
+
# Load and filter county boundaries for Tennessee
|
58 |
counties_geo = gpd.read_file("data/county/01_county-shape-file.shp")
|
59 |
counties_geo = counties_geo[counties_geo['statefp'] == '47'] # Filter for Tennessee
|
60 |
|
61 |
+
# Add county boundaries to the map
|
62 |
folium.GeoJson(counties_geo).add_to(m)
|
63 |
+
|
64 |
+
# Add mouse position plugin
|
65 |
MousePosition().add_to(m)
|
66 |
|
67 |
+
# Assume df_md_final1 is a pandas DataFrame loaded previously
|
68 |
+
# It should have columns 'md_x' (longitude), 'md_y' (latitude), and 'name'
|
69 |
+
|
70 |
+
# Iterate over the dataframe and add markers
|
71 |
+
for idx, row in df_md_final1.iterrows():
|
72 |
+
folium.Marker(
|
73 |
+
location=[row['md_y'], row['md_x']],
|
74 |
+
popup=str(row['name'])
|
75 |
+
).add_to(m)
|
76 |
+
|
77 |
+
# Set the map bounds to Tennessee
|
78 |
+
m.fit_bounds([
|
79 |
+
[34.9829, -90.3103], # Southwest corner of Tennessee
|
80 |
+
[36.6781, -81.6469] # Northeast corner of Tennessee
|
81 |
+
])
|
82 |
+
|
83 |
+
# Return the map's HTML representation
|
84 |
return m._repr_html_()
|
85 |
|
86 |
+
|
87 |
# Gradio Interface
|
88 |
with gr.Blocks() as app:
|
89 |
gr.Markdown("# Kora Customer Map Analysis")
|