Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,23 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
def create_marker(bird):
|
5 |
species = bird['species']
|
@@ -8,46 +26,33 @@ def create_marker(bird):
|
|
8 |
start_month = bird['start_month']
|
9 |
end_month = bird['end_month']
|
10 |
popup_msg = f"{species}: {start_month} - {end_month}"
|
11 |
-
|
12 |
-
|
13 |
-
marker.add_child(leafmap.Popup(icon_text))
|
14 |
-
return marker
|
15 |
|
16 |
def create_map(center, zoom, markers):
|
17 |
-
m =
|
18 |
for marker in markers:
|
19 |
marker.add_to(m)
|
20 |
return m
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
{'species': 'Wood Duck', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'March', 'end_month': 'November'},
|
26 |
-
{'species': 'Trumpeter Swan', 'lat': 45.0941, 'lon': -94.2392, 'start_month': 'October', 'end_month': 'April'},
|
27 |
-
{'species': 'Tundra Swan', 'lat': 44.9358, 'lon': -93.1553, 'start_month': 'November', 'end_month': 'April'},
|
28 |
-
{'species': 'Canvasback', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
29 |
-
{'species': 'Redhead', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
30 |
-
{'species': 'Greater Scaup', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'September', 'end_month': 'May'},
|
31 |
-
{'species': 'Lesser Scaup', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'May'},
|
32 |
-
{'species': 'Hooded Merganser', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'October', 'end_month': 'April'}
|
33 |
-
]
|
34 |
-
|
35 |
-
# Create list of markers for each bird species
|
36 |
-
markers = [create_marker(bird) for bird in birds]
|
37 |
-
|
38 |
-
# Define the center and zoom of the map
|
39 |
-
center = [44.9778, -93.2650]
|
40 |
-
zoom = 8
|
41 |
-
|
42 |
-
# Create the Streamlit app
|
43 |
-
st.title("Bird Migration Map")
|
44 |
month = st.slider("Select a month", 1, 12, 1)
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
# Create the map with the filtered markers
|
50 |
m = create_map(center, zoom, selected_markers)
|
51 |
|
52 |
-
#
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import folium
|
3 |
+
import json
|
4 |
+
from streamlit_folium import folium_static
|
5 |
+
import calendar
|
6 |
+
|
7 |
+
# Internal dataset saved as jsonl
|
8 |
+
birds_jsonl = '''
|
9 |
+
{"species": "Canada Goose", "lat": 44.9778, "lon": -93.2650, "start_month": "September", "end_month": "April"}
|
10 |
+
{"species": "Mallard Duck", "lat": 44.8835, "lon": -93.2273, "start_month": "August", "end_month": "May"}
|
11 |
+
{"species": "Wood Duck", "lat": 44.9778, "lon": -93.2650, "start_month": "March", "end_month": "November"}
|
12 |
+
{"species": "Trumpeter Swan", "lat": 45.0941, "lon": -94.2392, "start_month": "October", "end_month": "April"}
|
13 |
+
{"species": "Tundra Swan", "lat": 44.9358, "lon": -93.1553, "start_month": "November", "end_month": "April"}
|
14 |
+
{"species": "Canvasback", "lat": 44.8835, "lon": -93.2273, "start_month": "September", "end_month": "May"}
|
15 |
+
{"species": "Redhead", "lat": 44.9778, "lon": -93.2650, "start_month": "September", "end_month": "May"}
|
16 |
+
{"species": "Greater Scaup", "lat": 44.8835, "lon": -93.2273, "start_month": "September", "end_month": "May"}
|
17 |
+
{"species": "Lesser Scaup", "lat": 44.9778, "lon": -93.2650, "start_month": "September", "end_month": "May"}
|
18 |
+
{"species": "Hooded Merganser", "lat": 44.8835, "lon": -93.2273, "start_month": "October", "end_month": "April"}
|
19 |
+
'''
|
20 |
+
birds = [json.loads(line) for line in birds_jsonl.strip().split('\n')]
|
21 |
|
22 |
def create_marker(bird):
|
23 |
species = bird['species']
|
|
|
26 |
start_month = bird['start_month']
|
27 |
end_month = bird['end_month']
|
28 |
popup_msg = f"{species}: {start_month} - {end_month}"
|
29 |
+
icon = folium.Icon(icon="cloud")
|
30 |
+
return folium.Marker(location=[lat, lon], popup=popup_msg, icon=icon)
|
|
|
|
|
31 |
|
32 |
def create_map(center, zoom, markers):
|
33 |
+
m = folium.Map(location=center, zoom_start=zoom)
|
34 |
for marker in markers:
|
35 |
marker.add_to(m)
|
36 |
return m
|
37 |
|
38 |
+
st.title("Bird Migration Map 🦢")
|
39 |
+
st.markdown("### 📅 Use the slider to filter birds based on the months they are visible")
|
40 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
month = st.slider("Select a month", 1, 12, 1)
|
42 |
+
selected_markers = [create_marker(bird) for bird in birds if month >= list(calendar.month_abbr).index(bird['start_month'][:3]) and month <= list(calendar.month_abbr).index(bird['end_month'][:3])]
|
43 |
|
44 |
+
center = [44.9778, -93.2650] # Latitude, Longitude
|
45 |
+
zoom = 8 # Initial zoom level
|
46 |
|
|
|
47 |
m = create_map(center, zoom, selected_markers)
|
48 |
|
49 |
+
# Show the map in Streamlit
|
50 |
+
folium_static(m)
|
51 |
+
|
52 |
+
# Using Streamlit to inject HTML and JavaScript for animation effects
|
53 |
+
st.markdown("<h2 style='text-align: center; color: red;'>This is a HTML header</h2>", unsafe_allow_html=True)
|
54 |
+
|
55 |
+
js_code = """
|
56 |
+
// Your JavaScript code here
|
57 |
+
"""
|
58 |
+
st.markdown(f"<script>{js_code}</script>", unsafe_allow_html=True)
|