File size: 2,046 Bytes
8d6e69e 927b84a b01821f 927b84a 8cfb060 8d6e69e 6c7e17a 8d6e69e d4c167a 8d6e69e d4c167a 8d6e69e d4c167a 8d6e69e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import torch, os, gc, random
import gradio as gr
from PIL import Image
from diffusers.utils import load_image
from accelerate import Accelerator
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
accelerator = Accelerator(cpu=True)
pipe = StableDiffusionXLPipeline.from_single_file("https://huggingface.co/lllyasviel/fav_models/fav/realisticStockPhoto_v10.safetensors", torch_dtype=torch.bfloat16, use_safetensors=True, variant=None, safety_checker=False)
pipe.load_lora_weights("JoPmt/Txt2Img_Rlstc_Stck_Pht_Xl_Fused", weight_name="SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors", repo_type="space")
pipe.fuse_lora(fuse_unet=True,fuse_text_encoder=False)
##pipe = accelerator.prepare(pipe.unet.load_attn_procs("./", weight_name="SDXL_FILM_PHOTOGRAPHY_STYLE_BetaV0.4.safetensors"))
##pipe.scheduler = accelerator.prepare(EulerDiscreteScheduler.from_config(pipe.scheduler.config))
##pipe.unet.to(memory_format=torch.channels_last)
accelerator.prepare(pipe.to("cpu"))
apol=[]
def plex(prompt,neg_prompt,stips,nut):
apol=[]
if nut == 0:
nm = random.randint(1, 2147483616)
while nm % 32 != 0:
nm = random.randint(1, 2147483616)
else:
nm=nut
lora_scale=0.8
generator = torch.Generator(device="cpu").manual_seed(nm)
image = pipe(prompt=prompt, negative_prompt=neg_prompt, denoising_end=1.0,num_inference_steps=stips, output_type="pil",cross_attention_kwargs={"scale": lora_scale},generator=generator)
for i, imge in enumerate(image["images"]):
apol.append(imge)
return apol
iface = gr.Interface(fn=plex, inputs=[gr.Textbox(label="prompt"),gr.Textbox(label="negative prompt",value="ugly, blurry, poor quality"), gr.Slider(label="num inference steps", minimum=1, step=1, maximum=10, value=8),gr.Slider(label="manual seed (leave 0 for random)", minimum=0,step=32,maximum=2147483616,value=0)], outputs=gr.Gallery(label="out", columns=1),description="Running on cpu, very slow! by JoPmt.")
iface.queue(max_size=1,api_open=False)
iface.launch(max_threads=1) |