Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
6 |
# copies of the Software, and to permit persons to whom the Software is
|
7 |
import spaces
|
8 |
-
|
9 |
import os
|
10 |
import random
|
11 |
import uuid
|
@@ -13,12 +12,8 @@ import gradio as gr
|
|
13 |
import numpy as np
|
14 |
from PIL import Image
|
15 |
import torch
|
16 |
-
#import torch._dynamo
|
17 |
-
#import diffusers
|
18 |
from diffusers import AutoencoderKL, StableDiffusionXLPipeline
|
19 |
from diffusers import EulerAncestralDiscreteScheduler
|
20 |
-
#from diffusers import DPMSolverSDEScheduler
|
21 |
-
|
22 |
from typing import Tuple
|
23 |
import paramiko
|
24 |
import gc
|
@@ -95,7 +90,6 @@ DEFAULT_STYLE_NAME = "Style Zero"
|
|
95 |
STYLE_NAMES = list(styles.keys())
|
96 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
97 |
|
98 |
-
#sampling_schedule = AysSchedules["StableDiffusionXLTimesteps"]
|
99 |
upscaler = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
100 |
|
101 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
@@ -108,53 +102,19 @@ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str
|
|
108 |
return p.replace("{prompt}", positive), n + negative
|
109 |
|
110 |
def load_and_prepare_model():
|
111 |
-
#vae = AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16", safety_checker=None)
|
112 |
vaeX = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None,use_safetensors=False,token=HF_TOKEN)
|
113 |
-
#vaeRV = AutoencoderKL.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='vae', safety_checker=None,token=HF_TOKEN)
|
114 |
-
#vae = AutoencoderKL.from_single_file('https://huggingface.co/ford442/sdxl-vae-bf16/mySLR/myslrVAE_v10.safetensors')
|
115 |
-
#vaeX = AutoencoderKL.from_pretrained('ford442/Juggernaut-XI-v11-fp32',subfolder='vae') # ,use_safetensors=True FAILS
|
116 |
-
#unetX = UNet2DConditionModel.from_pretrained('ford442/RealVisXL_V5.0_BF16',subfolder='unet').to(torch.bfloat16) # ,use_safetensors=True FAILS
|
117 |
-
#sched = EulerAncestralDiscreteScheduler.from_pretrained("SG161222/RealVisXL_V5.0", subfolder='scheduler',beta_schedule="scaled_linear", steps_offset=1,timestep_spacing="trailing"))
|
118 |
sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16',token=HF_TOKEN, subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1,use_karras_sigmas=True)
|
119 |
-
#sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16',token=HF_TOKEN, subfolder='scheduler',beta_schedule="scaled_linear")
|
120 |
-
#sched = DPMSolverSDEScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler')
|
121 |
-
#pipeX = StableDiffusionXLPipeline.from_pretrained("SG161222/RealVisXL_V5.0").to(torch.bfloat16)
|
122 |
-
#pipeX = StableDiffusionXLPipeline.from_pretrained("ford442/Juggernaut-XI-v11-fp32",use_safetensors=True)
|
123 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
124 |
-
#'ford442/RealVisXL_V5.0_BF16',
|
125 |
-
#'ford442/Juggernaut-XI-v11-fp32',
|
126 |
-
# 'SG161222/RealVisXL_V5.0',
|
127 |
#'John6666/uber-realistic-porn-merge-ponyxl-urpm-ponyxlhybridv1-sdxl',
|
128 |
#'John6666/uber-realistic-porn-merge-xl-urpmxl-v3-sdxl',
|
129 |
'John6666/uber-realistic-porn-merge-xl-urpmxl-v6final-sdxl',
|
130 |
-
#'John6666/big-lust-v16-sdxl',
|
131 |
-
#'John6666/photo-realistic-pony-v5-sdxl',
|
132 |
#'John6666/pornworks-real-porn-ponyv04-sdxl',
|
133 |
#'John6666/pornmaster-amateur-sdxlv1vae-sdxl',
|
134 |
#torch_dtype=torch.bfloat16,
|
135 |
add_watermarker=False,
|
136 |
token=HF_TOKEN,
|
137 |
-
# custom_pipeline="lpw_stable_diffusion_xl",
|
138 |
#use_safetensors=True,
|
139 |
-
# vae=AutoencoderKL.from_pretrained("BeastHF/MyBack_SDXL_Juggernaut_XL_VAE/MyBack_SDXL_Juggernaut_XL_VAE_V10(version_X).safetensors",repo_type='model',safety_checker=None),
|
140 |
-
# vae=AutoencoderKL.from_pretrained("stabilityai/sdxl-vae",repo_type='model',safety_checker=None, torch_dtype=torch.float32),
|
141 |
-
# vae=AutoencoderKL.from_pretrained("ford442/sdxl-vae-bf16",repo_type='model',safety_checker=None),
|
142 |
-
#vae=vae,
|
143 |
-
#unet=pipeX.unet,
|
144 |
-
#scheduler = sched,
|
145 |
-
# scheduler = EulerAncestralDiscreteScheduler.from_config(pipeX.scheduler.config, beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1)
|
146 |
-
#scheduler=EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset =1)
|
147 |
)
|
148 |
-
#sched = EulerAncestralDiscreteScheduler.from_pretrained('SG161222/RealVisXL_V5.0',token=HF_TOKEN, subfolder='scheduler',beta_schedule="scaled_linear") #, beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
|
149 |
-
#sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16',token=HF_TOKEN, subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1) #,use_karras_sigmas=True)
|
150 |
-
#pipe.vae = AsymmetricAutoencoderKL.from_pretrained('cross-attention/asymmetric-autoencoder-kl-x-2').to(torch.bfloat16) # ,use_safetensors=True FAILS
|
151 |
-
|
152 |
-
#pipe.vae = AutoencoderKL.from_pretrained('ford442/Juggernaut-XI-v11-fp32',subfolder='vae') # ,use_safetensors=True FAILS
|
153 |
-
|
154 |
-
#pipe.vae = AutoencoderKL.from_pretrained('stabilityai/sdxl-vae-bf16',subfolder='vae')
|
155 |
-
#pipe.vae = AutoencoderKL.from_pretrained('stabilityai/sdxl-vae',subfolder='vae',force_upcast=False,scaling_factor= 0.182158767676)
|
156 |
-
#pipe.vae.to(torch.bfloat16)
|
157 |
-
|
158 |
|
159 |
'''
|
160 |
scaling_factor (`float`, *optional*, defaults to 0.18215):
|
@@ -175,41 +135,22 @@ def load_and_prepare_model():
|
|
175 |
#pipe.scheduler = DPMSolverMultistepScheduler.from_pretrained('SG161222/RealVisXL_V5.0', subfolder='scheduler', algorithm_type='sde-dpmsolver++')
|
176 |
|
177 |
#**** NEVER TO BFLOAT BEFORE CUDA****#
|
178 |
-
pipe.vae = vaeX
|
179 |
#**** NEVER TO BFLOAT BEFORE CUDA****#
|
180 |
|
181 |
-
#pipe.
|
182 |
-
|
183 |
-
#pipe.vae.do_resize=False
|
184 |
-
#pipe.vae.do_rescale=False
|
185 |
-
#pipe.vae.do_convert_rgb=True
|
186 |
-
#pipe.vae.vae_scale_factor=8
|
187 |
|
188 |
pipe.scheduler = sched
|
189 |
-
#pipe.vae=vae.to(torch.bfloat16)
|
190 |
-
#pipe.unet=pipeX.unet
|
191 |
-
#pipe.scheduler=EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config, beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1)
|
192 |
-
#pipe.scheduler=EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16', subfolder='scheduler',beta_schedule="scaled_linear")
|
193 |
# pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/Fantasy_World_XL.safetensors", adapter_name="fantasy")
|
194 |
pipe.vae.set_default_attn_processor() # Set attention processor first
|
195 |
|
196 |
-
#pipe.load_lora_weights("Keltezaa/flux_pussy_NSFW", weight_name="flux-pussy.safetensors", adapter_name="vagina", low_cpu_mem_usage=False,token=HF_TOKEN)
|
197 |
-
#pipe.load_lora_weights("xey/sldr_flux_nsfw_v2-studio", weight_name="sldr_flux_nsfw_v2-studio.safetensors", adapter_name="nsfw", low_cpu_mem_usage=False,token=HF_TOKEN)
|
198 |
pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/skin_texture_style_v4.safetensors", adapter_name="skin", low_cpu_mem_usage=False,token=HF_TOKEN)
|
199 |
-
#pipe.unet.load_lora_adapter("ford442/sdxl-vae-bf16", weight_name="LoRA/skin_texture_style_v4.safetensors", prefix="unet")
|
200 |
-
#pipe.text_encoder.load_lora_adapter("ford442/sdxl-vae-bf16", weight_name="LoRA/skin_texture_style_v4.safetensors", prefix="text_encoder")
|
201 |
|
202 |
#pipe.unet = pipe.unet.to(memory_format=torch.contiguous_format)
|
203 |
-
|
204 |
-
#Some typical diffusers pipeline optimizations
|
205 |
-
#pipe.unet.to(memory_format=torch.channels_last) #Unsupported by hidet, but does not seem to make a difference if disabled.
|
206 |
#pipe.enable_vae_tiling()
|
207 |
#pipe.enable_xformers_memory_efficient_attention()
|
208 |
-
|
209 |
|
210 |
-
#pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/epicNewPhoto.safetensors", adapter_name="photo")
|
211 |
-
#pipe.set_adapters(["skin", "vagina", "nsfw"], adapter_weights=[0.75, 0.25, 0.5])
|
212 |
-
#pipe.set_adapters(["skin", "photo", "fantasy"], adapter_weights=[0.75, 0.25, 0.5])
|
213 |
#pipe.set_adapters(["skin"], adapter_weights=[0.5])
|
214 |
#pipe.unet.set_default_attn_processor()
|
215 |
|
@@ -229,8 +170,6 @@ def load_and_prepare_model():
|
|
229 |
#print(f'UNET: {pipe.unet}')
|
230 |
pipe.watermark=None
|
231 |
pipe.safety_checker=None
|
232 |
-
|
233 |
-
#sched = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config, beta_schedule="linear", algorithm_type="dpmsolver++")
|
234 |
return pipe
|
235 |
|
236 |
pipe = load_and_prepare_model()
|
@@ -307,7 +246,6 @@ def generate_30(
|
|
307 |
"guidance_scale": guidance_scale,
|
308 |
"num_inference_steps": num_inference_steps,
|
309 |
"generator": generator,
|
310 |
-
# "timesteps": sampling_schedule,
|
311 |
"output_type": "pil",
|
312 |
}
|
313 |
if use_resolution_binning:
|
@@ -353,7 +291,6 @@ def generate_60(
|
|
353 |
#pipe.set_adapters(["skin"], adapter_weights=[lora_scale])
|
354 |
seed = int(randomize_seed_fn())
|
355 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
356 |
-
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
357 |
options = {
|
358 |
"prompt": [prompt],
|
359 |
"negative_prompt": [negative_prompt],
|
@@ -363,7 +300,6 @@ def generate_60(
|
|
363 |
"guidance_scale": guidance_scale,
|
364 |
"num_inference_steps": num_inference_steps,
|
365 |
"generator": generator,
|
366 |
-
# "timesteps": sampling_schedule,
|
367 |
"output_type": "pil",
|
368 |
}
|
369 |
if use_resolution_binning:
|
@@ -378,8 +314,6 @@ def generate_60(
|
|
378 |
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
379 |
upload_to_ftp(sd_image_path)
|
380 |
image_paths = save_image(rv_image)
|
381 |
-
#torch.cuda.empty_cache()
|
382 |
-
#gc.collect()
|
383 |
torch.set_float32_matmul_precision("medium")
|
384 |
with torch.no_grad():
|
385 |
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
@@ -409,7 +343,6 @@ def generate_90(
|
|
409 |
#pipe.set_adapters(["skin"], adapter_weights=[lora_scale])
|
410 |
seed = int(randomize_seed_fn())
|
411 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
412 |
-
#prompt, negative_prompt = apply_style(style_selection, prompt, negative_prompt)
|
413 |
options = {
|
414 |
"prompt": [prompt],
|
415 |
"negative_prompt": [negative_prompt],
|
@@ -419,7 +352,6 @@ def generate_90(
|
|
419 |
"guidance_scale": guidance_scale,
|
420 |
"num_inference_steps": num_inference_steps,
|
421 |
"generator": generator,
|
422 |
-
# "timesteps": sampling_schedule,
|
423 |
"output_type": "pil",
|
424 |
}
|
425 |
if use_resolution_binning:
|
@@ -434,8 +366,6 @@ def generate_90(
|
|
434 |
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
435 |
upload_to_ftp(sd_image_path)
|
436 |
image_paths = save_image(rv_image)
|
437 |
-
#torch.cuda.empty_cache()
|
438 |
-
#gc.collect()
|
439 |
torch.set_float32_matmul_precision("medium")
|
440 |
with torch.no_grad():
|
441 |
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
@@ -632,9 +562,6 @@ with gr.Blocks(theme=gr.themes.Origin(),css=css) as demo:
|
|
632 |
gr.Markdown("### REALVISXL V5.0")
|
633 |
predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
|
634 |
|
635 |
-
#gr.Markdown("### LIGHTNING V5.0")
|
636 |
-
#predefined_gallery = gr.Gallery(label="LIGHTNING V5.0", columns=3, show_label=False, value=load_predefined_images())
|
637 |
-
|
638 |
gr.Markdown(
|
639 |
"""
|
640 |
<div style="text-align: justify;">
|
|
|
5 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
6 |
# copies of the Software, and to permit persons to whom the Software is
|
7 |
import spaces
|
|
|
8 |
import os
|
9 |
import random
|
10 |
import uuid
|
|
|
12 |
import numpy as np
|
13 |
from PIL import Image
|
14 |
import torch
|
|
|
|
|
15 |
from diffusers import AutoencoderKL, StableDiffusionXLPipeline
|
16 |
from diffusers import EulerAncestralDiscreteScheduler
|
|
|
|
|
17 |
from typing import Tuple
|
18 |
import paramiko
|
19 |
import gc
|
|
|
90 |
STYLE_NAMES = list(styles.keys())
|
91 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
92 |
|
|
|
93 |
upscaler = UpscaleWithModel.from_pretrained("Kim2091/ClearRealityV1").to(torch.device("cuda:0"))
|
94 |
|
95 |
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
|
|
102 |
return p.replace("{prompt}", positive), n + negative
|
103 |
|
104 |
def load_and_prepare_model():
|
|
|
105 |
vaeX = AutoencoderKL.from_pretrained("stabilityai/sdxl-vae", safety_checker=None,use_safetensors=False,token=HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
106 |
sched = EulerAncestralDiscreteScheduler.from_pretrained('ford442/RealVisXL_V5.0_BF16',token=HF_TOKEN, subfolder='scheduler',beta_schedule="scaled_linear", beta_start=0.00085, beta_end=0.012, steps_offset=1,use_karras_sigmas=True)
|
|
|
|
|
|
|
|
|
107 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
|
|
|
|
|
108 |
#'John6666/uber-realistic-porn-merge-ponyxl-urpm-ponyxlhybridv1-sdxl',
|
109 |
#'John6666/uber-realistic-porn-merge-xl-urpmxl-v3-sdxl',
|
110 |
'John6666/uber-realistic-porn-merge-xl-urpmxl-v6final-sdxl',
|
|
|
|
|
111 |
#'John6666/pornworks-real-porn-ponyv04-sdxl',
|
112 |
#'John6666/pornmaster-amateur-sdxlv1vae-sdxl',
|
113 |
#torch_dtype=torch.bfloat16,
|
114 |
add_watermarker=False,
|
115 |
token=HF_TOKEN,
|
|
|
116 |
#use_safetensors=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
'''
|
120 |
scaling_factor (`float`, *optional*, defaults to 0.18215):
|
|
|
135 |
#pipe.scheduler = DPMSolverMultistepScheduler.from_pretrained('SG161222/RealVisXL_V5.0', subfolder='scheduler', algorithm_type='sde-dpmsolver++')
|
136 |
|
137 |
#**** NEVER TO BFLOAT BEFORE CUDA****#
|
138 |
+
pipe.vae = vaeX #.to(torch.bfloat16)
|
139 |
#**** NEVER TO BFLOAT BEFORE CUDA****#
|
140 |
|
141 |
+
#pipe.vae.force_upcast
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
pipe.scheduler = sched
|
|
|
|
|
|
|
|
|
144 |
# pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/Fantasy_World_XL.safetensors", adapter_name="fantasy")
|
145 |
pipe.vae.set_default_attn_processor() # Set attention processor first
|
146 |
|
|
|
|
|
147 |
pipe.load_lora_weights("ford442/sdxl-vae-bf16", weight_name="LoRA/skin_texture_style_v4.safetensors", adapter_name="skin", low_cpu_mem_usage=False,token=HF_TOKEN)
|
|
|
|
|
148 |
|
149 |
#pipe.unet = pipe.unet.to(memory_format=torch.contiguous_format)
|
150 |
+
#pipe.unet.to(memory_format=torch.channels_last)
|
|
|
|
|
151 |
#pipe.enable_vae_tiling()
|
152 |
#pipe.enable_xformers_memory_efficient_attention()
|
|
|
153 |
|
|
|
|
|
|
|
154 |
#pipe.set_adapters(["skin"], adapter_weights=[0.5])
|
155 |
#pipe.unet.set_default_attn_processor()
|
156 |
|
|
|
170 |
#print(f'UNET: {pipe.unet}')
|
171 |
pipe.watermark=None
|
172 |
pipe.safety_checker=None
|
|
|
|
|
173 |
return pipe
|
174 |
|
175 |
pipe = load_and_prepare_model()
|
|
|
246 |
"guidance_scale": guidance_scale,
|
247 |
"num_inference_steps": num_inference_steps,
|
248 |
"generator": generator,
|
|
|
249 |
"output_type": "pil",
|
250 |
}
|
251 |
if use_resolution_binning:
|
|
|
291 |
#pipe.set_adapters(["skin"], adapter_weights=[lora_scale])
|
292 |
seed = int(randomize_seed_fn())
|
293 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
|
|
294 |
options = {
|
295 |
"prompt": [prompt],
|
296 |
"negative_prompt": [negative_prompt],
|
|
|
300 |
"guidance_scale": guidance_scale,
|
301 |
"num_inference_steps": num_inference_steps,
|
302 |
"generator": generator,
|
|
|
303 |
"output_type": "pil",
|
304 |
}
|
305 |
if use_resolution_binning:
|
|
|
314 |
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
315 |
upload_to_ftp(sd_image_path)
|
316 |
image_paths = save_image(rv_image)
|
|
|
|
|
317 |
torch.set_float32_matmul_precision("medium")
|
318 |
with torch.no_grad():
|
319 |
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
|
|
343 |
#pipe.set_adapters(["skin"], adapter_weights=[lora_scale])
|
344 |
seed = int(randomize_seed_fn())
|
345 |
generator = torch.Generator(device='cuda').manual_seed(seed)
|
|
|
346 |
options = {
|
347 |
"prompt": [prompt],
|
348 |
"negative_prompt": [negative_prompt],
|
|
|
352 |
"guidance_scale": guidance_scale,
|
353 |
"num_inference_steps": num_inference_steps,
|
354 |
"generator": generator,
|
|
|
355 |
"output_type": "pil",
|
356 |
}
|
357 |
if use_resolution_binning:
|
|
|
366 |
rv_image.save(sd_image_path,optimize=False,compress_level=0)
|
367 |
upload_to_ftp(sd_image_path)
|
368 |
image_paths = save_image(rv_image)
|
|
|
|
|
369 |
torch.set_float32_matmul_precision("medium")
|
370 |
with torch.no_grad():
|
371 |
upscale = upscaler(rv_image, tiling=True, tile_width=256, tile_height=256)
|
|
|
562 |
gr.Markdown("### REALVISXL V5.0")
|
563 |
predefined_gallery = gr.Gallery(label="REALVISXL V5.0", columns=3, show_label=False, value=load_predefined_images1())
|
564 |
|
|
|
|
|
|
|
565 |
gr.Markdown(
|
566 |
"""
|
567 |
<div style="text-align: justify;">
|