Spaces:
Runtime error
Runtime error
Suchinthana commited on
Commit Β·
fe42fe7
1
Parent(s): 1139537
Removing validation
Browse files9 unmodified lines101112131415164 unmodified lines212223242526272829303132333435363738394083 unmodified lines1241251261271281291304 unmodified lines13513613713813914014123 unmodified lines1651661671681691701711721731741751761779 unmodified linesfrom diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipelineimport spacesimport loggingfrom pydantic import BaseModel, ValidationError, Fieldfrom typing import List, Union# Set up logging4 unmodified linesopenai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])geolocator = Nominatim(user_agent="geoapi")# Define Pydantic models for GeoJSON validationclass Geometry(BaseModel):type: strcoordinates: Union[List[float], List[List[List[float]]]]class Feature(BaseModel):type: str = "Feature"properties: dictgeometry: Geometryclass FeatureCollection(BaseModel):type: str = "FeatureCollection"features: List[Feature]# Function to fetch coordinates@spaces.GPUdef get_geo_coordinates(location_name):83 unmodified lines# Generate GeoJSON from OpenAI response@spaces.GPUdef generate_geojson(response):#log responselogger.info(f"OpenAI response: {response}")feature_type = response['output']['feature_representation']['type']city_names = response['output']['feature_representation']['cities']4 unmodified lines# Fetch coordinates for citiesfor city in city_names:try:coord = get_geo_coordinates(city) # Function to fetch city coordinatesif coord:coordinates.append(coord)else:23 unmodified lines],}# Validate the GeoJSONtry:validated_geojson = FeatureCollection(**geojson_data)return validated_geojson.dict()except ValidationError as e:logger.error(f"Invalid GeoJSON data: {e}")raise ValueError("Generated GeoJSON is invalid.")# Generate static map image@spaces.GPU9 unmodified lines1011121314154 unmodified lines20212223242583 unmodified lines1091101111121131144 unmodified lines11912012112212312412523 unmodified lines1491501511521531541559 unmodified linesfrom diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipelineimport spacesimport loggingfrom typing import List, Union# Set up logging4 unmodified linesopenai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])geolocator = Nominatim(user_agent="geoapi")# Function to fetch coordinates@spaces.GPUdef get_geo_coordinates(location_name):83 unmodified lines# Generate GeoJSON from OpenAI response@spaces.GPUdef generate_geojson(response):logger.info(f"OpenAI response: {response}")feature_type = response['output']['feature_representation']['type']city_names = response['output']['feature_representation']['cities']4 unmodified lines# Fetch coordinates for citiesfor city in city_names:try:coord = get_geo_coordinates(city)if coord:coordinates.append(coord)else:23 unmodified lines],}return geojson_data# Generate static map image@spaces.GPU
app.py+2-24