Suchinthana commited on
Commit
879a241
·
1 Parent(s): 4b1e4e3

Logging added

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -9,6 +9,11 @@ from geopy.geocoders import Nominatim
9
  from staticmap import StaticMap, CircleMarker, Polygon
10
  from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
11
  import spaces
 
 
 
 
 
12
 
13
  # Initialize APIs
14
  openai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
@@ -23,7 +28,7 @@ def get_geo_coordinates(location_name):
23
  return [location.longitude, location.latitude]
24
  return None
25
  except Exception as e:
26
- print(f"Error fetching coordinates for {location_name}: {e}")
27
  return None
28
 
29
  # Function to process OpenAI chat response
@@ -113,6 +118,8 @@ def generate_static_map(geojson_data, bounds=None):
113
  m = StaticMap(600, 600)
114
 
115
  if bounds:
 
 
116
  # If bounds are provided, set the center of the map
117
  center_lat = (bounds[0][0] + bounds[1][0]) / 2
118
  center_lng = (bounds[0][1] + bounds[1][1]) / 2
@@ -195,6 +202,7 @@ def get_bounds(geojson):
195
  coordinates.extend(part)
196
  lats = [coord[1] for coord in coordinates]
197
  lngs = [coord[0] for coord in coordinates]
 
198
  return [[min(lats), min(lngs)], [max(lats), max(lngs)]]
199
 
200
  # Gradio UI
 
9
  from staticmap import StaticMap, CircleMarker, Polygon
10
  from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
11
  import spaces
12
+ import logging
13
+
14
+ # Set up logging
15
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
16
+ logger = logging.getLogger(__name__)
17
 
18
  # Initialize APIs
19
  openai_client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
 
28
  return [location.longitude, location.latitude]
29
  return None
30
  except Exception as e:
31
+ logger.error(f"Error fetching coordinates for {location_name}: {e}")
32
  return None
33
 
34
  # Function to process OpenAI chat response
 
118
  m = StaticMap(600, 600)
119
 
120
  if bounds:
121
+ #log
122
+ logging.info(f"Bounds received: {bounds}")
123
  # If bounds are provided, set the center of the map
124
  center_lat = (bounds[0][0] + bounds[1][0]) / 2
125
  center_lng = (bounds[0][1] + bounds[1][1]) / 2
 
202
  coordinates.extend(part)
203
  lats = [coord[1] for coord in coordinates]
204
  lngs = [coord[0] for coord in coordinates]
205
+ logging.info(f"Bounds: {min(lats), min(lngs)}, {max(lats), max(lngs)}")
206
  return [[min(lats), min(lngs)], [max(lats), max(lngs)]]
207
 
208
  # Gradio UI