File size: 519 Bytes
9a1cdb3
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch

# Load Stable Diffusion model from Hugging Face
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v-1-4-original", torch_dtype=torch.float32)
pipe = pipe.to("cuda")  # If you have a GPU available, use it. Otherwise, change to "cpu"

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

# Set up the Gradio interface
gr.Interface(fn=generate_image, inputs="text", outputs="image").launch()