Spaces:
Running
on
T4
Running
on
T4
Krebzonide
commited on
Commit
·
98b5af6
1
Parent(s):
5a5ee63
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from diffusers import
|
2 |
import torch
|
3 |
import random
|
4 |
import os
|
@@ -35,7 +35,7 @@ css = """
|
|
35 |
}
|
36 |
"""
|
37 |
|
38 |
-
def generate(prompt,
|
39 |
prompt = prompt.lower()
|
40 |
if nsfw_filter:
|
41 |
if prompt[:10] == "krebzonide":
|
@@ -49,10 +49,9 @@ def generate(prompt, neg_prompt, samp_steps, cfg_scale, batch_size, seed, height
|
|
49 |
seed = random.randint(1,999999)
|
50 |
images = pipe(
|
51 |
prompt,
|
52 |
-
negative_prompt=neg_prompt,
|
53 |
num_inference_steps=samp_steps,
|
54 |
-
guidance_scale=cfg_scale,
|
55 |
num_images_per_prompt=batch_size,
|
|
|
56 |
height=height,
|
57 |
width=width,
|
58 |
generator=torch.manual_seed(seed),
|
@@ -63,16 +62,13 @@ def set_base_model(base_model_id):
|
|
63 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
64 |
global model_url_list
|
65 |
model_url = "https://huggingface.co/" + model_url_list[base_model_id]
|
66 |
-
pipe =
|
67 |
-
|
68 |
torch_dtype = torch.float16,
|
69 |
-
variant = "fp16"
|
70 |
-
|
71 |
-
use_safetensors = True,
|
72 |
-
use_auth_token=hf_token
|
73 |
)
|
74 |
pipe.to("cuda")
|
75 |
-
pipe.enable_xformers_memory_efficient_attention()
|
76 |
return pipe
|
77 |
|
78 |
def update_pixel_ratio(num1, num2):
|
@@ -100,12 +96,10 @@ examples = [
|
|
100 |
with gr.Blocks(css=css) as demo:
|
101 |
with gr.Column():
|
102 |
prompt = gr.Textbox(label="Prompt")
|
103 |
-
negative_prompt = gr.Textbox(label="Negative Prompt")
|
104 |
submit_btn = gr.Button("Generate", elem_classes="btn-green")
|
105 |
with gr.Row():
|
106 |
samp_steps = gr.Slider(1, 30, value=20, step=1, label="Sampling steps")
|
107 |
-
|
108 |
-
batch_size = gr.Slider(1, 6, value=1, step=1, label="Batch size", interactive=False)
|
109 |
with gr.Row():
|
110 |
height = gr.Slider(label="Height", value=1024, minimum=8, maximum=1536, step=8)
|
111 |
width = gr.Slider(label="Width", value=1024, minimum=8, maximum=1024, step=8)
|
@@ -116,7 +110,7 @@ with gr.Blocks(css=css) as demo:
|
|
116 |
with gr.Row():
|
117 |
lastSeed = gr.Number(label="Last Seed", value=-1, interactive=False)
|
118 |
ex = gr.Examples(examples=examples, inputs=[prompt, negative_prompt])
|
119 |
-
submit_btn.click(generate, [prompt,
|
120 |
height.release(update_pixel_ratio, [height, width], [pixels, height], queue=False)
|
121 |
width.release(update_pixel_ratio, [width, height], [pixels, width], queue=False)
|
122 |
|
|
|
1 |
+
from diffusers import AutoPipelineForText2Image
|
2 |
import torch
|
3 |
import random
|
4 |
import os
|
|
|
35 |
}
|
36 |
"""
|
37 |
|
38 |
+
def generate(prompt, samp_steps, batch_size, seed, height, width, progress=gr.Progress(track_tqdm=True)):
|
39 |
prompt = prompt.lower()
|
40 |
if nsfw_filter:
|
41 |
if prompt[:10] == "krebzonide":
|
|
|
49 |
seed = random.randint(1,999999)
|
50 |
images = pipe(
|
51 |
prompt,
|
|
|
52 |
num_inference_steps=samp_steps,
|
|
|
53 |
num_images_per_prompt=batch_size,
|
54 |
+
guidance_scale=0.0,
|
55 |
height=height,
|
56 |
width=width,
|
57 |
generator=torch.manual_seed(seed),
|
|
|
62 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
63 |
global model_url_list
|
64 |
model_url = "https://huggingface.co/" + model_url_list[base_model_id]
|
65 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
66 |
+
"stabilityai/sdxl-turbo",
|
67 |
torch_dtype = torch.float16,
|
68 |
+
variant = "fp16"
|
69 |
+
#use_auth_token=hf_token
|
|
|
|
|
70 |
)
|
71 |
pipe.to("cuda")
|
|
|
72 |
return pipe
|
73 |
|
74 |
def update_pixel_ratio(num1, num2):
|
|
|
96 |
with gr.Blocks(css=css) as demo:
|
97 |
with gr.Column():
|
98 |
prompt = gr.Textbox(label="Prompt")
|
|
|
99 |
submit_btn = gr.Button("Generate", elem_classes="btn-green")
|
100 |
with gr.Row():
|
101 |
samp_steps = gr.Slider(1, 30, value=20, step=1, label="Sampling steps")
|
102 |
+
batch_size = gr.Slider(1, 6, value=1, step=1, label="Batch size", interactive=True)
|
|
|
103 |
with gr.Row():
|
104 |
height = gr.Slider(label="Height", value=1024, minimum=8, maximum=1536, step=8)
|
105 |
width = gr.Slider(label="Width", value=1024, minimum=8, maximum=1024, step=8)
|
|
|
110 |
with gr.Row():
|
111 |
lastSeed = gr.Number(label="Last Seed", value=-1, interactive=False)
|
112 |
ex = gr.Examples(examples=examples, inputs=[prompt, negative_prompt])
|
113 |
+
submit_btn.click(generate, [prompt, samp_steps, batch_size, seed, height, width], [gallery, lastSeed], queue=True)
|
114 |
height.release(update_pixel_ratio, [height, width], [pixels, height], queue=False)
|
115 |
width.release(update_pixel_ratio, [width, height], [pixels, width], queue=False)
|
116 |
|