awacke1 commited on
Commit
90df45c
·
1 Parent(s): 017190b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -33
app.py CHANGED
@@ -1,5 +1,23 @@
1
  import streamlit as st
2
- import leafmap.foliumap as leafmap
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- icon_text = f"{species} ({start_month} - {end_month})"
12
- marker = leafmap.Marker(location=[lat, lon], popup=popup_msg)
13
- marker.add_child(leafmap.Popup(icon_text))
14
- return marker
15
 
16
  def create_map(center, zoom, markers):
17
- m = leafmap.Map(center=center, zoom=zoom)
18
  for marker in markers:
19
  marker.add_to(m)
20
  return m
21
 
22
- birds = [
23
- {'species': 'Canada Goose', 'lat': 44.9778, 'lon': -93.2650, 'start_month': 'September', 'end_month': 'April'},
24
- {'species': 'Mallard Duck', 'lat': 44.8835, 'lon': -93.2273, 'start_month': 'August', 'end_month': 'May'},
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
- # Filter the markers by the selected month
47
- selected_markers = [marker for marker in markers if month >= list(calendar.month_abbr).index(marker['start_month'][:3]) and month <= list(calendar.month_abbr).index(marker['end_month'][:3])]
48
 
49
- # Create the map with the filtered markers
50
  m = create_map(center, zoom, selected_markers)
51
 
52
- # Display the map on the Streamlit app
53
- st.write(m)
 
 
 
 
 
 
 
 
 
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)