Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,18 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
if torch.cuda.is_available():
|
10 |
-
torch.cuda.max_memory_allocated(device=device)
|
11 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
-
pipe.enable_xformers_memory_efficient_attention()
|
13 |
-
pipe = pipe.to(device)
|
14 |
-
else:
|
15 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
-
pipe = pipe.to(device)
|
17 |
|
18 |
MAX_SEED = np.iinfo(np.int32).max
|
19 |
MAX_IMAGE_SIZE = 1024
|
20 |
|
|
|
21 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
22 |
|
23 |
if randomize_seed:
|
@@ -37,12 +32,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 +39,11 @@ 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 |
# Text-to-Image Gradio Template
|
63 |
-
Currently running on {power_device}.
|
64 |
""")
|
65 |
|
66 |
with gr.Row():
|
@@ -131,11 +114,6 @@ with gr.Blocks(css=css) as demo:
|
|
131 |
step=1,
|
132 |
value=2,
|
133 |
)
|
134 |
-
|
135 |
-
gr.Examples(
|
136 |
-
examples = examples,
|
137 |
-
inputs = [prompt]
|
138 |
-
)
|
139 |
|
140 |
run_button.click(
|
141 |
fn = infer,
|
@@ -143,4 +121,4 @@ with gr.Blocks(css=css) as demo:
|
|
143 |
outputs = [result]
|
144 |
)
|
145 |
|
146 |
-
demo.queue().launch()
|
|
|
1 |
+
#Lisence: Apache 2.0
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
import random
|
5 |
from diffusers import DiffusionPipeline
|
6 |
import torch
|
7 |
+
import spaces
|
8 |
|
9 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
10 |
+
pipe = pipe.to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
MAX_SEED = np.iinfo(np.int32).max
|
13 |
MAX_IMAGE_SIZE = 1024
|
14 |
|
15 |
+
@spaces.GPU
|
16 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
17 |
|
18 |
if randomize_seed:
|
|
|
32 |
|
33 |
return image
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
css="""
|
36 |
#col-container {
|
37 |
margin: 0 auto;
|
|
|
39 |
}
|
40 |
"""
|
41 |
|
|
|
|
|
|
|
|
|
|
|
42 |
with gr.Blocks(css=css) as demo:
|
43 |
|
44 |
with gr.Column(elem_id="col-container"):
|
45 |
gr.Markdown(f"""
|
46 |
# Text-to-Image Gradio Template
|
|
|
47 |
""")
|
48 |
|
49 |
with gr.Row():
|
|
|
114 |
step=1,
|
115 |
value=2,
|
116 |
)
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
run_button.click(
|
119 |
fn = infer,
|
|
|
121 |
outputs = [result]
|
122 |
)
|
123 |
|
124 |
+
demo.queue().launch()
|