Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from folium.plugins import MarkerCluster
|
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
import streamlit as st
|
|
|
8 |
|
9 |
# Load data from Excel URL with error handling
|
10 |
def load_data(url):
|
@@ -43,7 +44,7 @@ def find_data_center(df, n_clusters=1):
|
|
43 |
kmeans = KMeans(n_clusters=n_clusters, random_state=0).fit(df[["latitude", "longitude"]])
|
44 |
return kmeans.cluster_centers_
|
45 |
|
46 |
-
# Plot the map with markers
|
47 |
def plot_map(df, center):
|
48 |
if df.empty:
|
49 |
st.write("Dataframe is empty, skipping map plotting")
|
@@ -72,7 +73,9 @@ def plot_map(df, center):
|
|
72 |
icon=folium.Icon(color="red", icon="cloud")
|
73 |
).add_to(map)
|
74 |
|
75 |
-
|
|
|
|
|
76 |
|
77 |
# Calculate the impact of data center on latency and bandwidth
|
78 |
def calculate_impact(df, center):
|
@@ -124,12 +127,12 @@ def main():
|
|
124 |
st.write("Could not find data center, exiting application.")
|
125 |
return
|
126 |
|
127 |
-
# Create the map and
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
|
134 |
# Calculate the impact of adding the data center
|
135 |
latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before = calculate_impact(df, center)
|
|
|
5 |
import requests
|
6 |
from io import BytesIO
|
7 |
import streamlit as st
|
8 |
+
import streamlit.components.v1 as components
|
9 |
|
10 |
# Load data from Excel URL with error handling
|
11 |
def load_data(url):
|
|
|
44 |
kmeans = KMeans(n_clusters=n_clusters, random_state=0).fit(df[["latitude", "longitude"]])
|
45 |
return kmeans.cluster_centers_
|
46 |
|
47 |
+
# Plot the map with markers and save as HTML
|
48 |
def plot_map(df, center):
|
49 |
if df.empty:
|
50 |
st.write("Dataframe is empty, skipping map plotting")
|
|
|
73 |
icon=folium.Icon(color="red", icon="cloud")
|
74 |
).add_to(map)
|
75 |
|
76 |
+
# Save the map as an HTML file
|
77 |
+
map.save("map.html")
|
78 |
+
return "map.html"
|
79 |
|
80 |
# Calculate the impact of data center on latency and bandwidth
|
81 |
def calculate_impact(df, center):
|
|
|
127 |
st.write("Could not find data center, exiting application.")
|
128 |
return
|
129 |
|
130 |
+
# Create the map and save it as an HTML file
|
131 |
+
map_file = plot_map(df, center)
|
132 |
+
|
133 |
+
# Embed the map in the Streamlit app using st.components.v1.html
|
134 |
+
if map_file:
|
135 |
+
components.html(open(map_file, 'r').read(), height=600)
|
136 |
|
137 |
# Calculate the impact of adding the data center
|
138 |
latency_reduction, download_increase, upload_increase, avg_latency_before, avg_download_before, avg_upload_before = calculate_impact(df, center)
|