File size: 735 Bytes
764c376 | 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 | import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
# Load Stable Diffusion model
model_id = "runwayml/stable-diffusion-v1-5"
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32)
pipe = pipe.to(device)
# Define generate function
def generate(prompt):
image = pipe(prompt).images[0]
return image
# Gradio UI
demo = gr.Interface(
fn=generate,
inputs=gr.Textbox(lines=2, placeholder="Type your prompt here..."),
outputs="image",
title="🎨 AI Image Generator",
description="Enter a text prompt and generate AI art for free!",
)
demo.launch()
|