Spaces:
Running
on
T4
Running
on
T4
Krebzonide
commited on
Commit
•
983bcd6
1
Parent(s):
f1f2536
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
from diffusers import AutoPipelineForText2Image, StableDiffusionImg2ImgPipeline
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
4 |
-
import numpy as np
|
5 |
import random
|
6 |
import torch
|
7 |
import math
|
@@ -17,36 +16,33 @@ css = """
|
|
17 |
}
|
18 |
"""
|
19 |
|
20 |
-
def generate(prompt, samp_steps, seed,
|
21 |
if seed < 0:
|
22 |
seed = random.randint(1,999999)
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
data=np.random.randint(low=0,high=256,size=128*128*3, dtype=np.uint8)
|
30 |
-
data=data.reshape(128,128,3)
|
31 |
-
image = Image.fromarray(data,'RGB')
|
32 |
upscaled_image = image.resize((1024,1024), 1)
|
33 |
final_image = img2img(
|
34 |
prompt,
|
35 |
upscaled_image,
|
36 |
num_inference_steps=math.ceil(samp_steps/strength),
|
37 |
guidance_scale=5,
|
38 |
-
strength=
|
39 |
generator=torch.manual_seed(seed),
|
40 |
).images[0]
|
41 |
return [final_image], seed
|
42 |
|
43 |
def set_base_models():
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
img2img = StableDiffusionImg2ImgPipeline.from_pretrained(
|
51 |
"Lykon/dreamshaper-8",
|
52 |
torch_dtype = torch.float16,
|
@@ -62,14 +58,13 @@ with gr.Blocks(css=css) as demo:
|
|
62 |
submit_btn = gr.Button("Generate", elem_classes="btn-green")
|
63 |
|
64 |
with gr.Row():
|
65 |
-
sampling_steps = gr.Slider(1,
|
66 |
-
strength = gr.Slider(0, 1, value=0.75, step=0.05, label="Refiner strength")
|
67 |
seed = gr.Number(label="Seed", value=-1, minimum=-1, precision=0)
|
68 |
lastSeed = gr.Number(label="Last Seed", value=-1, interactive=False)
|
69 |
|
70 |
gallery = gr.Gallery(show_label=False, preview=True, container=False, height=1100)
|
71 |
|
72 |
-
submit_btn.click(generate, [prompt, sampling_steps, seed
|
73 |
|
74 |
txt2img, img2img = set_base_models()
|
75 |
demo.launch(debug=True)
|
|
|
1 |
from diffusers import AutoPipelineForText2Image, StableDiffusionImg2ImgPipeline
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
|
|
4 |
import random
|
5 |
import torch
|
6 |
import math
|
|
|
16 |
}
|
17 |
"""
|
18 |
|
19 |
+
def generate(prompt, samp_steps, seed, progress=gr.Progress(track_tqdm=True)):
|
20 |
if seed < 0:
|
21 |
seed = random.randint(1,999999)
|
22 |
+
image = txt2img(
|
23 |
+
prompt,
|
24 |
+
num_inference_steps=1,
|
25 |
+
guidance_scale=0.0,
|
26 |
+
generator=torch.manual_seed(seed),
|
27 |
+
).images[0]
|
|
|
|
|
|
|
28 |
upscaled_image = image.resize((1024,1024), 1)
|
29 |
final_image = img2img(
|
30 |
prompt,
|
31 |
upscaled_image,
|
32 |
num_inference_steps=math.ceil(samp_steps/strength),
|
33 |
guidance_scale=5,
|
34 |
+
strength=1,
|
35 |
generator=torch.manual_seed(seed),
|
36 |
).images[0]
|
37 |
return [final_image], seed
|
38 |
|
39 |
def set_base_models():
|
40 |
+
txt2img = AutoPipelineForText2Image.from_pretrained(
|
41 |
+
"stabilityai/sdxl-turbo",
|
42 |
+
torch_dtype = torch.float16,
|
43 |
+
variant = "fp16"
|
44 |
+
)
|
45 |
+
txt2img.to("cuda")
|
46 |
img2img = StableDiffusionImg2ImgPipeline.from_pretrained(
|
47 |
"Lykon/dreamshaper-8",
|
48 |
torch_dtype = torch.float16,
|
|
|
58 |
submit_btn = gr.Button("Generate", elem_classes="btn-green")
|
59 |
|
60 |
with gr.Row():
|
61 |
+
sampling_steps = gr.Slider(1, 6, value=3, step=1, label="Refiner steps")
|
|
|
62 |
seed = gr.Number(label="Seed", value=-1, minimum=-1, precision=0)
|
63 |
lastSeed = gr.Number(label="Last Seed", value=-1, interactive=False)
|
64 |
|
65 |
gallery = gr.Gallery(show_label=False, preview=True, container=False, height=1100)
|
66 |
|
67 |
+
submit_btn.click(generate, [prompt, sampling_steps, seed], [gallery, lastSeed], queue=True)
|
68 |
|
69 |
txt2img, img2img = set_base_models()
|
70 |
demo.launch(debug=True)
|