grixelle commited on
Commit
1faa8b6
·
verified ·
1 Parent(s): 108875a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -24,13 +24,12 @@ def fetch_streetview(address):
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
 
@@ -39,7 +38,7 @@ def fetch_streetview(address):
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",
@@ -50,15 +49,13 @@ def fetch_streetview(address):
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
- # This will expose the exact JSON text Google sends back with the 403
58
  error_msg = sv_res.text if sv_res.text else "No reason provided."
59
  raise gr.Error(f"Maps 403 Error: {error_msg}")
60
-
61
-
62
  # --- 3. Spatial Drawing Engine ---
63
  def draw_forensic_targets(image, report_text):
64
  annotated_img = image.copy()
 
24
 
25
  gr.Info("Geocoding address...")
26
 
27
+ # 1. Geocoding API
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
  error_detail = geo_data.get('error_message', geo_data['status'])
34
  raise gr.Error(f"Maps API Error: {error_detail}")
35
 
 
38
 
39
  gr.Info("Fetching Street View imagery...")
40
 
41
+ # 2. Street View Static API
42
  sv_url = "https://maps.googleapis.com/maps/api/streetview"
43
  sv_params = {
44
  "size": "640x640",
 
49
  }
50
  sv_res = requests.get(sv_url, params=sv_params)
51
 
52
+ # --- ALIGNED IF/ELSE BLOCK ---
53
+ if sv_res.status_code == 200:
54
  gr.Info("Image successfully loaded!")
55
  return Image.open(BytesIO(sv_res.content))
56
  else:
 
57
  error_msg = sv_res.text if sv_res.text else "No reason provided."
58
  raise gr.Error(f"Maps 403 Error: {error_msg}")
 
 
59
  # --- 3. Spatial Drawing Engine ---
60
  def draw_forensic_targets(image, report_text):
61
  annotated_img = image.copy()