Suchinthana commited on
Commit
fe42fe7
·
1 Parent(s): 1139537

Removing validation

Browse files
Files changed (1) hide show
  1. app.py +2 -24
app.py CHANGED
@@ -10,7 +10,6 @@ from staticmap import StaticMap, CircleMarker, Polygon
10
  from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
11
  import spaces
12
  import logging
13
- from pydantic import BaseModel, ValidationError, Field
14
  from typing import List, Union
15
 
16
  # Set up logging
@@ -21,20 +20,6 @@ logger = logging.getLogger(__name__)
21
  openai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
22
  geolocator = Nominatim(user_agent="geoapi")
23
 
24
- # Define Pydantic models for GeoJSON validation
25
- class Geometry(BaseModel):
26
- type: str
27
- coordinates: Union[List[float], List[List[List[float]]]]
28
-
29
- class Feature(BaseModel):
30
- type: str = "Feature"
31
- properties: dict
32
- geometry: Geometry
33
-
34
- class FeatureCollection(BaseModel):
35
- type: str = "FeatureCollection"
36
- features: List[Feature]
37
-
38
  # Function to fetch coordinates
39
  @spaces.GPU
40
  def get_geo_coordinates(location_name):
@@ -124,7 +109,6 @@ Generate similar JSON for the following query:
124
  # Generate GeoJSON from OpenAI response
125
  @spaces.GPU
126
  def generate_geojson(response):
127
- #log response
128
  logger.info(f"OpenAI response: {response}")
129
  feature_type = response['output']['feature_representation']['type']
130
  city_names = response['output']['feature_representation']['cities']
@@ -135,7 +119,7 @@ def generate_geojson(response):
135
  # Fetch coordinates for cities
136
  for city in city_names:
137
  try:
138
- coord = get_geo_coordinates(city) # Function to fetch city coordinates
139
  if coord:
140
  coordinates.append(coord)
141
  else:
@@ -165,13 +149,7 @@ def generate_geojson(response):
165
  ],
166
  }
167
 
168
- # Validate the GeoJSON
169
- try:
170
- validated_geojson = FeatureCollection(**geojson_data)
171
- return validated_geojson.dict()
172
- except ValidationError as e:
173
- logger.error(f"Invalid GeoJSON data: {e}")
174
- raise ValueError("Generated GeoJSON is invalid.")
175
 
176
  # Generate static map image
177
  @spaces.GPU
 
10
  from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
11
  import spaces
12
  import logging
 
13
  from typing import List, Union
14
 
15
  # Set up logging
 
20
  openai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
21
  geolocator = Nominatim(user_agent="geoapi")
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Function to fetch coordinates
24
  @spaces.GPU
25
  def get_geo_coordinates(location_name):
 
109
  # Generate GeoJSON from OpenAI response
110
  @spaces.GPU
111
  def generate_geojson(response):
 
112
  logger.info(f"OpenAI response: {response}")
113
  feature_type = response['output']['feature_representation']['type']
114
  city_names = response['output']['feature_representation']['cities']
 
119
  # Fetch coordinates for cities
120
  for city in city_names:
121
  try:
122
+ coord = get_geo_coordinates(city)
123
  if coord:
124
  coordinates.append(coord)
125
  else:
 
149
  ],
150
  }
151
 
152
+ return geojson_data
 
 
 
 
 
 
153
 
154
  # Generate static map image
155
  @spaces.GPU