Spaces:
Runtime error
Runtime error
cpu_gpu_mps
Browse files
app.py
CHANGED
@@ -1,12 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import torch
|
|
|
4 |
from diffusers import DiffusionPipeline
|
5 |
from diffusers import EulerDiscreteScheduler
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config, timestep_spacing="trailing")
|
11 |
|
12 |
|
@@ -17,28 +33,22 @@ with gr.Blocks() as interface:
|
|
17 |
with gr.Column():
|
18 |
with gr.Row():
|
19 |
with gr.Column():
|
20 |
-
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="girl sitting on a small hill looking at night sky, back view, distant exploding moon
|
21 |
with gr.Column():
|
22 |
generate_button = gr.Button("Generate")
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=5, minimum=3, maximum=10, step=1, interactive=True)
|
32 |
-
|
33 |
with gr.Row():
|
34 |
-
|
35 |
-
Based on: Stable Diffusion XL Image Generation interface built by Noa Roggendorff.
|
36 |
-
|
37 |
-
You can enter a prompt and negative prompt, adjust the image size and sampling steps, and click the "Generate" button to generate an image.
|
38 |
-
"""
|
39 |
-
gr.Markdown(about_text)
|
40 |
|
41 |
generate_button.click(fn=generate, inputs=[prompt, width, height, sampling_steps], outputs=[output])
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
interface.launch()
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import torch
|
3 |
+
|
4 |
from diffusers import DiffusionPipeline
|
5 |
from diffusers import EulerDiscreteScheduler
|
6 |
|
7 |
+
device = "cpu"
|
8 |
+
dtype = torch.float32
|
9 |
+
if torch.cuda.is_available():
|
10 |
+
device = "cuda"
|
11 |
+
dtype = torch.float16
|
12 |
+
|
13 |
+
# check if MPS is available OSX only M1/M2/M3 chips
|
14 |
+
mps_available = hasattr(torch.backends, "mps") and torch.backends.mps.is_available()
|
15 |
+
if mps_available:
|
16 |
+
device = "mps"
|
17 |
+
dtype = torch.float16
|
18 |
+
#print(f"device: {device}, dtype: {dtype}")
|
19 |
|
20 |
+
|
21 |
+
pipeline = DiffusionPipeline.from_pretrained("recoilme/ColorfulXL-Lightning",
|
22 |
+
variant="fp16",
|
23 |
+
torch_dtype=dtype,
|
24 |
+
use_safetensors=True)
|
25 |
+
pipeline.to(device)
|
26 |
pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config, timestep_spacing="trailing")
|
27 |
|
28 |
|
|
|
33 |
with gr.Column():
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
36 |
+
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="girl sitting on a small hill looking at night sky, back view, distant exploding moon", lines=4, interactive=True)
|
37 |
with gr.Column():
|
38 |
generate_button = gr.Button("Generate")
|
39 |
+
with gr.Accordion(label="Advanced Settings", open=False):
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column():
|
42 |
+
width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=576, minimum=512, maximum=1280, step=64, interactive=True)
|
43 |
+
height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=832, minimum=512, maximum=1280, step=64, interactive=True)
|
44 |
+
with gr.Column():
|
45 |
+
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=5, minimum=3, maximum=10, step=1, interactive=True)
|
46 |
+
|
|
|
|
|
47 |
with gr.Row():
|
48 |
+
output = gr.Image()
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
generate_button.click(fn=generate, inputs=[prompt, width, height, sampling_steps], outputs=[output])
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
interface.launch()
|
54 |
+
|