Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
|
5 |
-
# import spaces #[uncomment to use ZeroGPU]
|
6 |
from diffusers import DiffusionPipeline
|
|
|
7 |
import torch
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
torch_dtype = torch.float32
|
16 |
|
17 |
-
|
18 |
-
pipe = pipe.to(device)
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
progress=gr.Progress(track_tqdm=True),
|
35 |
-
):
|
36 |
-
if randomize_seed:
|
37 |
-
seed = random.randint(0, MAX_SEED)
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
image = pipe(
|
42 |
-
prompt=prompt,
|
43 |
-
negative_prompt=negative_prompt,
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
).images[0]
|
|
|
|
|
50 |
|
51 |
-
return image, seed
|
52 |
|
53 |
|
54 |
examples = [
|
55 |
-
"
|
56 |
-
"
|
57 |
-
"
|
|
|
58 |
]
|
59 |
|
60 |
-
css
|
61 |
#col-container {
|
62 |
margin: 0 auto;
|
63 |
-
max-width:
|
64 |
}
|
65 |
"""
|
66 |
|
|
|
|
|
|
|
67 |
with gr.Blocks(css=css) as demo:
|
|
|
68 |
with gr.Column(elem_id="col-container"):
|
69 |
-
gr.Markdown("
|
70 |
-
|
|
|
|
|
|
|
71 |
with gr.Row():
|
72 |
prompt = gr.Text(
|
73 |
label="Prompt",
|
@@ -75,80 +155,22 @@ with gr.Blocks(css=css) as demo:
|
|
75 |
max_lines=1,
|
76 |
placeholder="Enter your prompt",
|
77 |
container=False,
|
78 |
-
)
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
result = gr.Image(label="Result", show_label=False)
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
maximum=MAX_SEED,
|
96 |
-
step=1,
|
97 |
-
value=0,
|
98 |
-
)
|
99 |
-
|
100 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
101 |
-
|
102 |
-
with gr.Row():
|
103 |
-
width = gr.Slider(
|
104 |
-
label="Width",
|
105 |
-
minimum=256,
|
106 |
-
maximum=MAX_IMAGE_SIZE,
|
107 |
-
step=32,
|
108 |
-
value=1024, # Replace with defaults that work for your model
|
109 |
-
)
|
110 |
-
|
111 |
-
height = gr.Slider(
|
112 |
-
label="Height",
|
113 |
-
minimum=256,
|
114 |
-
maximum=MAX_IMAGE_SIZE,
|
115 |
-
step=32,
|
116 |
-
value=1024, # Replace with defaults that work for your model
|
117 |
-
)
|
118 |
-
|
119 |
-
with gr.Row():
|
120 |
-
guidance_scale = gr.Slider(
|
121 |
-
label="Guidance scale",
|
122 |
-
minimum=0.0,
|
123 |
-
maximum=10.0,
|
124 |
-
step=0.1,
|
125 |
-
value=0.0, # Replace with defaults that work for your model
|
126 |
-
)
|
127 |
-
|
128 |
-
num_inference_steps = gr.Slider(
|
129 |
-
label="Number of inference steps",
|
130 |
-
minimum=1,
|
131 |
-
maximum=50,
|
132 |
-
step=1,
|
133 |
-
value=2, # Replace with defaults that work for your model
|
134 |
-
)
|
135 |
-
|
136 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
137 |
-
gr.on(
|
138 |
-
triggers=[run_button.click, prompt.submit],
|
139 |
-
fn=infer,
|
140 |
-
inputs=[
|
141 |
-
prompt,
|
142 |
-
negative_prompt,
|
143 |
-
seed,
|
144 |
-
randomize_seed,
|
145 |
-
width,
|
146 |
-
height,
|
147 |
-
guidance_scale,
|
148 |
-
num_inference_steps,
|
149 |
-
],
|
150 |
-
outputs=[result, seed],
|
151 |
)
|
152 |
|
153 |
-
|
154 |
-
demo.launch()
|
|
|
1 |
+
Hugging Face's logo
|
2 |
+
Hugging Face
|
3 |
+
Models
|
4 |
+
Datasets
|
5 |
+
Spaces
|
6 |
+
Posts
|
7 |
+
Docs
|
8 |
+
Enterprise
|
9 |
+
Pricing
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
Spaces:
|
14 |
+
|
15 |
+
|
16 |
+
hsuwill000
|
17 |
+
/
|
18 |
+
LCM_SoteMix_OpenVINO_CPU_Space_TAESD_0
|
19 |
+
|
20 |
+
|
21 |
+
like
|
22 |
+
0
|
23 |
+
|
24 |
+
Logs
|
25 |
+
App
|
26 |
+
Files
|
27 |
+
Community
|
28 |
+
Settings
|
29 |
+
LCM_SoteMix_OpenVINO_CPU_Space_TAESD_0
|
30 |
+
/
|
31 |
+
app.py
|
32 |
+
|
33 |
+
hsuwill000's picture
|
34 |
+
hsuwill000
|
35 |
+
Update app.py
|
36 |
+
075782c
|
37 |
+
verified
|
38 |
+
2 months ago
|
39 |
+
raw
|
40 |
+
|
41 |
+
Copy download link
|
42 |
+
history
|
43 |
+
blame
|
44 |
+
edit
|
45 |
+
delete
|
46 |
+
|
47 |
+
4.66 kB
|
48 |
import gradio as gr
|
49 |
import numpy as np
|
50 |
import random
|
|
|
|
|
51 |
from diffusers import DiffusionPipeline
|
52 |
+
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel, OVStableDiffusionPipeline
|
53 |
import torch
|
54 |
+
from huggingface_hub import snapshot_download
|
55 |
+
import openvino.runtime as ov
|
56 |
+
from typing import Optional, Dict
|
57 |
+
|
58 |
+
|
59 |
|
60 |
+
model_id = "stabilityai/sdxl-turbo"
|
61 |
+
#model_id = "Disty0/sotediffusion-v2" #不可
|
62 |
|
63 |
+
#1024*512 記憶體不足
|
64 |
+
HIGH=512
|
65 |
+
WIDTH=512
|
|
|
66 |
|
67 |
+
batch_size = -1
|
|
|
68 |
|
69 |
+
class CustomOVModelVaeDecoder(OVModelVaeDecoder):
|
70 |
+
def __init__(
|
71 |
+
self, model: ov.Model, parent_model: OVBaseModel, ov_config: Optional[Dict[str, str]] = None, model_dir: str = None,
|
72 |
+
):
|
73 |
+
super(OVModelVaeDecoder, self).__init__(model, parent_model, ov_config, "vae_decoder", model_dir)
|
74 |
|
75 |
|
76 |
+
pipe = OVStableDiffusionPipeline.from_pretrained(
|
77 |
+
model_id,
|
78 |
+
compile = False,
|
79 |
+
ov_config = {"CACHE_DIR":""},
|
80 |
+
torch_dtype=torch.int8, #快
|
81 |
+
#torch_dtype=torch.bfloat16, #中
|
82 |
+
#variant="fp16",
|
83 |
+
#torch_dtype=torch.IntTensor, #慢
|
84 |
+
use_safetensors=False,
|
85 |
+
)
|
|
|
|
|
|
|
|
|
86 |
|
87 |
+
taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
|
88 |
+
|
89 |
+
pipe.vae_decoder = CustomOVModelVaeDecoder(model = OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
|
90 |
+
parent_model = pipe,
|
91 |
+
model_dir = taesd_dir
|
92 |
+
)
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
|
97 |
+
#pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
|
98 |
+
#pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
|
99 |
+
#<shigure-ui-style>
|
100 |
+
#pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
|
101 |
+
#pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
|
102 |
+
#pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
|
103 |
+
|
104 |
+
|
105 |
+
pipe.compile()
|
106 |
+
|
107 |
+
prompt=""
|
108 |
+
negative_prompt="(worst quality, low quality, lowres, loli, kid, child), zombie, interlocked fingers, large breasts, username, watermark,"
|
109 |
+
|
110 |
+
def infer(prompt,negative_prompt):
|
111 |
|
112 |
image = pipe(
|
113 |
+
prompt = prompt,
|
114 |
+
negative_prompt = negative_prompt,
|
115 |
+
width = WIDTH,
|
116 |
+
height = HIGH,
|
117 |
+
guidance_scale=1.0,
|
118 |
+
num_inference_steps=8,
|
119 |
+
num_images_per_prompt=1,
|
120 |
+
).images[0]
|
121 |
+
|
122 |
+
return image
|
123 |
|
|
|
124 |
|
125 |
|
126 |
examples = [
|
127 |
+
"(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,",
|
128 |
+
"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",
|
129 |
+
"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,",
|
130 |
+
"((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))),",
|
131 |
]
|
132 |
|
133 |
+
css="""
|
134 |
#col-container {
|
135 |
margin: 0 auto;
|
136 |
+
max-width: 520px;
|
137 |
}
|
138 |
"""
|
139 |
|
140 |
+
|
141 |
+
power_device = "CPU"
|
142 |
+
|
143 |
with gr.Blocks(css=css) as demo:
|
144 |
+
|
145 |
with gr.Column(elem_id="col-container"):
|
146 |
+
gr.Markdown(f"""
|
147 |
+
# Disty0/LCM_SoteMix {WIDTH}x{HIGH}
|
148 |
+
Currently running on {power_device}.
|
149 |
+
""")
|
150 |
+
|
151 |
with gr.Row():
|
152 |
prompt = gr.Text(
|
153 |
label="Prompt",
|
|
|
155 |
max_lines=1,
|
156 |
placeholder="Enter your prompt",
|
157 |
container=False,
|
158 |
+
)
|
159 |
+
run_button = gr.Button("Run", scale=0)
|
160 |
+
|
|
|
161 |
result = gr.Image(label="Result", show_label=False)
|
162 |
|
163 |
+
gr.Examples(
|
164 |
+
examples = examples,
|
165 |
+
fn = infer,
|
166 |
+
inputs = [prompt],
|
167 |
+
outputs = [result]
|
168 |
+
)
|
169 |
+
|
170 |
+
run_button.click(
|
171 |
+
fn = infer,
|
172 |
+
inputs = [prompt],
|
173 |
+
outputs = [result]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
)
|
175 |
|
176 |
+
demo.queue().launch()
|
|