zeroscope / app.py
adminuser742150's picture
Update app.py
248c796 verified
raw
history blame contribute delete
754 Bytes
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
# Load Stable Diffusion pipeline (open source)
pipe = StableDiffusionPipeline.from_pretrained(
"runwayml/stable-diffusion-v1-5",
torch_dtype=torch.float32
)
# Force CPU (free Spaces usually don’t allow GPU)
pipe.to("cpu")
def generate_image(prompt):
image = pipe(prompt, guidance_scale=7.5).images[0]
return image
# Gradio UI for testing
demo = gr.Interface(
fn=generate_image,
inputs=gr.Textbox(label="Enter your prompt"),
outputs=gr.Image(label="Generated Image"),
title="Stable Diffusion Text-to-Image",
description="Enter a prompt and generate an image using Stable Diffusion."
)
if __name__ == "__main__":
demo.launch()