Spaces:
Runtime error

README / app.py
mdesamia's picture
Create app.py
764c376 verified
Raw History Blame Contribute Delete
735 Bytes
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()