Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
|
|
| 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",
|
|
@@ -25,14 +20,39 @@ pipe = StableDiffusionXLControlNetPipeline.from_pretrained(
|
|
| 25 |
)
|
| 26 |
pipe.enable_model_cpu_offload()
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
image =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
| 1 |
+
import gradio
|
| 2 |
from diffusers import ControlNetModel, StableDiffusionXLControlNetPipeline, AutoencoderKL
|
| 3 |
from diffusers.utils import load_image
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
| 6 |
import numpy as np
|
| 7 |
import cv2
|
| 8 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
controlnet = ControlNetModel.from_pretrained(
|
| 11 |
"diffusers/controlnet-canny-sdxl-1.0",
|
|
|
|
| 20 |
)
|
| 21 |
pipe.enable_model_cpu_offload()
|
| 22 |
|
| 23 |
+
def infer(image_in):
|
| 24 |
+
prompt = "aerial view, a futuristic research complex in a bright foggy jungle, hard lighting"
|
| 25 |
+
negative_prompt = 'low quality, bad quality, sketches'
|
| 26 |
+
|
| 27 |
+
image = load_image("https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/hf-logo.png")
|
| 28 |
+
|
| 29 |
+
controlnet_conditioning_scale = 0.5 # recommended for good generalization
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
image = np.array(image)
|
| 34 |
+
image = cv2.Canny(image, 100, 200)
|
| 35 |
+
image = image[:, :, None]
|
| 36 |
+
image = np.concatenate([image, image, image], axis=2)
|
| 37 |
+
image = Image.fromarray(image)
|
| 38 |
+
|
| 39 |
+
images = pipe(
|
| 40 |
+
prompt, negative_prompt=negative_prompt, image=image, controlnet_conditioning_scale=controlnet_conditioning_scale,
|
| 41 |
+
).images
|
| 42 |
+
|
| 43 |
+
images[0].save(f"hug_lab.png")
|
| 44 |
+
|
| 45 |
+
with gr.Blocks() as demo:
|
| 46 |
+
with gr.Column():
|
| 47 |
+
image_in = gr.Image(source="upload", type="filepath")
|
| 48 |
+
prompt = gr.Textbox(label="Prompt")
|
| 49 |
+
submit_btn = gr.Button("Submit")
|
| 50 |
+
result = gr.Image(label="Result")
|
| 51 |
|
| 52 |
+
submit_btn.click(
|
| 53 |
+
fn = infer,
|
| 54 |
+
inputs = [image_in, prompt],
|
| 55 |
+
outputs = [result]
|
| 56 |
+
)
|
| 57 |
|
| 58 |
+
demo.queue().launch()
|