Spaces:
Sleeping
Sleeping
add app
Browse files- app.py +48 -0
- requirements.dev.txt +2 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import folium
|
| 3 |
+
from folium.plugins import MarkerCluster
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from streamlit_folium import folium_static
|
| 6 |
+
|
| 7 |
+
from srai.regionalizers import geocode_to_region_gdf
|
| 8 |
+
|
| 9 |
+
# Define the function to create a map with markers
|
| 10 |
+
def create_map(points, color, marker_cluster):
|
| 11 |
+
points.apply(lambda row: folium.Marker(location=[row.y, row.x], icon=folium.Icon(color=color)).add_to(marker_cluster))
|
| 12 |
+
|
| 13 |
+
# Define the function to get the center of the region
|
| 14 |
+
def get_center(region):
|
| 15 |
+
boundary = geocode_to_region_gdf(region)
|
| 16 |
+
return boundary.centroid.iloc[0]
|
| 17 |
+
|
| 18 |
+
# Define the function to get the points of the region
|
| 19 |
+
def get_points(region, size):
|
| 20 |
+
boundary = geocode_to_region_gdf(region)
|
| 21 |
+
return boundary["geometry"].sample_points(size=size).explode()
|
| 22 |
+
|
| 23 |
+
# Set up the map
|
| 24 |
+
map_center = (52.34260, 20.04503)
|
| 25 |
+
poland_center = get_center("Poland")
|
| 26 |
+
my_map = folium.Map(location = (poland_center.y, poland_center.x), zoom_start = 5)
|
| 27 |
+
|
| 28 |
+
marker_cluster = MarkerCluster().add_to(my_map)
|
| 29 |
+
|
| 30 |
+
# Set up the sliders
|
| 31 |
+
poland_points_num = st.sidebar.slider('Number of points for Poland', 0, 500, 350)
|
| 32 |
+
riga_points_num = st.sidebar.slider('Number of points for Riga, Latvia', 0, 25, 5)
|
| 33 |
+
tallin_points_num = st.sidebar.slider('Number of points for Tallin, Estonia', 0, 25, 5)
|
| 34 |
+
pskov_points_num = st.sidebar.slider('Number of points for Pskov', 0, 25, 25)
|
| 35 |
+
|
| 36 |
+
poland_points = get_points("Poland", poland_points_num)
|
| 37 |
+
pskov_points = get_points("Pskov", pskov_points_num)
|
| 38 |
+
riga_points = get_points("Riga", riga_points_num)
|
| 39 |
+
tallin_points = get_points("Tallin", tallin_points_num)
|
| 40 |
+
|
| 41 |
+
# Create the map with markers
|
| 42 |
+
create_map(poland_points, 'blue', marker_cluster)
|
| 43 |
+
create_map(riga_points, 'blue', marker_cluster)
|
| 44 |
+
create_map(tallin_points, 'blue', marker_cluster)
|
| 45 |
+
create_map(pskov_points, 'red', marker_cluster)
|
| 46 |
+
|
| 47 |
+
# Display the map
|
| 48 |
+
st_data = folium_static(my_map)
|
requirements.dev.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-r requirements.txt
|
| 2 |
+
streamlit==1.34.0
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit-folium
|
| 2 |
+
folium
|
| 3 |
+
srai~=0.7
|