Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import DiffusionPipeline, LCMScheduler
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0").to("cuda")
|
| 6 |
+
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
| 7 |
+
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl")
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def generate_images(prompt, batch_size):
|
| 11 |
+
images = []
|
| 12 |
+
for _ in range(batch_size):
|
| 13 |
+
results = pipe(
|
| 14 |
+
prompt=prompt,
|
| 15 |
+
num_inference_steps=4,
|
| 16 |
+
guidance_scale=1.4,
|
| 17 |
+
)
|
| 18 |
+
images.append(results.images[0])
|
| 19 |
+
return images
|
| 20 |
+
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=generate_images,
|
| 23 |
+
inputs=[
|
| 24 |
+
gr.Textbox(label="Prompt"),
|
| 25 |
+
gr.Slider(label="Batch Size", minimum=1, maximum=12, step=1, value=1)
|
| 26 |
+
],
|
| 27 |
+
outputs=gr.Gallery(label="Generated Images"),
|
| 28 |
+
title="SuperFast SDXL Generation."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|