awacke1 commited on
Commit
c619d68
1 Parent(s): 169d3a3

Update backupapp.py

Browse files
Files changed (1) hide show
  1. backupapp.py +62 -63
backupapp.py CHANGED
@@ -1,77 +1,76 @@
1
  gmaps = googlemaps.Client(key='AIzaSyDybq2mxujekZVivmr03Y5-GGHXesn4TLI')
2
  import streamlit as st
3
- import streamlit.components.v1 as components
 
 
4
  import googlemaps
5
- import os
6
  from datetime import datetime
7
-
8
- def get_directions(source, destination):
9
- now = datetime.now()
10
- directions_info = {}
11
- modes = ['driving', 'walking', 'bicycling', 'transit']
12
- for mode in modes:
13
- directions_result = gmaps.directions(source, destination, mode=mode, departure_time=now)
14
- if directions_result:
15
- directions_info[mode] = directions_result[0]['legs'][0]['steps']
16
- else:
17
- directions_info[mode] = "No available routes."
18
- return directions_info
19
-
20
- def show_map(source, destination):
21
- html_code = f"""
22
- <html>
23
- <head>
24
- <script src="https://maps.googleapis.com/maps/api/js?key={os.getenv('GOOGLE_KEY')}&callback=initMap" async defer></script>
25
- <script>
26
- var map;
27
- function initMap() {{
28
- var directionsService = new google.maps.DirectionsService();
29
- var directionsRenderer = new google.maps.DirectionsRenderer();
30
- map = new google.maps.Map(document.getElementById('map'), {{
31
- zoom: 7,
32
- center: {{lat: 41.85, lng: -87.65}}
33
- }});
34
- directionsRenderer.setMap(map);
35
- var request = {{
36
- origin: '{source}',
37
- destination: '{destination}',
38
- travelMode: 'DRIVING'
39
- }};
40
- directionsService.route(request, function(result, status) {{
41
- if (status == 'OK') {{
42
- directionsRenderer.setDirections(result);
43
- }}
44
- }});
45
- }}
46
- </script>
47
- </head>
48
- <body onload="initMap()">
49
- <div id="map" style="height: 500px;"></div>
50
- </body>
51
- </html>
52
- """
53
- components.html(html_code, height=600, scrolling=False)
54
 
55
  # Initialize Google Maps
56
  gmaps = googlemaps.Client(key=os.getenv('GOOGLE_KEY'))
57
 
58
- # Streamlit app
59
- st.title('🗺️ Google Maps Directions')
60
- st.sidebar.header('📌 User Input Features')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  source_location = st.sidebar.text_input("Source Location", "Mound, MN")
63
  destination_location = st.sidebar.text_input("Destination Location", "Minneapolis, MN")
64
 
65
  if st.sidebar.button('Get Directions'):
66
- directions_info = get_directions(source_location, destination_location)
67
- for mode, directions in directions_info.items():
68
- st.write(f"## Directions by {mode.capitalize()} 🛣️")
69
- if directions == "No available routes.":
70
- st.write(" " + directions)
71
- else:
72
- for i, step in enumerate(directions):
73
- st.write(f"👣 {i + 1}. {step['html_instructions']}")
 
 
74
 
75
- show_map_button = st.button('Show Directions on Map 🗺️')
76
- if show_map_button:
77
- show_map(source_location, destination_location)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  gmaps = googlemaps.Client(key='AIzaSyDybq2mxujekZVivmr03Y5-GGHXesn4TLI')
2
  import streamlit as st
3
+ import folium
4
+ from folium.plugins import MarkerCluster
5
+ from streamlit_folium import folium_static
6
  import googlemaps
 
7
  from datetime import datetime
8
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Initialize Google Maps
11
  gmaps = googlemaps.Client(key=os.getenv('GOOGLE_KEY'))
12
 
