Spaces:
Running
on
Zero
Running
on
Zero
Suchinthana
commited on
Commit
·
8319e98
1
Parent(s):
ee86fef
Function addition, requirements update
Browse files- app.py +32 -0
- requirements.txt +4 -5
app.py
CHANGED
@@ -71,6 +71,28 @@ def generate_geojson(response):
|
|
71 |
}]
|
72 |
}
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Generate map image
|
75 |
def save_map_image(geojson_data):
|
76 |
m = Map()
|
@@ -90,6 +112,16 @@ pipeline = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|
|
90 |
)
|
91 |
pipeline.enable_model_cpu_offload()
|
92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
def generate_satellite_image(init_image_path, mask_image_path, prompt):
|
94 |
init_image = Image.open(init_image_path)
|
95 |
mask_image = Image.open(mask_image_path)
|
|
|
71 |
}]
|
72 |
}
|
73 |
|
74 |
+
|
75 |
+
# Function to compute bounds from GeoJSON
|
76 |
+
def get_bounds(geojson):
|
77 |
+
coordinates = []
|
78 |
+
for feature in geojson["features"]:
|
79 |
+
geom_type = feature["geometry"]["type"]
|
80 |
+
coords = feature["geometry"]["coordinates"]
|
81 |
+
if geom_type == "Point":
|
82 |
+
coordinates.append(coords)
|
83 |
+
elif geom_type in ["MultiPoint", "LineString"]:
|
84 |
+
coordinates.extend(coords)
|
85 |
+
elif geom_type in ["MultiLineString", "Polygon"]:
|
86 |
+
for part in coords:
|
87 |
+
coordinates.extend(part)
|
88 |
+
elif geom_type == "MultiPolygon":
|
89 |
+
for polygon in coords:
|
90 |
+
for part in polygon:
|
91 |
+
coordinates.extend(part)
|
92 |
+
lats = [coord[1] for coord in coordinates]
|
93 |
+
lngs = [coord[0] for coord in coordinates]
|
94 |
+
return [[min(lats), min(lngs)], [max(lats), max(lngs)]]
|
95 |
+
|
96 |
# Generate map image
|
97 |
def save_map_image(geojson_data):
|
98 |
m = Map()
|
|
|
112 |
)
|
113 |
pipeline.enable_model_cpu_offload()
|
114 |
|
115 |
+
def make_inpaint_condition(init_image, mask_image):
|
116 |
+
init_image = np.array(init_image.convert("RGB")).astype(np.float32) / 255.0
|
117 |
+
mask_image = np.array(mask_image.convert("L")).astype(np.float32) / 255.0
|
118 |
+
|
119 |
+
assert init_image.shape[0:1] == mask_image.shape[0:1], "image and image_mask must have the same image size"
|
120 |
+
init_image[mask_image > 0.5] = -1.0 # set as masked pixel
|
121 |
+
init_image = np.expand_dims(init_image, 0).transpose(0, 3, 1, 2)
|
122 |
+
init_image = torch.from_numpy(init_image)
|
123 |
+
return init_image
|
124 |
+
|
125 |
def generate_satellite_image(init_image_path, mask_image_path, prompt):
|
126 |
init_image = Image.open(init_image_path)
|
127 |
mask_image = Image.open(mask_image_path)
|
requirements.txt
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
-
torch
|
2 |
openai # For interacting with OpenAI API
|
3 |
gradio # For creating the Gradio UI
|
4 |
gradio-folium # For embedding Folium maps into Gradio
|
5 |
folium # For creating maps
|
6 |
geopy # For fetching geolocation data # For PyTorch (used by Diffusers and ControlNet)
|
7 |
-
diffusers # For the Stable Diffusion inpainting pipeline
|
8 |
-
opencv-python-headless # For image processing with OpenCV
|
9 |
-
Pillow # For working with images
|
10 |
numpy # For numerical operations
|
11 |
-
|
|
|
|
|
|
|
|
|
|
1 |
openai # For interacting with OpenAI API
|
2 |
gradio # For creating the Gradio UI
|
3 |
gradio-folium # For embedding Folium maps into Gradio
|
4 |
folium # For creating maps
|
5 |
geopy # For fetching geolocation data # For PyTorch (used by Diffusers and ControlNet)
|
|
|
|
|
|
|
6 |
numpy # For numerical operations
|
7 |
+
diffusers
|
8 |
+
transformers
|
9 |
+
torchvision
|
10 |
+
torch
|