Spaces:
Sleeping
Sleeping
| 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() | |