Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
import numpy as
|
3 |
from diffusers import StableDiffusionXLControlNetInpaintPipeline
|
4 |
from diffusers import StableDiffusionXLImg2ImgPipeline, DPMSolverMultistepScheduler, AutoencoderTiny, StableDiffusionXLControlNetPipeline, ControlNetModel
|
5 |
from diffusers.utils import load_image
|
@@ -30,7 +30,22 @@ controlnets = [
|
|
30 |
),
|
31 |
]
|
32 |
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
###pro_encode = pipe_cn.encode_text(prompt)
|
36 |
|
@@ -44,22 +59,17 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int):
|
|
44 |
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_depth_solo_square.png"},
|
45 |
2:{'mask1':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_in_C.png",
|
46 |
'depth_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/depth_C.png",
|
47 |
-
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/
|
48 |
3:{'mask1':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_in_B.png",
|
49 |
'depth_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/depth_B.png",
|
50 |
-
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/
|
51 |
|
52 |
|
53 |
-
|
54 |
-
pipe_CN.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", torch_dtype=torch.float16)
|
55 |
-
pipe_CN.scheduler=DPMSolverSDEScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
56 |
-
###pipe_CN.scheduler=DPMSolverMultistepScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
57 |
-
###pipe_CN.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
58 |
-
pipe_CN.to("cuda")
|
59 |
|
60 |
##############################load loras
|
61 |
|
62 |
-
|
63 |
###pipe_CN.fuse_lora()
|
64 |
|
65 |
output_height = 1024
|
@@ -70,7 +80,7 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int):
|
|
70 |
###ip_images init
|
71 |
###ip_img_1 = load_image(r"C:\Users\AntonioEsparzaGlisma\PycharmProjects\hB8\Cases\a-place-to_210930_HAY_A-PLACE-TO_091-768x1024.png")
|
72 |
###ip_images = [[ip_img_1]]
|
73 |
-
pipe_CN.set_ip_adapter_scale([[0.7]])
|
74 |
n_steps = num_inference_steps
|
75 |
###precomputed depth image
|
76 |
depth_image = load_image(scaff_dic[scaffold]['depth_image'])
|
@@ -89,18 +99,17 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int):
|
|
89 |
num_inference_steps=n_steps,
|
90 |
num_images_per_prompt=1,
|
91 |
generator=generator,
|
92 |
-
denoising_end=0.
|
93 |
-
image=images_CN
|
94 |
output_type="latent",
|
95 |
-
|
96 |
-
|
|
|
97 |
).images[0]
|
98 |
|
99 |
-
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",text_encoder_2=pipe_CN.text_encoder_2,vae=pipe_CN.vae,torch_dtype=torch.float16,use_safetensors=True,variant="fp16")
|
100 |
-
refiner.to("cuda")
|
101 |
|
102 |
-
|
103 |
-
|
104 |
|
105 |
image = refiner(
|
106 |
prompt=prompt1,
|
@@ -108,12 +117,9 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int):
|
|
108 |
denoising_start=0.8,
|
109 |
image=results).images[0]
|
110 |
|
111 |
-
del refiner
|
112 |
-
torch.cuda.empty_cache()
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
pipe_IN.to("cuda")
|
117 |
|
118 |
image = pipe_IN(
|
119 |
prompt=prompt2,
|
@@ -121,16 +127,15 @@ def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int):
|
|
121 |
image=image,
|
122 |
mask_image=mask1,
|
123 |
num_inference_steps=n_steps,
|
124 |
-
strength=0
|
125 |
-
control_guidance_end=[0.
|
126 |
controlnet_conditioning_scale=[0.3, 0.45],
|
127 |
control_image=images_CN,
|
128 |
generator=generator,
|
129 |
).images[0]
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
torch.cuda.empty_cache()
|
134 |
|
135 |
return image
|
136 |
|
@@ -201,17 +206,9 @@ with gr.Blocks(css=css) as demo:
|
|
201 |
value=0,
|
202 |
)
|
203 |
|
204 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
205 |
|
206 |
with gr.Row():
|
207 |
|
208 |
-
fracc = gr.Slider(
|
209 |
-
label="¨seed",
|
210 |
-
minimum=0,
|
211 |
-
maximum=9999,
|
212 |
-
step=1,
|
213 |
-
value=0, #Replace with defaults that work for your model
|
214 |
-
)
|
215 |
|
216 |
num_inference_steps = gr.Slider(
|
217 |
label="Number of inference steps",
|
@@ -228,7 +225,7 @@ with gr.Blocks(css=css) as demo:
|
|
228 |
gr.on(
|
229 |
triggers=[run_button.click, prompt.submit],
|
230 |
fn = ourhood_inference,
|
231 |
-
inputs = [prompt, num_inference_steps, perspective],
|
232 |
outputs = [result]
|
233 |
)
|
234 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
from diffusers import StableDiffusionXLControlNetInpaintPipeline
|
4 |
from diffusers import StableDiffusionXLImg2ImgPipeline, DPMSolverMultistepScheduler, AutoencoderTiny, StableDiffusionXLControlNetPipeline, ControlNetModel
|
5 |
from diffusers.utils import load_image
|
|
|
30 |
),
|
31 |
]
|
32 |
|
33 |
+
pipe_CN = StableDiffusionXLControlNetPipeline.from_pretrained("SG161222/RealVisXL_V5.0", torch_dtype=torch.float16,controlnet=controlnets, use_safetensors=True, variant='fp16')
|
34 |
+
pipe_CN.vae = AutoencoderTiny.from_pretrained("madebyollin/taesdxl", torch_dtype=torch.float16)
|
35 |
+
pipe_CN.scheduler=DPMSolverSDEScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
36 |
+
###pipe_CN.scheduler=DPMSolverMultistepScheduler.from_pretrained("SG161222/RealVisXL_V5.0",subfolder="scheduler",use_karras_sigmas=True)
|
37 |
+
###pipe_CN.load_ip_adapter("h94/IP-Adapter", subfolder="sdxl_models", weight_name="ip-adapter_sdxl.bin")
|
38 |
+
pipe_CN.to("cuda")
|
39 |
+
pipe_CN.load_lora_weights('CreativesCombined/hb8_cases_dreambooth_lora_test_1_14', weight_name='pytorch_lora_weights.safetensors',adapter_name='cases')
|
40 |
+
|
41 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0",text_encoder_2=pipe_CN.text_encoder_2,vae=pipe_CN.vae,torch_dtype=torch.float16,use_safetensors=True,variant="fp16")
|
42 |
+
refiner.to("cuda")
|
43 |
+
|
44 |
+
pipe_IN = StableDiffusionXLControlNetInpaintPipeline.from_pretrained("diffusers/stable-diffusion-xl-1.0-inpainting-0.1",controlnet=controlnets, torch_dtype=torch.float16, variant="fp16").to("cuda")
|
45 |
+
pipe_IN.load_lora_weights('Tonioesparza/ourhood_training_dreambooth_lora_2_0', weight_name='pytorch_lora_weights.safetensors',adapter_name='ourhood')
|
46 |
+
pipe_IN.to("cuda")
|
47 |
+
|
48 |
+
def ourhood_inference(prompt1=str,num_inference_steps=int,scaffold=int,seed=int):
|
49 |
|
50 |
###pro_encode = pipe_cn.encode_text(prompt)
|
51 |
|
|
|
59 |
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_depth_solo_square.png"},
|
60 |
2:{'mask1':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_in_C.png",
|
61 |
'depth_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/depth_C.png",
|
62 |
+
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/canny_C_solo.png"},
|
63 |
3:{'mask1':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/mask_in_B.png",
|
64 |
'depth_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/depth_B.png",
|
65 |
+
'canny_image':"https://huggingface.co/Tonioesparza/ourhood_training_dreambooth_lora_2_0/blob/main/canny_B_solo.png"}}
|
66 |
|
67 |
|
68 |
+
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
##############################load loras
|
71 |
|
72 |
+
|
73 |
###pipe_CN.fuse_lora()
|
74 |
|
75 |
output_height = 1024
|
|
|
80 |
###ip_images init
|
81 |
###ip_img_1 = load_image(r"C:\Users\AntonioEsparzaGlisma\PycharmProjects\hB8\Cases\a-place-to_210930_HAY_A-PLACE-TO_091-768x1024.png")
|
82 |
###ip_images = [[ip_img_1]]
|
83 |
+
###pipe_CN.set_ip_adapter_scale([[0.7]])
|
84 |
n_steps = num_inference_steps
|
85 |
###precomputed depth image
|
86 |
depth_image = load_image(scaff_dic[scaffold]['depth_image'])
|
|
|
99 |
num_inference_steps=n_steps,
|
100 |
num_images_per_prompt=1,
|
101 |
generator=generator,
|
102 |
+
denoising_end=0.8,
|
103 |
+
image=images_CN,
|
104 |
output_type="latent",
|
105 |
+
control_guidance_start=[0.0,0.5],
|
106 |
+
control_guidance_end=[0.5,1.0],
|
107 |
+
controlnet_conditioning_scale=[0.5,1.0],
|
108 |
).images[0]
|
109 |
|
|
|
|
|
110 |
|
111 |
+
|
112 |
+
|
113 |
|
114 |
image = refiner(
|
115 |
prompt=prompt1,
|
|
|
117 |
denoising_start=0.8,
|
118 |
image=results).images[0]
|
119 |
|
|
|
|
|
120 |
|
121 |
+
|
122 |
+
|
|
|
123 |
|
124 |
image = pipe_IN(
|
125 |
prompt=prompt2,
|
|
|
127 |
image=image,
|
128 |
mask_image=mask1,
|
129 |
num_inference_steps=n_steps,
|
130 |
+
strength=1.0,
|
131 |
+
control_guidance_end=[0.9,0.9],
|
132 |
controlnet_conditioning_scale=[0.3, 0.45],
|
133 |
control_image=images_CN,
|
134 |
generator=generator,
|
135 |
).images[0]
|
136 |
|
137 |
+
|
138 |
+
|
|
|
139 |
|
140 |
return image
|
141 |
|
|
|
206 |
value=0,
|
207 |
)
|
208 |
|
|
|
209 |
|
210 |
with gr.Row():
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
num_inference_steps = gr.Slider(
|
214 |
label="Number of inference steps",
|
|
|
225 |
gr.on(
|
226 |
triggers=[run_button.click, prompt.submit],
|
227 |
fn = ourhood_inference,
|
228 |
+
inputs = [prompt, num_inference_steps, perspective,seed],
|
229 |
outputs = [result]
|
230 |
)
|
231 |
|