Spaces:
Runtime error
Runtime error
Create backupapp.py
Browse files- backupapp.py +40 -0
backupapp.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import googlemaps
|
2 |
+
import streamlit as st
|
3 |
+
from datetime import datetime
|
4 |
+
|
5 |
+
# Replace your Google Maps API key here
|
6 |
+
#gmaps = googlemaps.Client(key='Your-Google-Maps-API-Key')
|
7 |
+
gmaps = googlemaps.Client(key='AIzaSyDybq2mxujekZVivmr03Y5-GGHXesn4TLI')
|
8 |
+
|
9 |
+
def get_directions(source, destination):
|
10 |
+
now = datetime.now()
|
11 |
+
# Get all modes: driving, walking, bicycling, and transit
|
12 |
+
modes = ['driving', 'walking', 'bicycling', 'transit']
|
13 |
+
directions_info = {}
|
14 |
+
for mode in modes:
|
15 |
+
directions_result = gmaps.directions(source, destination, mode=mode, departure_time=now)
|
16 |
+
if directions_result:
|
17 |
+
directions_info[mode] = directions_result[0]['legs'][0]['steps']
|
18 |
+
else:
|
19 |
+
directions_info[mode] = "No available routes."
|
20 |
+
return directions_info
|
21 |
+
|
22 |
+
# Streamlit App
|
23 |
+
st.title("🗺️ Google Maps Directions")
|
24 |
+
st.sidebar.header('User Input Features')
|
25 |
+
|
26 |
+
# Input for source and destination
|
27 |
+
source_location = st.sidebar.text_input("Source Location", "Mound, MN")
|
28 |
+
destination_location = st.sidebar.text_input("Destination Location", "Minneapolis, MN")
|
29 |
+
|
30 |
+
if st.sidebar.button('Get Directions'):
|
31 |
+
directions_info = get_directions(source_location, destination_location)
|
32 |
+
|
33 |
+
# Displaying the directions
|
34 |
+
for mode, directions in directions_info.items():
|
35 |
+
st.write(f"## Directions by {mode.capitalize()}")
|
36 |
+
if directions == "No available routes.":
|
37 |
+
st.write(directions)
|
38 |
+
else:
|
39 |
+
for i, step in enumerate(directions):
|
40 |
+
st.write(f"{i+1}. {step['html_instructions']}")
|