Spaces:
Runtime error
Runtime error
add prints
Browse files- app.py +5 -1
- climategan_wrapper.py +6 -3
app.py
CHANGED
@@ -20,6 +20,7 @@ from gradio.components import (
|
|
20 |
Textbox,
|
21 |
)
|
22 |
from skimage import io
|
|
|
23 |
|
24 |
from climategan_wrapper import ClimateGAN
|
25 |
|
@@ -122,6 +123,7 @@ def toggle(radio):
|
|
122 |
|
123 |
def predict(cg: ClimateGAN, api_key):
|
124 |
def _predict(*args):
|
|
|
125 |
image = place = painter = radio = None
|
126 |
if api_key:
|
127 |
radio, image, place, painter = args
|
@@ -134,7 +136,9 @@ def predict(cg: ClimateGAN, api_key):
|
|
134 |
address = geocode_result[0]["formatted_address"]
|
135 |
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={parse.quote(address)}&source=outdoor&key={api_key}"
|
136 |
img_np = io.imread(static_map_url)
|
|
|
137 |
else:
|
|
|
138 |
img_np = image
|
139 |
|
140 |
painters = {
|
@@ -142,7 +146,7 @@ def predict(cg: ClimateGAN, api_key):
|
|
142 |
"Stable Diffusion Painter": "stable_diffusion",
|
143 |
"Both": "both",
|
144 |
}
|
145 |
-
|
146 |
output_dict = cg.infer_single(img_np, painters[painter], as_pil_image=True)
|
147 |
|
148 |
input_image = output_dict["input"]
|
|
|
20 |
Textbox,
|
21 |
)
|
22 |
from skimage import io
|
23 |
+
from datetime import datetime
|
24 |
|
25 |
from climategan_wrapper import ClimateGAN
|
26 |
|
|
|
123 |
|
124 |
def predict(cg: ClimateGAN, api_key):
|
125 |
def _predict(*args):
|
126 |
+
print(f"Starting inference ({str(datetime.now())})")
|
127 |
image = place = painter = radio = None
|
128 |
if api_key:
|
129 |
radio, image, place, painter = args
|
|
|
136 |
address = geocode_result[0]["formatted_address"]
|
137 |
static_map_url = f"https://maps.googleapis.com/maps/api/streetview?size=640x640&location={parse.quote(address)}&source=outdoor&key={api_key}"
|
138 |
img_np = io.imread(static_map_url)
|
139 |
+
print("Using GSV image")
|
140 |
else:
|
141 |
+
print("Using user image")
|
142 |
img_np = image
|
143 |
|
144 |
painters = {
|
|
|
146 |
"Stable Diffusion Painter": "stable_diffusion",
|
147 |
"Both": "both",
|
148 |
}
|
149 |
+
print("Using painter", painters[painter])
|
150 |
output_dict = cg.infer_single(img_np, painters[painter], as_pil_image=True)
|
151 |
|
152 |
input_image = output_dict["input"]
|
climategan_wrapper.py
CHANGED
@@ -264,7 +264,7 @@ class ClimateGAN:
|
|
264 |
pil_image = None
|
265 |
if as_pil_image:
|
266 |
pil_image = Image.fromarray(image_array)
|
267 |
-
|
268 |
image = self._preprocess_image(image_array)
|
269 |
output_dict = self.infer_preprocessed_batch(
|
270 |
images=image[None, ...],
|
@@ -273,6 +273,7 @@ class ClimateGAN:
|
|
273 |
concats=concats,
|
274 |
pil_image=pil_image,
|
275 |
)
|
|
|
276 |
return {k: v[0] for k, v in output_dict.items()}
|
277 |
|
278 |
def infer_preprocessed_batch(
|
@@ -340,6 +341,7 @@ class ClimateGAN:
|
|
340 |
pil_image = Image.fromarray(((images[0] + 1) / 2 * 255).astype(np.uint8))
|
341 |
|
342 |
# Retrieve numpy events as a dict {event: array[BxHxWxC]}
|
|
|
343 |
outputs = self.trainer.infer_all(
|
344 |
images,
|
345 |
numpy=True,
|
@@ -376,8 +378,7 @@ class ClimateGAN:
|
|
376 |
if pil_image is None
|
377 |
else Image.fromarray(mask[0])
|
378 |
)
|
379 |
-
print("
|
380 |
-
print("input_images size: ", input_images.size)
|
381 |
floods = self.sdip_pipeline(
|
382 |
prompt=[prompt] * images.shape[0],
|
383 |
image=input_images,
|
@@ -386,6 +387,7 @@ class ClimateGAN:
|
|
386 |
width=640,
|
387 |
num_inference_steps=50,
|
388 |
)
|
|
|
389 |
|
390 |
bin_mask = mask[..., None] > 0
|
391 |
flood = np.stack([np.array(i) for i in floods.images])
|
@@ -394,6 +396,7 @@ class ClimateGAN:
|
|
394 |
outputs["stable_copy_flood"] = copy_flood
|
395 |
|
396 |
if concats:
|
|
|
397 |
outputs["concat"] = concat_events(outputs, concats, axis=2)
|
398 |
|
399 |
return {k: v.squeeze(1) if v.shape[1] == 1 else v for k, v in outputs.items()}
|
|
|
264 |
pil_image = None
|
265 |
if as_pil_image:
|
266 |
pil_image = Image.fromarray(image_array)
|
267 |
+
print("Preprocessing image")
|
268 |
image = self._preprocess_image(image_array)
|
269 |
output_dict = self.infer_preprocessed_batch(
|
270 |
images=image[None, ...],
|
|
|
273 |
concats=concats,
|
274 |
pil_image=pil_image,
|
275 |
)
|
276 |
+
print("Inference done")
|
277 |
return {k: v[0] for k, v in output_dict.items()}
|
278 |
|
279 |
def infer_preprocessed_batch(
|
|
|
341 |
pil_image = Image.fromarray(((images[0] + 1) / 2 * 255).astype(np.uint8))
|
342 |
|
343 |
# Retrieve numpy events as a dict {event: array[BxHxWxC]}
|
344 |
+
print("Inferring ClimateGAN events")
|
345 |
outputs = self.trainer.infer_all(
|
346 |
images,
|
347 |
numpy=True,
|
|
|
378 |
if pil_image is None
|
379 |
else Image.fromarray(mask[0])
|
380 |
)
|
381 |
+
print("Inferring stable diffusion in-painting for 50 steps")
|
|
|
382 |
floods = self.sdip_pipeline(
|
383 |
prompt=[prompt] * images.shape[0],
|
384 |
image=input_images,
|
|
|
387 |
width=640,
|
388 |
num_inference_steps=50,
|
389 |
)
|
390 |
+
print("Stable diffusion in-painting done")
|
391 |
|
392 |
bin_mask = mask[..., None] > 0
|
393 |
flood = np.stack([np.array(i) for i in floods.images])
|
|
|
396 |
outputs["stable_copy_flood"] = copy_flood
|
397 |
|
398 |
if concats:
|
399 |
+
print("Concatenating flood images")
|
400 |
outputs["concat"] = concat_events(outputs, concats, axis=2)
|
401 |
|
402 |
return {k: v.squeeze(1) if v.shape[1] == 1 else v for k, v in outputs.items()}
|