Spaces:
Runtime error
Runtime error
File size: 724 Bytes
03824ce 9089f56 03824ce 9089f56 03824ce | 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 | import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
# Load a smaller model if running on CPU
model_id = "CompVis/stable-diffusion-v1-4"
pipeline = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
device = "cuda" if torch.cuda.is_available() else "cpu"
pipeline.to(device)
def generate_image(prompt):
image = pipeline(prompt).images[0]
return image
interface = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Enter your text prompt"),
outputs=gr.Image(type="pil"),
title="Text-to-Image Generator",
description="Enter a prompt, and the AI will generate an image based on it."
)
if __name__ == "__main__":
interface.launch()
|