Skip to content

Commit 1668867

Browse files
Fix deps + use smaller bbox
1 parent 83329fd commit 1668867

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ then
88
python3 -m hackyeah2024.main ${CMD} ${CMD_ARGS}
99
else
1010
echo "No CLI command provided, running Streamlit server"
11-
python3 -m streamlit run hackyeah2024/server.py
11+
python3 -m streamlit run hackyeah2024/server.py --server.headless true
1212
fi

hackyeah2024/server.py

+29-27
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
from osmnx import distance, features_from_bbox, geocoder, graph_from_bbox, routing
44
from streamlit_folium import st_folium
55

6-
bounding_box = {'min_lat': 49.174522, 'max_lat': 50.526524, 'min_lon': 19.076385, 'max_lon': 21.432953}
6+
bbox = {'min_lat': 49.880478, 'max_lat': 50.373496,
7+
'min_lon': 20.478516, 'max_lon': 21.242065}
78

89

910
@st.cache_resource
1011
def get_graph():
11-
return graph_from_bbox(
12-
bbox=(bounding_box['max_lat'], bounding_box['min_lat'], bounding_box['min_lon'], bounding_box['max_lon']),
12+
graph = graph_from_bbox(
13+
bbox=(bbox['max_lat'], bbox['min_lat'], bbox['min_lon'], bbox['max_lon']),
1314
network_type='bike',
1415
simplify=False,
1516
retain_all=True,
1617
)
18+
print('Constructed graph')
19+
return graph
20+
1721

1822

1923
@st.cache_data
@@ -26,21 +30,34 @@ def get_route_points(start, end):
2630
# print(o, d)
2731
route = routing.shortest_path(G, o, d)
2832
points = [G.nodes[x] for x in route]
33+
print("Computed route")
2934
return [(x['y'], x['x']) for x in points]
3035

3136

32-
def plot_route(map_, route_pts):
33-
route = folium.PolyLine(locations=route_pts, weight=2)
34-
map_.add_child(route)
35-
return map
37+
@st.cache_resource
38+
def get_map():
39+
map_ = folium.Map(
40+
max_bounds=True,
41+
location=[0.5 * (bbox['min_lat'] + bbox['max_lat']), 0.5 * (bbox['min_lon'] + bbox['max_lon'])],
42+
zoom_start=9,
43+
tiles='OpenStreetMap',
44+
min_lon=19.076385,
45+
max_lon=21.432953,
46+
min_lat=49.174522,
47+
max_lat=50.526524,
48+
)
49+
marker = folium.Marker([50.01381, 20.98698], popup='Tarnów', tooltip='Tarnów')
50+
map_.add_child(marker)
51+
print('Constructed map')
52+
return map_
3653

3754

3855
@st.cache_data
3956
def get_localities():
4057
print('Fetching localities')
4158
x = tuple(
4259
features_from_bbox(
43-
bbox=(bounding_box['max_lat'], bounding_box['min_lat'], bounding_box['min_lon'], bounding_box['max_lon']),
60+
bbox=(bbox['max_lat'], bbox['min_lat'], bbox['min_lon'], bbox['max_lon']),
4461
tags={'place': ['town', 'vilage']},
4562
)['name'].values
4663
)
@@ -66,26 +83,11 @@ def run_server():
6683

6784
cont2 = st.container()
6885

69-
# center on Liberty Bell, add marker
70-
map_ = folium.Map(
71-
max_bounds=True,
72-
location=[0.5 * (49.174522 + 50.526524), 0.5 * (19.944544 + 21.432953)],
73-
zoom_start=9,
74-
tiles='OpenStreetMap',
75-
min_lon=19.076385,
76-
max_lon=21.432953,
77-
min_lat=49.174522,
78-
max_lat=50.526524,
79-
)
80-
marker = folium.Marker([50.049683, 19.944544], popup='Kraków', tooltip='Kraków')
81-
map_.add_child(marker)
82-
83-
route_pts = get_route_points(origin, destination)
84-
85-
plot_route(map_, route_pts)
86-
8786
with cont2:
88-
# call to render Folium map in Streamlit
87+
map_ = get_map()
88+
route_pts = get_route_points(origin, destination)
89+
route = folium.PolyLine(locations=route_pts, weight=2)
90+
map_.add_child(route)
8991
_st_data = st_folium(map_, width=725)
9092

9193

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"streamlit_folium",
1111
"taxicab",
1212
"osmnx",
13-
"scikt-learn",
13+
"scikit-learn",
1414
]
1515

1616

requirements.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ jinja2==3.1.4
4848
# folium
4949
# pydeck
5050
# streamlit-folium
51+
joblib==1.4.2
52+
# via scikit-learn
5153
jsonschema==4.23.0
5254
# via altair
5355
jsonschema-specifications==2023.12.1
@@ -79,11 +81,15 @@ numpy==2.1.1
7981
# pyarrow
8082
# pydeck
8183
# pyogrio
84+
# scikit-learn
85+
# scipy
8286
# shapely
8387
# streamlit
8488
# taxicab
8589
osmnx==1.9.3
86-
# via taxicab
90+
# via
91+
# hackyeah2024 (pyproject.toml)
92+
# taxicab
8793
packaging==24.1
8894
# via
8995
# altair
@@ -135,6 +141,10 @@ rpds-py==0.20.0
135141
# via
136142
# jsonschema
137143
# referencing
144+
scikit-learn==1.5.2
145+
# via hackyeah2024 (pyproject.toml)
146+
scipy==1.14.1
147+
# via scikit-learn
138148
shapely==2.0.6
139149
# via
140150
# geopandas
@@ -154,6 +164,8 @@ taxicab==0.0.3
154164
# via hackyeah2024 (pyproject.toml)
155165
tenacity==8.5.0
156166
# via streamlit
167+
threadpoolctl==3.5.0
168+
# via scikit-learn
157169
toml==0.10.2
158170
# via streamlit
159171
tornado==6.4.1

0 commit comments

Comments
 (0)