|
|
import torch |
|
|
from diffusers import StableDiffusionPipeline |
|
|
import gradio as gr |
|
|
|
|
|
model_id = "runwayml/stable-diffusion-v1-5" |
|
|
|
|
|
|
|
|
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() |