saassa commited on
Commit
92122f1
1 Parent(s): 2396136

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
2
+ from diffusers.utils import load_image
3
+ from PIL import Image
4
+ import torch
5
+ import numpy as np
6
+ import cv2
7
+
8
+ prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
9
+ negative_prompt = 'low quality, bad quality, sketches'
10
+
11
+ image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png")
12
+
13
+ controlnet_conditioning_scale = 0.5 # recommended for good generalization
14
+
15
+ controlnet = ControlNetModel.from_pretrained(
16
+ "diffusers/controlnet-canny-sdxl-1.0",
17
+ torch_dtype=torch.float16
18
+ )
19
+ vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
20
+ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
21
+ "stabilityai/stable-diffusion-xl-base-1.0",
22
+ controlnet=controlnet,
23
+ vae=vae,
24
+ torch_dtype=torch.float16,
25
+ )
26
+ pipe.enable_model_cpu_offload()
27
+
28
+ image = np.array(image)
29
+ image = cv2.Canny(image, 100, 200)
30
+ image = image[:, :, None]
31
+ image = np.concatenate([image, image, image], axis=2)
32
+ image = Image.fromarray(image)
33
+
34
+