File size: 4,410 Bytes
93b0d61
 
 
 
 
 
 
 
 
799c1d9
210813d
 
 
1d17134
93b0d61
6904e5b
9fa0ffc
e1e9b2f
9fa0ffc
6ac807a
93b0d61
d9ce3a8
030a8f4
b320555
93b0d61
 
 
 
 
 
 
ea7c1d6
 
93b0d61
4265f46
 
93b0d61
 
c082d19
f5ea5bf
6ac807a
93b0d61
07a5035
 
93b0d61
 
 
 
 
 
 
 
 
 
 
 
 
 
5210510
93b0d61
 
 
 
 
 
 
 
f5ea5bf
5210510
93b0d61
 
 
 
 
 
 
0b9e28c
93b0d61
 
799c1d9
93b0d61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ff16a6
93b0d61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
#from diffusers import EulerAncestralDiscreteScheduler, LCMScheduler

#LCMScheduler 產生垃圾
#EulerDiscreteScheduler 尚可
#EulerAncestralDiscreteScheduler 很不錯chatgpt推薦


model_id = "hsuwill000/LCM-anything-v5-openvino"

#model_id = "spamsoms/LCM-anything-v5-openvino2"
#adapter_id = "latent-consistency/lcm-lora-sdv1-5"

#512*512 好 太大會變形
HIGH=1024
WIDTH=512

batch_size = -1

pipe = OVStableDiffusionPipeline.from_pretrained(
        model_id, 
        compile = False, 
        ov_config = {"CACHE_DIR":""},
        torch_dtype=torch.int8, #快
        #torch_dtype=torch.bfloat16, #中
        #variant="fp16", 
        #torch_dtype=torch.IntTensor, #慢,
        safety_checker=None,
        use_safetensors=False,
        )
print(pipe.scheduler.compatibles)
#pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
#pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)

#pipe.load_lora_weights(adapter_id)
#pipe.fuse_lora()


pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
#pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
#pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
#<shigure-ui-style>
#pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
#pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
#pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")


pipe.compile()

prompt=""
negative_prompt="EasyNegative, "

def infer(prompt,negative_prompt):

    image = pipe(
        prompt = prompt, 
        negative_prompt = negative_prompt,
        width = WIDTH, 
        height = HIGH,
        guidance_scale=1.0,
        num_inference_steps=5,
        num_images_per_prompt=1,
    ).images[0] 
    
    return image


examples = [
    "(Digital art, highres, best quality, 8K, masterpiece, anime screencap, perfect eyes:1.4, ultra detailed:1.5),1girl,flat chest,short messy pink hair,blue eyes,tall,thick thighs,light blue hoodie,collar,light blue shirt,black sport shorts,bulge,black thigh highs,femboy,okoto no ko,smiling,blushing,looking at viewer,inside,livingroom,sitting on couch,nighttime,dark,hand_to_mouth,",
    "1girl, silver hair, symbol-shaped pupils, yellow eyes, smiling, light particles, light rays, wallpaper, star guardian, serious face, red inner hair, power aura, grandmaster1, golden and white clothes",
    "masterpiece, best quality, highres booru, 1girl, solo, depth of field, rim lighting, flowers, petals, from above, crystals, butterfly, vegetation, aura, magic, hatsune miku, blush, slight smile, close-up, against wall,",
    "((colofrul:1.7)),((best quality)), ((masterpiece)), ((ultra-detailed)), (illustration), (detailed light), (an extremely delicate and beautiful),incredibly_absurdres,(glowing),(1girl:1.7),solo,a beautiful girl,(((cowboy shot))),standding,((Hosiery)),((beautiful off-shoulder lace-trimmed layered strapless dress+white stocking):1.25),((Belts)),(leg loops),((Hosiery)),((flower headdress)),((long white hair)),(((beautiful eyes))),BREAK,((english text)),(flower:1.35),(garden),(((border:1.75))),",
]

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"""
        # lcmanything-v5-openvino {WIDTH}x{HIGH}
        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,
            fn = infer,
            inputs = [prompt],
            outputs = [result]
        )

    run_button.click(
        fn = infer,
        inputs = [prompt],
        outputs = [result]
    )

demo.queue().launch()