Spaces:
Runtime error
Runtime error
Suchinthana
commited on
Commit
Β·
92e64c7
1
Parent(s):
9b980f8
adding invisible makers
Browse files
app.py
CHANGED
|
@@ -108,30 +108,39 @@ def generate_geojson(response):
|
|
| 108 |
|
| 109 |
# Generate static map image
|
| 110 |
@spaces.GPU
|
| 111 |
-
def generate_static_map(geojson_data):
|
| 112 |
# Create a static map object with specified dimensions
|
| 113 |
m = StaticMap(600, 600)
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
# Process each feature in the GeoJSON
|
| 116 |
for feature in geojson_data["features"]:
|
| 117 |
geom_type = feature["geometry"]["type"]
|
| 118 |
coords = feature["geometry"]["coordinates"]
|
| 119 |
|
| 120 |
if geom_type == "Point":
|
| 121 |
-
# Add a blue marker for Point geometries
|
| 122 |
m.add_marker(CircleMarker((coords[0], coords[1]), 'blue', 10))
|
| 123 |
elif geom_type in ["MultiPoint", "LineString"]:
|
| 124 |
-
# Add a red marker for each point in MultiPoint or LineString geometries
|
| 125 |
for coord in coords:
|
| 126 |
m.add_marker(CircleMarker((coord[0], coord[1]), 'blue', 10))
|
| 127 |
elif geom_type in ["Polygon", "MultiPolygon"]:
|
| 128 |
-
# Add green polygons for Polygon or MultiPolygon geometries
|
| 129 |
for polygon in coords:
|
| 130 |
m.add_polygon(Polygon([(c[0], c[1]) for c in polygon], 'blue', 3))
|
| 131 |
-
|
| 132 |
-
# Render the static map and return the Pillow Image object
|
| 133 |
return m.render(zoom=10)
|
| 134 |
|
|
|
|
| 135 |
# ControlNet pipeline setup
|
| 136 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16)
|
| 137 |
pipeline = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|
|
|
|
| 108 |
|
| 109 |
# Generate static map image
|
| 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"]:
|
| 129 |
geom_type = feature["geometry"]["type"]
|
| 130 |
coords = feature["geometry"]["coordinates"]
|
| 131 |
|
| 132 |
if geom_type == "Point":
|
|
|
|
| 133 |
m.add_marker(CircleMarker((coords[0], coords[1]), 'blue', 10))
|
| 134 |
elif geom_type in ["MultiPoint", "LineString"]:
|
|
|
|
| 135 |
for coord in coords:
|
| 136 |
m.add_marker(CircleMarker((coord[0], coord[1]), 'blue', 10))
|
| 137 |
elif geom_type in ["Polygon", "MultiPolygon"]:
|
|
|
|
| 138 |
for polygon in coords:
|
| 139 |
m.add_polygon(Polygon([(c[0], c[1]) for c in polygon], 'blue', 3))
|
| 140 |
+
|
|
|
|
| 141 |
return m.render(zoom=10)
|
| 142 |
|
| 143 |
+
|
| 144 |
# ControlNet pipeline setup
|
| 145 |
controlnet = ControlNetModel.from_pretrained("lllyasviel/control_v11p_sd15_inpaint", torch_dtype=torch.float16)
|
| 146 |
pipeline = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|