Urban Space Visualization Feature

Feature Description

Utilize our Greenery Visualization Tool to preview the transformative impact of converting urban spaces into thriving green areas. Upload images of current urban landscapes to see detailed visualizations of potential green enhancements. This tool aids in planning and envisioning the ecological uplift of city spaces, providing a clear comparison between the present and the proposed green futures.

Original Place

Before Transformation: City with vacant spaces

After Transformation: City with Green Spaces

See more examples!

Code Snippet

!pip install transformers diffusers accelerate==0.20.3

import torch
import numpy as np
from transformers import pipeline
from diffusers import StableDiffusionControlNetImg2ImgPipeline, ControlNetModel, UniPCMultistepScheduler
from diffusers.utils import load_image, make_image_grid

# Load the farm image
farm_image_url = "https://thumbs.dreamstime.com/b/beautiful-indian-farm-landscape-11981336.jpg" # Replace with the your farm iamge image URL
farm_image = load_image(farm_image_url)

# Extract the depth map
depth_estimator = pipeline("depth-estimation")
def get_depth_map(image, depth_estimator):
    image = depth_estimator(image)["depth"]
    image = np.array(image)
    image = image[:, :, None]
    image = np.concatenate([image, image, image], axis=2)
    detected_map = torch.from_numpy(image).float() / 255.0
    depth_map = detected_map.permute(2, 0, 1)
    return depth_map
depth_map = get_depth_map(farm_image, depth_estimator).unsqueeze(0).half().to("cuda")

# Load the ControlNet model and the StableDiffusionControlNetImg2ImgPipeline
controlnet = ControlNetModel.from_pretrained("lllyasviel/sd-controlnet-normal", torch_dtype=torch.float16, use_safetensors=True)
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    controlnet=controlnet,
    torch_dtype=torch.float16,
    use_safetensors=True
).to("cuda")
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
pipe.enable_model_cpu_offload()

prompt = "a green space in the vacant space in city image" # Replace with your agrotourism service name
output = pipe(
    prompt,
    image=farm_image,
    control_image=depth_map,
).images[0]

# Display the original and generated images
make_image_grid([farm_image, output], rows=1, cols=2)

Try Visualizations on Google Colab