Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import AutoPipelineForText2Image
|
| 4 |
+
|
| 5 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
| 6 |
+
"stabilityai/sdxl-turbo",
|
| 7 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 8 |
+
variant="fp16" if torch.cuda.is_available() else None,
|
| 9 |
+
)
|
| 10 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
|
| 12 |
+
def generate_image(prompt):
|
| 13 |
+
result = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0)
|
| 14 |
+
return result.images[0] # returns a PIL image
|
| 15 |
+
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
+
inputs=gr.Textbox(label="Prompt"),
|
| 19 |
+
outputs=gr.Image(type="pil", format="jpeg"), # base64 encoded image
|
| 20 |
+
title="Speech2Image - Turbo",
|
| 21 |
+
description="Fast image gen using SDXL Turbo"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
iface.launch()
|
| 26 |
+
|
| 27 |
+
|