File size: 1,148 Bytes
9a23b93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
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()