File size: 654 Bytes
4179b9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr

# Load Stable Diffusion model from Hugging Face
model_id = "runwayml/stable-diffusion-v1-5"  # Change to "stabilityai/stable-diffusion-xl-base-1.0" for SDXL
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.to("cuda")  # Use "cpu" if no GPU is available

def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Create Gradio UI
demo = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(label="Enter your prompt"),
    outputs=gr.Image(),
    title="Stable Diffusion Image Generator"
)

demo.launch()