Spaces:
Runtime error
Runtime error
Commit
·
b8d3c8f
0
Parent(s):
init
Browse files- app.py +51 -0
- images/0.png +0 -0
- images/1.png +0 -0
- images/2.png +0 -0
- images/3.png +0 -0
- images/4.png +0 -0
- images/5.png +0 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCMultistepScheduler
|
4 |
+
|
5 |
+
controlnet = ControlNetModel.from_pretrained(
|
6 |
+
"williamberman/controlnet-model-3-12-learning-rates",
|
7 |
+
torch_dtype=torch.float16
|
8 |
+
)
|
9 |
+
|
10 |
+
pipe = StableDiffusionControlNetPipeline.from_pretrained(
|
11 |
+
"runwayml/stable-diffusion-v1-5",
|
12 |
+
controlnet=controlnet,
|
13 |
+
safety_checker=None,
|
14 |
+
torch_dtype=torch.float16,
|
15 |
+
)
|
16 |
+
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
17 |
+
pipe.enable_xformers_memory_efficient_attention()
|
18 |
+
pipe.enable_model_cpu_offload()
|
19 |
+
|
20 |
+
def inference(prompt, image, seed=-1):
|
21 |
+
if seed == -1:
|
22 |
+
generator = None
|
23 |
+
else:
|
24 |
+
generator = torch.Generator().manual_seed(seed)
|
25 |
+
|
26 |
+
image = pipe(prompt, image, num_inference_steps=20, generator=generator).images[0]
|
27 |
+
|
28 |
+
return image
|
29 |
+
|
30 |
+
io = gr.Interface(
|
31 |
+
inference,
|
32 |
+
inputs = [
|
33 |
+
gr.Textbox(lines=3, label="Prompt"),
|
34 |
+
gr.Image(label="Controlnet conditioning", type="pil"),
|
35 |
+
gr.Number(-1, label="Seed", precision=0),
|
36 |
+
],
|
37 |
+
outputs=[
|
38 |
+
gr.Image(type="pil"),
|
39 |
+
],
|
40 |
+
examples=[
|
41 |
+
["red circle with blue background", "images/0.png", 0],
|
42 |
+
["cyan circle with brown floral background", "images/1.png", 0],
|
43 |
+
["light coral circle with white background", "images/2.png", 0],
|
44 |
+
["cornflower blue circle with light golden rod yellow background", "images/3.png", 0],
|
45 |
+
["light slate gray circle with blue background", "images/4.png", 0],
|
46 |
+
["light golden rod yellow circle with turquoise background", "images/5.png", 0],
|
47 |
+
],
|
48 |
+
title="fill50k controlnet",
|
49 |
+
cache_examples=True,
|
50 |
+
)
|
51 |
+
io.launch(share=True)
|
images/0.png
ADDED
![]() |
images/1.png
ADDED
![]() |
images/2.png
ADDED
![]() |
images/3.png
ADDED
![]() |
images/4.png
ADDED
![]() |
images/5.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
accelerate
|
5 |
+
git+https://github.com/huggingface/diffusers.git
|
6 |
+
xformers
|