Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,8 +21,8 @@ class PDOKLocationSearchInput(BaseModel):
|
|
| 21 |
def validate_postal_code(cls, v):
|
| 22 |
if v is not None and (len(v) != 7 or not v[0:4].isdigit() or v[4] != " " or not v[5:7].isalpha()):
|
| 23 |
raise ValueError("Invalid postal code format. It must be '1234 AA'.")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
def construct_query(self) -> str:
|
| 27 |
"""Constructs the query string based on provided inputs."""
|
| 28 |
if self.postal_code and self.house_number:
|
|
@@ -65,10 +65,10 @@ def pdok_location_info(postal_code: Optional[str] = None, house_number: Optional
|
|
| 65 |
|
| 66 |
debug_info = []
|
| 67 |
debug_info.append(f"Input values:\n"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
base_url = "https://api.pdok.nl/bzk/locatieserver/search/v3_1/free"
|
| 74 |
headers = {"accept": "application/json"}
|
|
@@ -151,6 +151,15 @@ try:
|
|
| 151 |
print(f"District: {location_info.get('wijknaam', 'N/A')}")
|
| 152 |
print(f"Centroid (Lat/Lon): {location_info.get('centroide_ll', 'N/A')}")
|
| 153 |
print(f"Centroid (RD): {location_info.get('centroide_rd', 'N/A')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
else:
|
| 155 |
print("No information found for the given address.")
|
| 156 |
except json.JSONDecodeError:
|
|
@@ -159,12 +168,7 @@ except Exception as e:
|
|
| 159 |
print(f"Error: {str(e)}")
|
| 160 |
print(f"Raw response: {location_info_str}")
|
| 161 |
|
| 162 |
-
|
| 163 |
-
print("Error: Unable to parse location information")
|
| 164 |
-
print(f"Raw response: {location_info_str}")
|
| 165 |
-
except Exception as e:
|
| 166 |
-
print(f"Error processing location information: {str(e)}")
|
| 167 |
-
print(f"Raw response: {location_info_str}")
|
| 168 |
|
| 169 |
@tool
|
| 170 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 21 |
def validate_postal_code(cls, v):
|
| 22 |
if v is not None and (len(v) != 7 or not v[0:4].isdigit() or v[4] != " " or not v[5:7].isalpha()):
|
| 23 |
raise ValueError("Invalid postal code format. It must be '1234 AA'.")
|
| 24 |
+
return v
|
| 25 |
+
|
| 26 |
def construct_query(self) -> str:
|
| 27 |
"""Constructs the query string based on provided inputs."""
|
| 28 |
if self.postal_code and self.house_number:
|
|
|
|
| 65 |
|
| 66 |
debug_info = []
|
| 67 |
debug_info.append(f"Input values:\n"
|
| 68 |
+
f" Postal code: {postal_code}\n"
|
| 69 |
+
f" House number: {house_number}\n"
|
| 70 |
+
f" Street name: {street_name}\n"
|
| 71 |
+
f" City: {city}")
|
| 72 |
|
| 73 |
base_url = "https://api.pdok.nl/bzk/locatieserver/search/v3_1/free"
|
| 74 |
headers = {"accept": "application/json"}
|
|
|
|
| 151 |
print(f"District: {location_info.get('wijknaam', 'N/A')}")
|
| 152 |
print(f"Centroid (Lat/Lon): {location_info.get('centroide_ll', 'N/A')}")
|
| 153 |
print(f"Centroid (RD): {location_info.get('centroide_rd', 'N/A')}")
|
| 154 |
+
|
| 155 |
+
# Add Google Maps link
|
| 156 |
+
centroide_ll = location_info.get('centroide_ll')
|
| 157 |
+
if centroide_ll:
|
| 158 |
+
# Extract latitude and longitude from POINT(lon lat)
|
| 159 |
+
lon, lat = centroide_ll.replace("POINT(", "").replace(")", "").split()
|
| 160 |
+
google_maps_url = f"https://www.google.com/maps/search/?api=1&query={lat},{lon}"
|
| 161 |
+
print(f"Google Maps Link: {google_maps_url}")
|
| 162 |
+
|
| 163 |
else:
|
| 164 |
print("No information found for the given address.")
|
| 165 |
except json.JSONDecodeError:
|
|
|
|
| 168 |
print(f"Error: {str(e)}")
|
| 169 |
print(f"Raw response: {location_info_str}")
|
| 170 |
|
| 171 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
@tool
|
| 174 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|