Update app.py
Browse files
app.py
CHANGED
@@ -3,30 +3,24 @@ import gradio as gr
|
|
3 |
import numpy as np
|
4 |
import spaces
|
5 |
import torch
|
6 |
-
from diffusers import
|
7 |
-
|
8 |
-
# 添加导入语句
|
9 |
-
from sd_embed.embedding_funcs import get_weighted_text_embeddings_sdxl
|
10 |
|
11 |
if not torch.cuda.is_available():
|
12 |
-
DESCRIPTION += "\n<p>你现在运行在CPU
|
13 |
|
14 |
MAX_SEED = np.iinfo(np.int32).max
|
15 |
MAX_IMAGE_SIZE = 4096
|
16 |
|
17 |
if torch.cuda.is_available():
|
18 |
-
vae = AutoencoderKL.from_pretrained(
|
19 |
-
|
20 |
-
)
|
21 |
-
pipe = StableDiffusionXLPipeline.from_pretrained(
|
22 |
"John6666/noobai-xl-nai-xl-epsilonpred075version-sdxl",
|
23 |
vae=vae,
|
24 |
torch_dtype=torch.float16,
|
25 |
use_safetensors=True,
|
26 |
-
add_watermarker=False
|
27 |
)
|
28 |
-
#
|
29 |
-
# pipe.tokenizer.model_max_length = 512
|
30 |
pipe.to("cuda")
|
31 |
|
32 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
@@ -38,7 +32,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
38 |
def infer(
|
39 |
prompt: str,
|
40 |
negative_prompt: str = "",
|
41 |
-
use_negative_prompt: bool =
|
42 |
seed: int = 1,
|
43 |
width: int = 512,
|
44 |
height: int = 768,
|
@@ -50,40 +44,15 @@ def infer(
|
|
50 |
):
|
51 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
52 |
generator = torch.Generator().manual_seed(seed)
|
53 |
-
|
54 |
-
# 使用 get_weighted_text_embeddings_sdxl 获取文本嵌入,不传递 device 参数
|
55 |
-
if use_negative_prompt and negative_prompt:
|
56 |
-
(
|
57 |
-
prompt_embeds,
|
58 |
-
prompt_neg_embeds,
|
59 |
-
pooled_prompt_embeds,
|
60 |
-
negative_pooled_prompt_embeds,
|
61 |
-
) = get_weighted_text_embeddings_sdxl(
|
62 |
-
pipe,
|
63 |
-
prompt=prompt,
|
64 |
-
neg_prompt=negative_prompt,
|
65 |
-
)
|
66 |
-
else:
|
67 |
-
(
|
68 |
-
prompt_embeds,
|
69 |
-
_,
|
70 |
-
pooled_prompt_embeds,
|
71 |
-
_,
|
72 |
-
) = get_weighted_text_embeddings_sdxl(
|
73 |
-
pipe,
|
74 |
-
prompt=prompt,
|
75 |
-
)
|
76 |
-
prompt_neg_embeds = None
|
77 |
-
negative_pooled_prompt_embeds = None
|
78 |
-
|
79 |
image = pipe(
|
80 |
-
|
81 |
-
|
82 |
width=width,
|
83 |
height=height,
|
84 |
guidance_scale=guidance_scale,
|
85 |
num_inference_steps=num_inference_steps,
|
86 |
generator=generator,
|
|
|
87 |
).images[0]
|
88 |
return image, seed
|
89 |
|
@@ -93,13 +62,13 @@ examples = [
|
|
93 |
]
|
94 |
|
95 |
css = '''
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
'''
|
102 |
-
|
103 |
with gr.Blocks(css=css) as demo:
|
104 |
gr.Markdown("""# 梦羽的模型生成器
|
105 |
### 快速生成NoobXL的模型图片.""")
|
@@ -171,7 +140,7 @@ with gr.Blocks(css=css) as demo:
|
|
171 |
)
|
172 |
|
173 |
gr.on(
|
174 |
-
triggers=[prompt.submit,
|
175 |
fn=infer,
|
176 |
inputs=[
|
177 |
prompt,
|
|
|
3 |
import numpy as np
|
4 |
import spaces
|
5 |
import torch
|
6 |
+
from diffusers import AutoPipelineForText2Image, AutoencoderKL #,EulerDiscreteScheduler
|
|
|
|
|
|
|
7 |
|
8 |
if not torch.cuda.is_available():
|
9 |
+
DESCRIPTION += "\n<p>你现在运行在CPU上 但是只支持GPU.</p>"
|
10 |
|
11 |
MAX_SEED = np.iinfo(np.int32).max
|
12 |
MAX_IMAGE_SIZE = 4096
|
13 |
|
14 |
if torch.cuda.is_available():
|
15 |
+
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
16 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
|
|
|
|
17 |
"John6666/noobai-xl-nai-xl-epsilonpred075version-sdxl",
|
18 |
vae=vae,
|
19 |
torch_dtype=torch.float16,
|
20 |
use_safetensors=True,
|
21 |
+
add_watermarker=False
|
22 |
)
|
23 |
+
#pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
|
|
24 |
pipe.to("cuda")
|
25 |
|
26 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
|
32 |
def infer(
|
33 |
prompt: str,
|
34 |
negative_prompt: str = "",
|
35 |
+
use_negative_prompt: bool = False,
|
36 |
seed: int = 1,
|
37 |
width: int = 512,
|
38 |
height: int = 768,
|
|
|
44 |
):
|
45 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
46 |
generator = torch.Generator().manual_seed(seed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
image = pipe(
|
48 |
+
prompt=prompt,
|
49 |
+
negative_prompt=negative_prompt,
|
50 |
width=width,
|
51 |
height=height,
|
52 |
guidance_scale=guidance_scale,
|
53 |
num_inference_steps=num_inference_steps,
|
54 |
generator=generator,
|
55 |
+
use_resolution_binning=use_resolution_binning,
|
56 |
).images[0]
|
57 |
return image, seed
|
58 |
|
|
|
62 |
]
|
63 |
|
64 |
css = '''
|
65 |
+
.gradio-container{max-width: 560px !important}
|
66 |
+
h1{text-align:center}
|
67 |
+
footer {
|
68 |
+
visibility: hidden
|
69 |
+
}
|
70 |
'''
|
71 |
+
|
72 |
with gr.Blocks(css=css) as demo:
|
73 |
gr.Markdown("""# 梦羽的模型生成器
|
74 |
### 快速生成NoobXL的模型图片.""")
|
|
|
140 |
)
|
141 |
|
142 |
gr.on(
|
143 |
+
triggers=[prompt.submit,run_button.click],
|
144 |
fn=infer,
|
145 |
inputs=[
|
146 |
prompt,
|