import gradio as gr import torch from diffusers import StableDiffusionPipeline model_id = "CompVis/stable-diffusion-v1-4" device = "cuda" if torch.cuda.is_available() else "cpu" pipe = StableDiffusionPipeline.from_pretrained( model_id, torch_dtype=torch.float32) pipe = pipe.to(device) def generatorImage(name): prompt = name image = pipe(prompt).images[0] image_name = '-'.join(prompt.split()) + ".png" image.save("./images/" + image_name) return image_name iface = gr.Interface(fn=generatorImage, inputs="text", outputs="text") iface.launch()