grixelle commited on
Commit
79540f7
·
verified ·
1 Parent(s): f79e0c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
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 = f"https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={gmaps_api_key}"
29
- geo_data = requests.get(geo_url).json()
 
30
 
31
  if geo_data['status'] != 'OK':
32
- raise gr.Error("Could not map this address. Check for typos.")
 
 
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 = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={lat},{lng}&fov=80&pitch=0&key={gmaps_api_key}"
41
- sv_res = requests.get(sv_url)
 
 
 
 
 
 
 
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 API Error: {sv_res.status_code}")
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()