Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,28 +24,37 @@ def fetch_streetview(address):
|
|
| 24 |
|
| 25 |
gr.Info("Geocoding address...")
|
| 26 |
|
| 27 |
-
# 1. Geocoding API
|
| 28 |
-
geo_url =
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
if geo_data['status'] != 'OK':
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
lat = geo_data['results'][0]['geometry']['location']['lat']
|
| 35 |
lng = geo_data['results'][0]['geometry']['location']['lng']
|
| 36 |
|
| 37 |
gr.Info("Fetching Street View imagery...")
|
| 38 |
|
| 39 |
-
# 2. Street View Static API
|
| 40 |
-
sv_url =
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
if sv_res.status_code == 200:
|
| 44 |
gr.Info("Image successfully loaded!")
|
| 45 |
return Image.open(BytesIO(sv_res.content))
|
| 46 |
else:
|
| 47 |
-
raise gr.Error(f"Street View
|
| 48 |
-
|
| 49 |
# --- 3. Spatial Drawing Engine ---
|
| 50 |
def draw_forensic_targets(image, report_text):
|
| 51 |
annotated_img = image.copy()
|
|
|
|
| 24 |
|
| 25 |
gr.Info("Geocoding address...")
|
| 26 |
|
| 27 |
+
# 1. Geocoding API (Updated to auto-encode the URL)
|
| 28 |
+
geo_url = "https://maps.googleapis.com/maps/api/geocode/json"
|
| 29 |
+
geo_params = {"address": address, "key": gmaps_api_key}
|
| 30 |
+
geo_data = requests.get(geo_url, params=geo_params).json()
|
| 31 |
|
| 32 |
if geo_data['status'] != 'OK':
|
| 33 |
+
# This will now display Google's specific error reason (e.g. REQUEST_DENIED)
|
| 34 |
+
error_detail = geo_data.get('error_message', geo_data['status'])
|
| 35 |
+
raise gr.Error(f"Maps API Error: {error_detail}")
|
| 36 |
|
| 37 |
lat = geo_data['results'][0]['geometry']['location']['lat']
|
| 38 |
lng = geo_data['results'][0]['geometry']['location']['lng']
|
| 39 |
|
| 40 |
gr.Info("Fetching Street View imagery...")
|
| 41 |
|
| 42 |
+
# 2. Street View Static API (Updated to auto-encode)
|
| 43 |
+
sv_url = "https://maps.googleapis.com/maps/api/streetview"
|
| 44 |
+
sv_params = {
|
| 45 |
+
"size": "640x640",
|
| 46 |
+
"location": f"{lat},{lng}",
|
| 47 |
+
"fov": "80",
|
| 48 |
+
"pitch": "0",
|
| 49 |
+
"key": gmaps_api_key
|
| 50 |
+
}
|
| 51 |
+
sv_res = requests.get(sv_url, params=sv_params)
|
| 52 |
|
| 53 |
if sv_res.status_code == 200:
|
| 54 |
gr.Info("Image successfully loaded!")
|
| 55 |
return Image.open(BytesIO(sv_res.content))
|
| 56 |
else:
|
| 57 |
+
raise gr.Error(f"Street View Download Error: {sv_res.status_code}")
|
|
|
|
| 58 |
# --- 3. Spatial Drawing Engine ---
|
| 59 |
def draw_forensic_targets(image, report_text):
|
| 60 |
annotated_img = image.copy()
|