13
+ # Function to fetch directions
14
+ def get_directions_and_coords(source, destination):
15
+ now = datetime.now()
16
+ directions_info = gmaps.directions(source, destination, mode='driving', departure_time=now)
17
+ if directions_info:
18
+ steps = directions_info[0]['legs'][0]['steps']
19
+ coords = [(step['start_location']['lat'], step['start_location']['lng']) for step in steps]
20
+ return steps, coords
21
+ else:
22
+ return None, None
23
+
24
+ # Function to render map with directions
25
+ def render_folium_map(coords):
26
+ m = folium.Map(location=[coords[0][0], coords[0][1]], zoom_start=13)
27
+ folium.PolyLine(coords, color="blue", weight=2.5, opacity=1).add_to(m)
28
+ return m
29
+
30
+ # Streamlit UI
31
+ st.title('Google Maps and Minnesota Medical Centers')
32
+ st.sidebar.header('Directions')
33
 
34
  source_location = st.sidebar.text_input("Source Location", "Mound, MN")
35
  destination_location = st.sidebar.text_input("Destination Location", "Minneapolis, MN")
36
 
37
  if st.sidebar.button('Get Directions'):
38
+ steps, coords = get_directions_and_coords(source_location, destination_location)
39
+ if steps and coords:
40
+ st.subheader('Driving Directions:')
41
+ for i, step in enumerate(steps):
42
+ st.write(f"{i+1}. {step['html_instructions']}")
43
+ st.subheader('Route on Map:')
44
+ m1 = render_folium_map(coords)
45
+ folium_static(m1)
46
+ else:
47
+ st.write("No available routes.")
48
 
49
+ # The existing code for Minnesota medical centers
50
+ st.markdown("## 🏥 Minnesota Medical Centers 🌳")
51
+ m2 = folium.Map(location=[45.6945, -93.9002], zoom_start=6)
52
+ marker_cluster = MarkerCluster().add_to(m2)
53
+ # Define Minnesota medical centers data
54
+ minnesota_med_centers = [
55
+ ('Mayo Clinic', 44.0224, -92.4658, 'General medical and surgical', 'Rochester'),
56
+ ('University of Minnesota Medical Center', 44.9721, -93.2595, 'Teaching hospital', 'Minneapolis'),
57
+ ('Abbott Northwestern Hospital', 44.9526, -93.2622, 'Heart specialty', 'Minneapolis'),
58
+ ('Regions Hospital', 44.9558, -93.0942, 'Trauma center', 'St. Paul'),
59
+ ('St. Cloud Hospital', 45.5671, -94.1989, 'Multiple specialties', 'St. Cloud'),
60
+ ('Park Nicollet Methodist Hospital', 44.9304, -93.3640, 'General medical and surgical', 'St. Louis Park'),
61
+ ('Fairview Ridges Hospital', 44.7391, -93.2777, 'Community hospital', 'Burnsville'),
62
+ ('Mercy Hospital', 45.1761, -93.3099, 'Acute care', 'Coon Rapids'),
63
+ ('North Memorial Health Hospital', 45.0131, -93.3246, 'General medical and surgical', 'Robbinsdale'),
64
+ ('Essentia Health-Duluth', 46.7860, -92.1011, 'Community hospital', 'Duluth'),
65
+ ('M Health Fairview Southdale Hospital', 44.8806, -93.3241, 'Community hospital', 'Edina'),
66
+ ('Woodwinds Health Campus', 44.9272, -92.9689, 'Community hospital', 'Woodbury'),
67
+ ('United Hospital', 44.9460, -93.1052, 'Acute care', 'St. Paul'),
68
+ ('Buffalo Hospital', 45.1831, -93.8772, 'Community hospital', 'Buffalo'),
69
+ ('Maple Grove Hospital', 45.1206, -93.4790, 'Community hospital', 'Maple Grove'),
70
+ ('Olmsted Medical Center', 44.0234, -92.4610, 'General medical and surgical', 'Rochester'),
71
+ ('Hennepin Healthcare', 44.9738, -93.2605, 'Teaching hospital', 'Minneapolis'),
72
+ ('St. Francis Regional Medical Center', 44.7658, -93.5143, 'Community hospital', 'Shakopee'),
73
+ ('Lakeview Hospital', 45.0422, -92.8137, 'Community hospital', 'Stillwater'),
74
+ ('St. Luke\'s Hospital', 46.7831, -92.1043, 'Community hospital', 'Duluth')
75
+ ]
76
+ folium_static(m2)