Spaces:
Running
on
Zero
Running
on
Zero
nroggendorff
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import spaces
|
3 |
+
|
4 |
+
import torch
|
5 |
+
from diffusers import StableDiffusionXLPipeline
|
6 |
+
|
7 |
+
pipeline = StableDiffusionXLPipeline.from_pretrained(
|
8 |
+
"stabilityai/stable-diffusion-xl-base-1.0"
|
9 |
+
).to("cuda")
|
10 |
+
|
11 |
+
@spaces.GPU
|
12 |
+
def generate(prompt, negative_prompt, width, height, sample_steps):
|
13 |
+
return pipeline(prompt=prompt, negative_prompt=negative_prompt, width=width, height=height, num_inference_steps=sample_steps).images[0]
|
14 |
+
|
15 |
+
with gr.Blocks() as interface:
|
16 |
+
with gr.Column():
|
17 |
+
with gr.Row():
|
18 |
+
with gr.Column():
|
19 |
+
prompt = gr.Textbox(label="Prompt", info="What do you want?", value="A perfectly red apple, 32k HDR, studio lighting", lines=4, interactive=True)
|
20 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", info="What do you want to exclude from the image?", value="ugly, low quality", lines=4, interactive=True)
|
21 |
+
with gr.Column():
|
22 |
+
generate_button = gr.Button("Generate")
|
23 |
+
output = gr.Image()
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Accordion(label="Advanced Settings", open=False):
|
26 |
+
with gr.Row():
|
27 |
+
with gr.Column():
|
28 |
+
width = gr.Slider(label="Width", info="The width in pixels of the generated image.", value=1024, minimum=128, maximum=4096, step=64, interactive=True)
|
29 |
+
height = gr.Slider(label="Height", info="The height in pixels of the generated image.", value=1024, minimum=128, maximum=4096, step=64, interactive=True)
|
30 |
+
with gr.Column():
|
31 |
+
sampling_steps = gr.Slider(label="Sampling Steps", info="The number of denoising steps.", value=20, minimum=4, maximum=50, step=1, interactive=True)
|
32 |
+
|
33 |
+
generate_button.click(fn=generate, inputs=[prompt, negative_prompt, width, height, sampling_steps], outputs=[output])
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch()
|