Spaces:
Sleeping
Sleeping
File size: 754 Bytes
e1edf19 6f16ef1 1447e65 9d3c925 248c796 95120dc 248c796 95120dc 9d3c925 248c796 1447e65 248c796 1447e65 9d3c925 248c796 |
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 28 29 30 31 |
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()
|