Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
9fb5d19
1
Parent(s):
c07fee1
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,9 @@ import pandas as pd
|
|
3 |
import numpy as np
|
4 |
from sklearn.neighbors import KNeighborsRegressor
|
5 |
from geopy.distance import geodesic
|
|
|
|
|
|
|
6 |
|
7 |
# Function to calculate distance in meters between two coordinates
|
8 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
@@ -72,21 +75,30 @@ zoom_level = round(15 - np.log10(max_distance))
|
|
72 |
|
73 |
# Create a sidebar for controls
|
74 |
with st.sidebar:
|
75 |
-
# Display a title
|
76 |
st.title('avalia.se')
|
77 |
|
78 |
-
# Dropdown to select specific coordinates
|
79 |
selected_coords = st.selectbox('Selecione Coordenadas', ['Random', 'Custom'])
|
|
|
80 |
if selected_coords == 'Custom':
|
81 |
-
|
82 |
-
custom_lon = st.number_input('Enter Longitude', value=filtered_data['longitude'].mean())
|
83 |
radius_visible = True # Show radius slider for custom coordinates
|
84 |
# No need to initialize max_distance_all here
|
85 |
else:
|
86 |
-
|
87 |
radius_visible = False # Hide radius slider for random coordinates
|
88 |
max_distance_all = 0 # Initialize max_distance_all here
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
# Slider for setting the zoom level
|
91 |
if selected_coords == 'Custom':
|
92 |
zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level)
|
|
|
3 |
import numpy as np
|
4 |
from sklearn.neighbors import KNeighborsRegressor
|
5 |
from geopy.distance import geodesic
|
6 |
+
import googlemaps
|
7 |
+
from geopy.exc import GeocoderTimedOut
|
8 |
+
|
9 |
|
10 |
# Function to calculate distance in meters between two coordinates
|
11 |
def calculate_distance(lat1, lon1, lat2, lon2):
|
|
|
75 |
|
76 |
# Create a sidebar for controls
|
77 |
with st.sidebar:
|
|
|
78 |
st.title('avalia.se')
|
79 |
|
|
|
80 |
selected_coords = st.selectbox('Selecione Coordenadas', ['Random', 'Custom'])
|
81 |
+
|
82 |
if selected_coords == 'Custom':
|
83 |
+
custom_address = st.text_input('Enter Address', 'Your Address Here')
|
|
|
84 |
radius_visible = True # Show radius slider for custom coordinates
|
85 |
# No need to initialize max_distance_all here
|
86 |
else:
|
87 |
+
custom_address = "Porto Alegre, Brazil" # Default address
|
88 |
radius_visible = False # Hide radius slider for random coordinates
|
89 |
max_distance_all = 0 # Initialize max_distance_all here
|
90 |
|
91 |
+
max_distance_all = 0 # Initialize max_distance_all here
|
92 |
+
|
93 |
+
# Geocode the custom address using the Google Maps API
|
94 |
+
gmaps = googlemaps.Client(key='AIzaSyDoJ6C7NE2CHqFcaHTnhreOfgJeTk4uSH0') # Replace with your API key
|
95 |
+
|
96 |
+
try:
|
97 |
+
location = gmaps.geocode(custom_address)[0]['geometry']['location']
|
98 |
+
custom_lat, custom_lon = location['lat'], location['lng']
|
99 |
+
except (IndexError, GeocoderTimedOut):
|
100 |
+
st.error("Error: Unable to geocode the provided address. Please check and try again.")
|
101 |
+
|
102 |
# Slider for setting the zoom level
|
103 |
if selected_coords == 'Custom':
|
104 |
zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level)
|