James Peter Perrfone Jefferies
commited on
Commit
·
601904e
1
Parent(s):
6e0823f
Add seed support
Browse files
app.py
CHANGED
@@ -2,10 +2,14 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from diffusers import DiffusionPipeline
|
4 |
|
|
|
|
|
5 |
def generate(
|
6 |
-
prompt, negative_prompt, num_inference_steps, width, height, guidance_scale
|
7 |
):
|
8 |
-
pipeline = DiffusionPipeline.from_pretrained("Lykon/DreamShaper")
|
|
|
|
|
9 |
|
10 |
return pipeline(
|
11 |
prompt=prompt,
|
@@ -14,6 +18,7 @@ def generate(
|
|
14 |
width=width,
|
15 |
height=height,
|
16 |
guidance_scale=guidance_scale,
|
|
|
17 |
).images[0]
|
18 |
|
19 |
iface = gr.Interface(
|
@@ -25,6 +30,13 @@ iface = gr.Interface(
|
|
25 |
gr.Slider(label="Width", minimum=64, maximum=2048, value=512, step=1),
|
26 |
gr.Slider(label="Height", minimum=64, maximum=2048, value=512, step=1),
|
27 |
gr.Slider(label="CFG Scale", minimum=1, maximum=30, value=9, step=0.5),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
],
|
29 |
outputs="image",
|
30 |
)
|
|
|
2 |
import torch
|
3 |
from diffusers import DiffusionPipeline
|
4 |
|
5 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
6 |
+
|
7 |
def generate(
|
8 |
+
prompt, negative_prompt, num_inference_steps, width, height, guidance_scale, seed
|
9 |
):
|
10 |
+
pipeline = DiffusionPipeline.from_pretrained("Lykon/DreamShaper", safety_checker=None)
|
11 |
+
pipeline = pipeline.to(device)
|
12 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
13 |
|
14 |
return pipeline(
|
15 |
prompt=prompt,
|
|
|
18 |
width=width,
|
19 |
height=height,
|
20 |
guidance_scale=guidance_scale,
|
21 |
+
generator=generator,
|
22 |
).images[0]
|
23 |
|
24 |
iface = gr.Interface(
|
|
|
30 |
gr.Slider(label="Width", minimum=64, maximum=2048, value=512, step=1),
|
31 |
gr.Slider(label="Height", minimum=64, maximum=2048, value=512, step=1),
|
32 |
gr.Slider(label="CFG Scale", minimum=1, maximum=30, value=9, step=0.5),
|
33 |
+
gr.Slider(
|
34 |
+
label="Seed",
|
35 |
+
minimum=0,
|
36 |
+
maximum=4294967294,
|
37 |
+
step=1,
|
38 |
+
randomize=True,
|
39 |
+
),
|
40 |
],
|
41 |
outputs="image",
|
42 |
)
|