Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
+
from diffusers import AutoPipelineForText2Image
|
| 5 |
+
|
| 6 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
| 7 |
+
"stabilityai/sdxl-turbo",
|
| 8 |
+
torch_dtype=torch.float16,
|
| 9 |
+
variant="fp16"
|
| 10 |
+
).to("cpu")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Disable safety checker (optional, to avoid empty images)
|
| 14 |
+
pipe.safety_checker = lambda images, **kwargs: (images, False)
|
| 15 |
+
|
| 16 |
+
# Image generation function
|
| 17 |
+
def generate_image(prompt):
|
| 18 |
+
result = pipe(prompt)
|
| 19 |
+
return result.images[0]
|
| 20 |
+
|
| 21 |
+
# Gradio UI
|
| 22 |
+
iface = gr.Interface(
|
| 23 |
+
fn=generate_image,
|
| 24 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
| 25 |
+
outputs=gr.Image(label="Generated Image"),
|
| 26 |
+
title="Speech2Image 💖",
|
| 27 |
+
description="Enter a sentence and get a beautiful image ✨"
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
iface.launch()
|