Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
-
from diffusers import DiffusionPipeline
|
5 |
import torch
|
|
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
9 |
if torch.cuda.is_available():
|
10 |
torch.cuda.max_memory_allocated(device=device)
|
11 |
-
pipe =
|
12 |
pipe.enable_xformers_memory_efficient_attention()
|
13 |
pipe = pipe.to(device)
|
14 |
else:
|
15 |
-
pipe =
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
-
MAX_IMAGE_SIZE =
|
20 |
|
21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
|
@@ -37,12 +37,6 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
37 |
|
38 |
return image
|
39 |
|
40 |
-
examples = [
|
41 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
42 |
-
"An astronaut riding a green horse",
|
43 |
-
"A delicious ceviche cheesecake slice",
|
44 |
-
]
|
45 |
-
|
46 |
css="""
|
47 |
#col-container {
|
48 |
margin: 0 auto;
|
@@ -50,17 +44,12 @@ css="""
|
|
50 |
}
|
51 |
"""
|
52 |
|
53 |
-
if torch.cuda.is_available():
|
54 |
-
power_device = "GPU"
|
55 |
-
else:
|
56 |
-
power_device = "CPU"
|
57 |
|
58 |
with gr.Blocks(css=css) as demo:
|
59 |
|
60 |
with gr.Column(elem_id="col-container"):
|
61 |
gr.Markdown(f"""
|
62 |
-
#
|
63 |
-
Currently running on {power_device}.
|
64 |
""")
|
65 |
|
66 |
with gr.Row():
|
@@ -68,7 +57,7 @@ with gr.Blocks(css=css) as demo:
|
|
68 |
prompt = gr.Text(
|
69 |
label="Prompt",
|
70 |
show_label=False,
|
71 |
-
max_lines=
|
72 |
placeholder="Enter your prompt",
|
73 |
container=False,
|
74 |
)
|
@@ -103,7 +92,7 @@ with gr.Blocks(css=css) as demo:
|
|
103 |
minimum=256,
|
104 |
maximum=MAX_IMAGE_SIZE,
|
105 |
step=32,
|
106 |
-
value=
|
107 |
)
|
108 |
|
109 |
height = gr.Slider(
|
@@ -111,7 +100,7 @@ with gr.Blocks(css=css) as demo:
|
|
111 |
minimum=256,
|
112 |
maximum=MAX_IMAGE_SIZE,
|
113 |
step=32,
|
114 |
-
value=
|
115 |
)
|
116 |
|
117 |
with gr.Row():
|
@@ -121,7 +110,7 @@ with gr.Blocks(css=css) as demo:
|
|
121 |
minimum=0.0,
|
122 |
maximum=10.0,
|
123 |
step=0.1,
|
124 |
-
value=
|
125 |
)
|
126 |
|
127 |
num_inference_steps = gr.Slider(
|
@@ -129,14 +118,10 @@ with gr.Blocks(css=css) as demo:
|
|
129 |
minimum=1,
|
130 |
maximum=12,
|
131 |
step=1,
|
132 |
-
value=
|
133 |
)
|
134 |
|
135 |
-
|
136 |
-
examples = examples,
|
137 |
-
inputs = [prompt]
|
138 |
-
)
|
139 |
-
|
140 |
run_button.click(
|
141 |
fn = infer,
|
142 |
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
|
|
4 |
import torch
|
5 |
+
from diffusers import StableDiffusion3Pipeline
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
9 |
if torch.cuda.is_available():
|
10 |
torch.cuda.max_memory_allocated(device=device)
|
11 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype=torch.float16)
|
12 |
pipe.enable_xformers_memory_efficient_attention()
|
13 |
pipe = pipe.to(device)
|
14 |
else:
|
15 |
+
pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers", torch_dtype=torch.float16)
|
16 |
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
+
MAX_IMAGE_SIZE = 2048
|
20 |
|
21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
|
|
|
37 |
|
38 |
return image
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
css="""
|
41 |
#col-container {
|
42 |
margin: 0 auto;
|
|
|
44 |
}
|
45 |
"""
|
46 |
|
|
|
|
|
|
|
|
|
47 |
|
48 |
with gr.Blocks(css=css) as demo:
|
49 |
|
50 |
with gr.Column(elem_id="col-container"):
|
51 |
gr.Markdown(f"""
|
52 |
+
# FallnAI Text2Image
|
|
|
53 |
""")
|
54 |
|
55 |
with gr.Row():
|
|
|
57 |
prompt = gr.Text(
|
58 |
label="Prompt",
|
59 |
show_label=False,
|
60 |
+
max_lines=4,
|
61 |
placeholder="Enter your prompt",
|
62 |
container=False,
|
63 |
)
|
|
|
92 |
minimum=256,
|
93 |
maximum=MAX_IMAGE_SIZE,
|
94 |
step=32,
|
95 |
+
value=1024,
|
96 |
)
|
97 |
|
98 |
height = gr.Slider(
|
|
|
100 |
minimum=256,
|
101 |
maximum=MAX_IMAGE_SIZE,
|
102 |
step=32,
|
103 |
+
value=1024,
|
104 |
)
|
105 |
|
106 |
with gr.Row():
|
|
|
110 |
minimum=0.0,
|
111 |
maximum=10.0,
|
112 |
step=0.1,
|
113 |
+
value=2.0,
|
114 |
)
|
115 |
|
116 |
num_inference_steps = gr.Slider(
|
|
|
118 |
minimum=1,
|
119 |
maximum=12,
|
120 |
step=1,
|
121 |
+
value=4,
|
122 |
)
|
123 |
|
124 |
+
|
|
|
|
|
|
|
|
|
125 |
run_button.click(
|
126 |
fn = infer,
|
127 |
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|