Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ from sklearn.cluster import KMeans
|
|
| 4 |
from folium.plugins import MarkerCluster
|
| 5 |
import requests
|
| 6 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load data from Excel (directly from the URL)
|
| 9 |
def load_data(url):
|
|
@@ -42,10 +45,11 @@ def find_data_center(df, n_clusters=1):
|
|
| 42 |
|
| 43 |
# Create a map and plot the points
|
| 44 |
def plot_map(df, center):
|
|
|
|
| 45 |
map = folium.Map(location=[center[0][0], center[0][1]], zoom_start=10)
|
| 46 |
marker_cluster = MarkerCluster().add_to(map)
|
| 47 |
|
| 48 |
-
# Add school locations
|
| 49 |
for idx, row in df.iterrows():
|
| 50 |
school_name = row.get("school_name", "No Name Provided") # Ensure correct column access
|
| 51 |
|
|
@@ -60,7 +64,7 @@ def plot_map(df, center):
|
|
| 60 |
icon=folium.Icon(color="blue", icon="info-sign")
|
| 61 |
).add_to(marker_cluster)
|
| 62 |
|
| 63 |
-
# Add data center
|
| 64 |
folium.Marker(
|
| 65 |
location=[center[0][0], center[0][1]],
|
| 66 |
popup="Proposed Data Center",
|
|
@@ -75,8 +79,13 @@ def main():
|
|
| 75 |
df = load_data(url)
|
| 76 |
center = find_data_center(df)
|
| 77 |
map = plot_map(df, center)
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
main()
|
|
|
|
| 4 |
from folium.plugins import MarkerCluster
|
| 5 |
import requests
|
| 6 |
from io import BytesIO
|
| 7 |
+
import streamlit as st
|
| 8 |
+
import folium
|
| 9 |
+
from streamlit.components.v1 import html
|
| 10 |
|
| 11 |
# Load data from Excel (directly from the URL)
|
| 12 |
def load_data(url):
|
|
|
|
| 45 |
|
| 46 |
# Create a map and plot the points
|
| 47 |
def plot_map(df, center):
|
| 48 |
+
# Create map centered on the data center location
|
| 49 |
map = folium.Map(location=[center[0][0], center[0][1]], zoom_start=10)
|
| 50 |
marker_cluster = MarkerCluster().add_to(map)
|
| 51 |
|
| 52 |
+
# Add school locations to the map
|
| 53 |
for idx, row in df.iterrows():
|
| 54 |
school_name = row.get("school_name", "No Name Provided") # Ensure correct column access
|
| 55 |
|
|
|
|
| 64 |
icon=folium.Icon(color="blue", icon="info-sign")
|
| 65 |
).add_to(marker_cluster)
|
| 66 |
|
| 67 |
+
# Add data center location to the map
|
| 68 |
folium.Marker(
|
| 69 |
location=[center[0][0], center[0][1]],
|
| 70 |
popup="Proposed Data Center",
|
|
|
|
| 79 |
df = load_data(url)
|
| 80 |
center = find_data_center(df)
|
| 81 |
map = plot_map(df, center)
|
| 82 |
+
|
| 83 |
+
# Embed the map directly in the Streamlit app
|
| 84 |
+
map_html = map._repr_html_() # Render the folium map as HTML
|
| 85 |
+
html(map_html, width=700, height=500) # Adjust the size of the embedded map
|
| 86 |
+
|
| 87 |
+
st.title("Data Center Location Mapping")
|
| 88 |
+
st.write("This map shows school locations and proposed data center locations based on clustering.")
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
main()
|