File size: 597 Bytes
8459afb
 
a73aa9b
 
8459afb
c1826f2
 
 
 
 
 
 
a73aa9b
8459afb
 
 
 
c1826f2
8459afb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr

model_id = "runwayml/stable-diffusion-v1-5"

# Detect if GPU is available, else fall back to CPU and float32
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32

pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype)
pipe.to(device)

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

iface = gr.Interface(fn=generate, inputs="text", outputs="image", title="Stable Diffusion Image Generator")
iface.launch()