Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import geopandas
|
|
@@ -71,6 +173,19 @@ if uploaded_file is not None:
|
|
| 71 |
tooltip=folium.GeoJsonTooltip(fields=['ISD'], aliases=['ISD:'])
|
| 72 |
).add_to(m)
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
# call to render Folium map in Streamlit
|
| 75 |
st_data = st_folium(m, width=725)
|
| 76 |
|
|
@@ -86,15 +201,3 @@ if uploaded_file is not None:
|
|
| 86 |
mime="text/html"
|
| 87 |
)
|
| 88 |
|
| 89 |
-
# Displaying ISDs with a count of 1
|
| 90 |
-
ISDs_with_one = ISD_Combined[ISD_Combined['Count'] == 1]
|
| 91 |
-
if not ISDs_with_one.empty:
|
| 92 |
-
st.write("ISDs:")
|
| 93 |
-
# st.dataframe(ISDs_with_one[['ISD', 'ISD Code']])
|
| 94 |
-
st.dataframe(ISDs_with_one[['ISD', 'ISD Code']].reset_index(drop=True))
|
| 95 |
-
|
| 96 |
-
# Informing the user about the total number of ISD with a count of 1
|
| 97 |
-
total_ISDs_with_one = len(ISDs_with_one)
|
| 98 |
-
st.write(f"Total number of ISD: {total_ISDs_with_one}")
|
| 99 |
-
else:
|
| 100 |
-
st.write("No ISD have a count of 1.")
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# import pandas as pd
|
| 3 |
+
# import geopandas
|
| 4 |
+
# import folium
|
| 5 |
+
# from streamlit_folium import st_folium
|
| 6 |
+
# from pathlib import Path
|
| 7 |
+
# import tempfile
|
| 8 |
+
|
| 9 |
+
# # Streamlit page setup
|
| 10 |
+
# st.set_page_config(page_title="ISD Mapping", layout="centered", initial_sidebar_state="collapsed")
|
| 11 |
+
# st.image('MTSS.ai_Logo.png', width=300) # Adjust path as needed
|
| 12 |
+
# st.header('MTSS Maps™ | ISDs')
|
| 13 |
+
# st.subheader('Map Generator')
|
| 14 |
+
|
| 15 |
+
# # CSV file upload
|
| 16 |
+
# # uploaded_file = st.file_uploader("Upload your ISD data CSV", type=["csv"])
|
| 17 |
+
# # if uploaded_file is not None:
|
| 18 |
+
# # df = pd.read_csv(uploaded_file)
|
| 19 |
+
|
| 20 |
+
# # Excel file upload
|
| 21 |
+
# uploaded_file = st.file_uploader("Upload your ISD data XLSX", type=["xlsx"])
|
| 22 |
+
# if uploaded_file is not None:
|
| 23 |
+
# # Specify dtype as str for 'ISD Code' to ensure it reads in as string
|
| 24 |
+
# df = pd.read_excel(uploaded_file, dtype={"ISD Code": str})
|
| 25 |
+
|
| 26 |
+
# # Add column "Count" and add 1 to all rows
|
| 27 |
+
# df['Count'] = 1
|
| 28 |
+
|
| 29 |
+
# # If the 'ISD Code' column contains integers without leading zeros, add them
|
| 30 |
+
# df['ISD Code'] = df['ISD Code'].apply(lambda x: str(x).zfill(5))
|
| 31 |
+
|
| 32 |
+
# # Load GeoJSON file from the root directory
|
| 33 |
+
# geojson_filename = "Intermediate_School_Districts.geojson" # Name of your GeoJSON file
|
| 34 |
+
# geojson_path = Path(__file__).parent / geojson_filename # Construct the path to the GeoJSON file
|
| 35 |
+
|
| 36 |
+
# if geojson_path.exists():
|
| 37 |
+
# Mi_ISD_geojson = geopandas.read_file(str(geojson_path))
|
| 38 |
+
# Mi_ISD_geojson.rename(columns={'ISD': 'ISD Code', 'NAME': 'ISD'}, inplace=True)
|
| 39 |
+
|
| 40 |
+
# # Drop unwanted columns
|
| 41 |
+
# columns_to_drop = ['OBJECTID', 'LABEL', 'TYPE', 'SQKM', 'SQMILES', 'ACRES', 'VER','LAYOUT', 'PENINSULA', 'ISDCode', 'ISD1', 'ShapeSTArea', 'ShapeSTLength']
|
| 42 |
+
# Mi_ISD_geojson.drop(columns=columns_to_drop, axis=1, inplace=True)
|
| 43 |
+
|
| 44 |
+
# # Ensure 'ISD Code' is treated as a string to preserve leading zeros
|
| 45 |
+
# Mi_ISD_geojson['ISD Code'] = Mi_ISD_geojson['ISD Code'].astype(str)
|
| 46 |
+
|
| 47 |
+
# # If the 'ISD Code' column contains integers without leading zeros, add them
|
| 48 |
+
# Mi_ISD_geojson['ISD Code'] = Mi_ISD_geojson['ISD Code'].apply(lambda x: str(x).zfill(5))
|
| 49 |
+
|
| 50 |
+
# # Merge GeoJSON file and DataFrame
|
| 51 |
+
# ISD_Combined = pd.merge(Mi_ISD_geojson, df, on='ISD Code', how='left', suffixes=('', '_drop')).fillna(0)
|
| 52 |
+
|
| 53 |
+
# # Identify any columns that end with '_drop' and drop them
|
| 54 |
+
# ISD_Combined = ISD_Combined.loc[:, ~ISD_Combined.columns.str.endswith('_drop')]
|
| 55 |
+
|
| 56 |
+
# # Generating the Folium map
|
| 57 |
+
# def style_function(feature):
|
| 58 |
+
# count = feature['properties'].get('Count', 0)
|
| 59 |
+
# return {
|
| 60 |
+
# 'fillColor': '#48BB88' if count > 0 else 'white',
|
| 61 |
+
# 'color': 'black',
|
| 62 |
+
# 'weight': 0.15,
|
| 63 |
+
# 'fillOpacity': 0.7 if count > 0 else 0.25,
|
| 64 |
+
# 'lineOpacity': 0.4,
|
| 65 |
+
# }
|
| 66 |
+
|
| 67 |
+
# m = folium.Map(location=[44.3148, -85.6024], zoom_start=7)
|
| 68 |
+
# folium.GeoJson(
|
| 69 |
+
# ISD_Combined.to_json(),
|
| 70 |
+
# style_function=style_function,
|
| 71 |
+
# tooltip=folium.GeoJsonTooltip(fields=['ISD'], aliases=['ISD:'])
|
| 72 |
+
# ).add_to(m)
|
| 73 |
+
|
| 74 |
+
# # call to render Folium map in Streamlit
|
| 75 |
+
# st_data = st_folium(m, width=725)
|
| 76 |
+
|
| 77 |
+
# # Save the map to a temporary HTML file and offer it for download
|
| 78 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
|
| 79 |
+
# m.save(tmpfile.name)
|
| 80 |
+
# tmpfile.seek(0)
|
| 81 |
+
# with open(tmpfile.name, "rb") as file:
|
| 82 |
+
# btn = st.download_button(
|
| 83 |
+
# label="Download Map as HTML",
|
| 84 |
+
# data=file,
|
| 85 |
+
# file_name="District_Map.html",
|
| 86 |
+
# mime="text/html"
|
| 87 |
+
# )
|
| 88 |
+
|
| 89 |
+
# # Displaying ISDs with a count of 1
|
| 90 |
+
# ISDs_with_one = ISD_Combined[ISD_Combined['Count'] == 1]
|
| 91 |
+
# if not ISDs_with_one.empty:
|
| 92 |
+
# st.write("ISDs:")
|
| 93 |
+
# # st.dataframe(ISDs_with_one[['ISD', 'ISD Code']])
|
| 94 |
+
# st.dataframe(ISDs_with_one[['ISD', 'ISD Code']].reset_index(drop=True))
|
| 95 |
+
|
| 96 |
+
# # Informing the user about the total number of ISD with a count of 1
|
| 97 |
+
# total_ISDs_with_one = len(ISDs_with_one)
|
| 98 |
+
# st.write(f"Total number of ISD: {total_ISDs_with_one}")
|
| 99 |
+
# else:
|
| 100 |
+
# st.write("No ISD have a count of 1.")
|
| 101 |
+
|
| 102 |
+
|
| 103 |
import streamlit as st
|
| 104 |
import pandas as pd
|
| 105 |
import geopandas
|
|
|
|
| 173 |
tooltip=folium.GeoJsonTooltip(fields=['ISD'], aliases=['ISD:'])
|
| 174 |
).add_to(m)
|
| 175 |
|
| 176 |
+
# Displaying ISDs with a count of 1
|
| 177 |
+
ISDs_with_one = ISD_Combined[ISD_Combined['Count'] == 1]
|
| 178 |
+
if not ISDs_with_one.empty:
|
| 179 |
+
st.write("ISDs:")
|
| 180 |
+
# st.dataframe(ISDs_with_one[['ISD', 'ISD Code']])
|
| 181 |
+
st.dataframe(ISDs_with_one[['ISD', 'ISD Code']].reset_index(drop=True))
|
| 182 |
+
|
| 183 |
+
# Informing the user about the total number of ISD with a count of 1
|
| 184 |
+
total_ISDs_with_one = len(ISDs_with_one)
|
| 185 |
+
st.write(f"Total number of ISD: {total_ISDs_with_one}")
|
| 186 |
+
else:
|
| 187 |
+
st.write("No ISD have a count of 1.")
|
| 188 |
+
|
| 189 |
# call to render Folium map in Streamlit
|
| 190 |
st_data = st_folium(m, width=725)
|
| 191 |
|
|
|
|
| 201 |
mime="text/html"
|
| 202 |
)
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|