Spaces:
Runtime error
Runtime error
Suchinthana
commited on
Commit
Β·
a1a380b
1
Parent(s):
1ade128
Revert "adding bounds"
Browse filesThis reverts commit 1ade128161eac699c3fc6997e813d39d86174c2a.
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from PIL import Image, ImageDraw
|
|
| 6 |
import gradio as gr
|
| 7 |
from openai import OpenAI
|
| 8 |
from geopy.geocoders import Nominatim
|
| 9 |
-
from staticmap import StaticMap, CircleMarker,
|
| 10 |
from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
|
| 11 |
import spaces
|
| 12 |
|
|
@@ -110,19 +110,19 @@ def generate_geojson(response):
|
|
| 110 |
@spaces.GPU
|
| 111 |
def generate_static_map(geojson_data, bounds=None):
|
| 112 |
# Create a static map object with specified dimensions
|
| 113 |
-
m = StaticMap(
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
|
| 122 |
# Check if there are no features to avoid an empty map
|
| 123 |
if not geojson_data["features"]:
|
| 124 |
# Add a small invisible marker to prevent rendering error
|
| 125 |
-
m.add_marker(
|
| 126 |
|
| 127 |
# Process each feature in the GeoJSON
|
| 128 |
for feature in geojson_data["features"]:
|
|
@@ -209,7 +209,7 @@ def handle_query(query):
|
|
| 209 |
"type": "FeatureCollection",
|
| 210 |
"features": [] # Empty map contains no features
|
| 211 |
}
|
| 212 |
-
empty_map_image = generate_static_map(empty_geojson
|
| 213 |
|
| 214 |
# Create the mask
|
| 215 |
difference = np.abs(np.array(map_image.convert("RGB")) - np.array(empty_map_image.convert("RGB")))
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from openai import OpenAI
|
| 8 |
from geopy.geocoders import Nominatim
|
| 9 |
+
from staticmap import StaticMap, CircleMarker, Polygon
|
| 10 |
from diffusers import ControlNetModel, StableDiffusionControlNetInpaintPipeline
|
| 11 |
import spaces
|
| 12 |
|
|
|
|
| 110 |
@spaces.GPU
|
| 111 |
def generate_static_map(geojson_data, bounds=None):
|
| 112 |
# Create a static map object with specified dimensions
|
| 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
|
| 119 |
+
zoom = 10 # Adjust zoom level as needed
|
| 120 |
+
m.set_center(center_lat, center_lng, zoom)
|
| 121 |
|
| 122 |
# Check if there are no features to avoid an empty map
|
| 123 |
if not geojson_data["features"]:
|
| 124 |
# Add a small invisible marker to prevent rendering error
|
| 125 |
+
m.add_marker(CircleMarker((0.0, 0.0), '#FFFFFF', 0)) # White marker with size 0
|
| 126 |
|
| 127 |
# Process each feature in the GeoJSON
|
| 128 |
for feature in geojson_data["features"]:
|
|
|
|
| 209 |
"type": "FeatureCollection",
|
| 210 |
"features": [] # Empty map contains no features
|
| 211 |
}
|
| 212 |
+
empty_map_image = generate_static_map(empty_geojson) # Empty map with the same bounds
|
| 213 |
|
| 214 |
# Create the mask
|
| 215 |
difference = np.abs(np.array(map_image.convert("RGB")) - np.array(empty_map_image.convert("RGB")))
|