Spaces:
Sleeping
Sleeping
import gradio as gr | |
import torch | |
from diffusers import StableDiffusionPipeline | |
# Load model (you can replace this with your own if needed) | |
pipe = StableDiffusionPipeline.from_pretrained( | |
"runwayml/stable-diffusion-v1-5", | |
torch_dtype=torch.float16 | |
).to("cuda") | |
def generate_image(prompt, width, height, guidance_scale): | |
image = pipe(prompt, width=width, height=height, guidance_scale=guidance_scale).images[0] | |
return image | |
with gr.Blocks() as demo: | |
gr.Markdown("## 🎨 AI Image Generator - Powered by Stable Diffusion") | |
with gr.Row(): | |
prompt = gr.Textbox(label="Enter your prompt", placeholder="e.g. A futuristic city at sunset") | |
with gr.Row(): | |
width = gr.Slider(256, 1024, value=512, step=64, label="Width") | |
height = gr.Slider(256, 1024, value=512, step=64, label="Height") | |
guidance_scale = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale") | |
generate_btn = gr.Button("Generate Image") | |
output = gr.Image(label="Generated Image") | |
generate_btn.click(fn=generate_image, inputs=[prompt, width, height, guidance_scale], outputs=output) | |
demo.launch() | |