File size: 761 Bytes
c1a128a
65bcf7e
c1a128a
 
c1fc394
65bcf7e
 
c1fc394
97cf833
c1a128a
c1fc394
 
65bcf7e
c1fc394
97cf833
 
 
c1a128a
c1fc394
65bcf7e
 
 
 
c1fc394
 
65bcf7e
c1a128a
c1fc394
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import gradio as gr
from diffusers import AutoPipelineForText2Image
import torch

# Load the sd-turbo model
pipe = AutoPipelineForText2Image.from_pretrained(
    "stabilityai/sd-turbo",
    torch_dtype=torch.float32  # Use float32 for CPU (or float16 for GPU)
).to("cuda" if torch.cuda.is_available() else "cpu")

# Warm-up to reduce first-time delay (optional)
pipe("a test prompt")

# Gradio interface (simple)
def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Use only launch() here (no enable_queue)
iface = gr.Interface(
    fn=generate_image,
    inputs="text",
    outputs="image",
    title="Text-to-Image with SD-Turbo",
    description="Fast free text-to-image generation using stabilityai/sd-turbo"
)

iface.launch()