| 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() |