|
import gradio as gr |
|
import numpy as np |
|
import random |
|
from diffusers import DiffusionPipeline |
|
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel, OVStableDiffusionPipeline |
|
import torch |
|
from huggingface_hub import snapshot_download |
|
import openvino.runtime as ov |
|
from typing import Optional, Dict |
|
|
|
model_id = "Disty0/LCM_SoteMix" |
|
batch_size = -1 |
|
class CustomOVModelVaeDecoder(OVModelVaeDecoder): |
|
def __init__( |
|
self, model: ov.Model, parent_model: OVBaseModel, ov_config: Optional[Dict[str, str]] = None, model_dir: str = None, |
|
): |
|
super(OVModelVaeDecoder, self).__init__(model, parent_model, ov_config, "vae_decoder", model_dir) |
|
|
|
|
|
pipe = OVStableDiffusionPipeline.from_pretrained(model_id, compile = False, ov_config = {"CACHE_DIR":""}) |
|
|
|
taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino") |
|
pipe.vae_decoder = CustomOVModelVaeDecoder(model = OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"), parent_model = pipe, model_dir = taesd_dir) |
|
|
|
pipe.reshape( batch_size=-1, height=512, width=512, num_images_per_prompt=1) |
|
pipe.compile() |
|
|
|
|
|
def infer(prompt,negative_prompt): |
|
|
|
image = pipe( |
|
prompt = prompt+"score_8_up,score_7_up,score_6_up,score_9,score_8_up,score_7,masterpiece,best quality,source_anime,bangs,", |
|
negative_prompt = "score_6,score_5,score_4,source_furry,pathway,walkway,face mask,heterochromia,\ |
|
tattoos,muscular,deformed iris,deformed pupils,long body,long neck,text,error,print,signature,\ |
|
logo,watermark,deformed,distorted,disfigured,bad anatomy,wrong anatomy,ugly,disgusting,\ |
|
cropped,crooked teeth,multiple views,bad proportions,gross proportions,cloned face,\ |
|
worst quality,low quality,normal quality,bad quality,lowres,poorly drawn,semi-realistic,\ |
|
3d,render,cg,cgi,imperfect,partial,unfinished,incomplete,monochrome,grayscale,sepia,fat,\ |
|
wrinkle,fat leg,fat ass,blurry,hazy,sagging breasts,longbody,lowres,\ |
|
bad anatomy,bad hands,missing fingers,extra digit,fewer digits,worst quality,\ |
|
low quality,normal quality,watermark,artist name,signature,(bad anatomy)), ((bad art)),\ |
|
(((bad proportions))), (b&w), (black/white), (black and white), blurry, body out of frame,\ |
|
canvas frame, cloned face, ((close up)), cross-eye, ((deformed)), ((disfigured)), (((duplicate))), \ |
|
(((extra arms))), extra fingers, (((extra legs))), ((extra limbs)), (fused fingers), gross proportions, \ |
|
((morbid)), (malformed limbs), ((missing arms)), ((missing legs)), mutated, mutated hands, \ |
|
(((mutation))), ((mutilated)), (out of frame), ((poorly drawn face)), poorly drawn feet, \ |
|
((poorly drawn hands)), tiling, (too many fingers), ((ugly)), wierd colors, (((long neck))), \ |
|
ugly, words, wrinkles, writing", |
|
width = 512, |
|
height = 512, |
|
guidance_scale=1.0, |
|
num_inference_steps=8, |
|
num_images_per_prompt=1, |
|
).images[0] |
|
|
|
return image |
|
|
|
|
|
examples = [ |
|
"A cute kitten, Japanese cartoon style.", |
|
"A sweet family, dad stands next to mom, mom holds baby girl.", |
|
"A delicious ceviche cheesecake slice", |
|
] |
|
|
|
css=""" |
|
#col-container { |
|
margin: 0 auto; |
|
max-width: 520px; |
|
} |
|
""" |
|
|
|
|
|
power_device = "CPU" |
|
|
|
with gr.Blocks(css=css) as demo: |
|
|
|
with gr.Column(elem_id="col-container"): |
|
gr.Markdown(f""" |
|
# Disty0/LCM_SoteMix 512x512 |
|
Currently running on {power_device}. |
|
""") |
|
|
|
with gr.Row(): |
|
prompt = gr.Text( |
|
label="Prompt", |
|
show_label=False, |
|
max_lines=1, |
|
placeholder="Enter your prompt", |
|
container=False, |
|
) |
|
run_button = gr.Button("Run", scale=0) |
|
|
|
result = gr.Image(label="Result", show_label=False) |
|
|
|
gr.Examples( |
|
examples = examples, |
|
inputs = [prompt] |
|
) |
|
|
|
run_button.click( |
|
fn = infer, |
|
inputs = [prompt], |
|
outputs = [result] |
|
) |
|
|
|
demo.queue().launch() |