Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -148,30 +148,49 @@ import streamlit as st
|
|
| 148 |
import pandas as pd
|
| 149 |
|
| 150 |
def get_route(start_coord, end_coord):
|
| 151 |
-
api_key = os.getenv('OPENSTREET_API')
|
|
|
|
|
|
|
| 152 |
if not api_key:
|
| 153 |
st.error("API key not found. Please set the OPENSTREET_API environment variable.")
|
| 154 |
-
return
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
| 156 |
headers = {
|
| 157 |
'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
|
| 158 |
}
|
| 159 |
url = f"https://api.openrouteservice.org/v2/directions/driving-car?api_key={api_key}&start={start_coord[0]},{start_coord[1]}&end={end_coord[0]},{end_coord[1]}"
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
response = requests.get(url, headers=headers)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
| 163 |
if response.status_code == 200:
|
| 164 |
-
print("API call successful. Response data:", response.json()) # For debugging: remove or comment out in production
|
| 165 |
data = response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
if 'features' in data and len(data['features']) > 0:
|
| 167 |
route = data['features'][0]['geometry']['coordinates']
|
|
|
|
|
|
|
|
|
|
| 168 |
return route
|
| 169 |
else:
|
| 170 |
st.error("Route data is missing from the response.")
|
| 171 |
return None
|
| 172 |
else:
|
| 173 |
-
|
| 174 |
-
st.error(f"Failed to get route data. Status code: {response.status_code}")
|
| 175 |
return None
|
| 176 |
|
| 177 |
|
|
|
|
| 148 |
import pandas as pd
|
| 149 |
|
| 150 |
def get_route(start_coord, end_coord):
|
| 151 |
+
api_key = os.getenv('OPENSTREET_API')
|
| 152 |
+
|
| 153 |
+
# Debugging: Confirm API key retrieval
|
| 154 |
if not api_key:
|
| 155 |
st.error("API key not found. Please set the OPENSTREET_API environment variable.")
|
| 156 |
+
return None
|
| 157 |
+
else:
|
| 158 |
+
st.success("API key successfully retrieved.")
|
| 159 |
+
|
| 160 |
+
# Prepare the request details
|
| 161 |
headers = {
|
| 162 |
'Accept': 'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
|
| 163 |
}
|
| 164 |
url = f"https://api.openrouteservice.org/v2/directions/driving-car?api_key={api_key}&start={start_coord[0]},{start_coord[1]}&end={end_coord[0]},{end_coord[1]}"
|
| 165 |
|
| 166 |
+
# Debugging: Display the request URL for verification
|
| 167 |
+
st.write("Requesting URL:", url)
|
| 168 |
+
|
| 169 |
+
# Make the API request
|
| 170 |
response = requests.get(url, headers=headers)
|
| 171 |
|
| 172 |
+
# Debugging: Check and display the response status
|
| 173 |
+
st.write(f"Response Status Code: {response.status_code}")
|
| 174 |
+
|
| 175 |
if response.status_code == 200:
|
|
|
|
| 176 |
data = response.json()
|
| 177 |
+
|
| 178 |
+
# Debugging: Display a portion of the response for inspection
|
| 179 |
+
st.write("API call successful. Here's a preview of the response data:")
|
| 180 |
+
st.json(data) # Displaying the full response might be overwhelming; consider showing just a part of it
|
| 181 |
+
|
| 182 |
if 'features' in data and len(data['features']) > 0:
|
| 183 |
route = data['features'][0]['geometry']['coordinates']
|
| 184 |
+
|
| 185 |
+
# Debugging: Confirm route data extraction
|
| 186 |
+
st.success("Route data successfully extracted.")
|
| 187 |
return route
|
| 188 |
else:
|
| 189 |
st.error("Route data is missing from the response.")
|
| 190 |
return None
|
| 191 |
else:
|
| 192 |
+
response_text = response.text[:500] # Limit the amount of text displayed for clarity
|
| 193 |
+
st.error(f"Failed to get route data. Status code: {response.status_code}, Response: {response_text}")
|
| 194 |
return None
|
| 195 |
|
| 196 |
|