Update app.py
Browse files
app.py
CHANGED
@@ -8,77 +8,61 @@ from huggingface_hub import snapshot_download
|
|
8 |
import openvino.runtime as ov
|
9 |
from typing import Optional, Dict
|
10 |
|
11 |
-
|
12 |
-
|
13 |
model_id = "Disty0/LCM_SoteMix"
|
14 |
-
#model_id = "Disty0/sotediffusion-v2" #不可
|
15 |
|
16 |
-
#1024*512 記憶體不足
|
17 |
-
HIGH=768
|
18 |
-
WIDTH=512
|
19 |
|
20 |
batch_size = -1
|
21 |
-
"""
|
22 |
-
class CustomOVModelVaeDecoder(OVModelVaeDecoder):
|
23 |
-
def __init__(
|
24 |
-
self, model: ov.Model, parent_model: OVBaseModel, ov_config: Optional[Dict[str, str]] = None, model_dir: str = None,
|
25 |
-
):
|
26 |
-
super(OVModelVaeDecoder, self).__init__(model, parent_model, ov_config, "vae_decoder", model_dir)
|
27 |
-
"""
|
28 |
|
29 |
pipe = OVStableDiffusionPipeline.from_pretrained(
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
|
41 |
-
|
42 |
-
|
43 |
-
parent_model = pipe,
|
44 |
-
model_dir = taesd_dir
|
45 |
-
)
|
46 |
-
"""
|
47 |
pipe.vae_decoder = OVModelVaeDecoder(
|
48 |
-
model=OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
|
49 |
-
parent_model=pipe,
|
50 |
-
ov_config=None, #
|
51 |
-
model_type="vae_decoder", #
|
52 |
model_dir=taesd_dir
|
53 |
)
|
54 |
|
55 |
-
|
56 |
-
pipe.
|
57 |
-
#pipe.load_textual_inversion("./
|
58 |
-
#
|
59 |
-
|
60 |
-
#pipe.load_textual_inversion("sd-concepts-library/
|
61 |
-
#pipe.load_textual_inversion("sd-concepts-library/
|
62 |
-
#pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
|
63 |
-
|
64 |
|
65 |
pipe.compile()
|
66 |
|
67 |
-
prompt=""
|
68 |
-
negative_prompt="(worst quality, low quality, lowres), zombie, interlocked fingers,"
|
69 |
-
|
70 |
-
def infer(prompt,negative_prompt):
|
71 |
|
|
|
72 |
image = pipe(
|
73 |
-
prompt
|
74 |
-
negative_prompt
|
75 |
-
width
|
76 |
-
height
|
77 |
guidance_scale=1.0,
|
78 |
num_inference_steps=4,
|
79 |
num_images_per_prompt=1,
|
80 |
-
).images[0]
|
81 |
-
|
82 |
return image
|
83 |
|
84 |
|
@@ -89,24 +73,23 @@ examples = [
|
|
89 |
"(illustration, 8k CG, extremely detailed),(whimsical),catgirl,teenage girl,playing in the snow,winter wonderland,snow-covered trees,soft pastel colors,gentle lighting,sparkling snow,joyful,magical atmosphere,highly detailed,fluffy cat ears and tail,intricate winter clothing,shallow depth of field,watercolor techniques,close-up shot,slightly tilted angle,fairy tale architecture,nostalgic,playful,winter magic,(masterpiece:2),best quality,ultra highres,original,extremely detailed,perfect lighting,",
|
90 |
]
|
91 |
|
92 |
-
css="""
|
93 |
#col-container {
|
94 |
margin: 0 auto;
|
95 |
max-width: 520px;
|
96 |
}
|
97 |
"""
|
98 |
|
99 |
-
|
100 |
power_device = "CPU"
|
101 |
|
102 |
with gr.Blocks(css=css) as demo:
|
103 |
-
|
104 |
with gr.Column(elem_id="col-container"):
|
105 |
gr.Markdown(f"""
|
106 |
# Disty0/LCM_SoteMix {WIDTH}x{HIGH}
|
107 |
Currently running on {power_device}.
|
108 |
""")
|
109 |
-
|
110 |
with gr.Row():
|
111 |
prompt = gr.Text(
|
112 |
label="Prompt",
|
@@ -114,22 +97,22 @@ with gr.Blocks(css=css) as demo:
|
|
114 |
max_lines=1,
|
115 |
placeholder="Enter your prompt",
|
116 |
container=False,
|
117 |
-
)
|
118 |
run_button = gr.Button("Run", scale=0)
|
119 |
-
|
120 |
result = gr.Image(label="Result", show_label=False)
|
121 |
|
122 |
gr.Examples(
|
123 |
-
examples
|
124 |
-
fn
|
125 |
-
inputs
|
126 |
-
outputs
|
127 |
)
|
128 |
|
129 |
run_button.click(
|
130 |
-
fn
|
131 |
-
inputs
|
132 |
-
outputs
|
133 |
)
|
134 |
|
135 |
-
demo.queue().launch()
|
|
|
8 |
import openvino.runtime as ov
|
9 |
from typing import Optional, Dict
|
10 |
|
|
|
|
|
11 |
model_id = "Disty0/LCM_SoteMix"
|
12 |
+
# model_id = "Disty0/sotediffusion-v2" #不可
|
13 |
|
14 |
+
# 1024*512 記憶體不足
|
15 |
+
HIGH = 768
|
16 |
+
WIDTH = 512
|
17 |
|
18 |
batch_size = -1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
pipe = OVStableDiffusionPipeline.from_pretrained(
|
21 |
+
model_id,
|
22 |
+
compile=False,
|
23 |
+
ov_config={"CACHE_DIR": ""},
|
24 |
+
torch_dtype=torch.int8, # 快
|
25 |
+
# torch_dtype=torch.bfloat16, # 中
|
26 |
+
# variant="fp16",
|
27 |
+
# torch_dtype=torch.IntTensor, # 慢
|
28 |
+
use_safetensors=False,
|
29 |
+
)
|
30 |
|
31 |
taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
|
32 |
+
|
33 |
+
# 這裡直接使用 OVModelVaeDecoder,而不是自訂的 CustomOVModelVaeDecoder
|
|
|
|
|
|
|
|
|
34 |
pipe.vae_decoder = OVModelVaeDecoder(
|
35 |
+
model=OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
|
36 |
+
parent_model=pipe,
|
37 |
+
ov_config=None, # 如果沒有配置,傳入 None
|
38 |
+
model_type="vae_decoder", # 保持與原本類型一致
|
39 |
model_dir=taesd_dir
|
40 |
)
|
41 |
|
42 |
+
pipe.reshape(batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
|
43 |
+
# pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
|
44 |
+
# pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
|
45 |
+
# <shigure-ui-style>
|
46 |
+
# pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
|
47 |
+
# pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
|
48 |
+
# pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
|
|
|
|
|
49 |
|
50 |
pipe.compile()
|
51 |
|
52 |
+
prompt = ""
|
53 |
+
negative_prompt = "(worst quality, low quality, lowres), zombie, interlocked fingers,"
|
|
|
|
|
54 |
|
55 |
+
def infer(prompt, negative_prompt):
|
56 |
image = pipe(
|
57 |
+
prompt=prompt,
|
58 |
+
negative_prompt=negative_prompt,
|
59 |
+
width=WIDTH,
|
60 |
+
height=HIGH,
|
61 |
guidance_scale=1.0,
|
62 |
num_inference_steps=4,
|
63 |
num_images_per_prompt=1,
|
64 |
+
).images[0]
|
65 |
+
|
66 |
return image
|
67 |
|
68 |
|
|
|
73 |
"(illustration, 8k CG, extremely detailed),(whimsical),catgirl,teenage girl,playing in the snow,winter wonderland,snow-covered trees,soft pastel colors,gentle lighting,sparkling snow,joyful,magical atmosphere,highly detailed,fluffy cat ears and tail,intricate winter clothing,shallow depth of field,watercolor techniques,close-up shot,slightly tilted angle,fairy tale architecture,nostalgic,playful,winter magic,(masterpiece:2),best quality,ultra highres,original,extremely detailed,perfect lighting,",
|
74 |
]
|
75 |
|
76 |
+
css = """
|
77 |
#col-container {
|
78 |
margin: 0 auto;
|
79 |
max-width: 520px;
|
80 |
}
|
81 |
"""
|
82 |
|
|
|
83 |
power_device = "CPU"
|
84 |
|
85 |
with gr.Blocks(css=css) as demo:
|
86 |
+
|
87 |
with gr.Column(elem_id="col-container"):
|
88 |
gr.Markdown(f"""
|
89 |
# Disty0/LCM_SoteMix {WIDTH}x{HIGH}
|
90 |
Currently running on {power_device}.
|
91 |
""")
|
92 |
+
|
93 |
with gr.Row():
|
94 |
prompt = gr.Text(
|
95 |
label="Prompt",
|
|
|
97 |
max_lines=1,
|
98 |
placeholder="Enter your prompt",
|
99 |
container=False,
|
100 |
+
)
|
101 |
run_button = gr.Button("Run", scale=0)
|
102 |
+
|
103 |
result = gr.Image(label="Result", show_label=False)
|
104 |
|
105 |
gr.Examples(
|
106 |
+
examples=examples,
|
107 |
+
fn=infer,
|
108 |
+
inputs=[prompt],
|
109 |
+
outputs=[result]
|
110 |
)
|
111 |
|
112 |
run_button.click(
|
113 |
+
fn=infer,
|
114 |
+
inputs=[prompt],
|
115 |
+
outputs=[result]
|
116 |
)
|
117 |
|
118 |
+
demo.queue().launch()
|