| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| # Load Stable Diffusion Model | |
| model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v-1-4-original") | |
| # Function to generate images | |
| def generate_image(prompt): | |
| image = model(prompt).images[0] | |
| return image | |
| # Create Gradio interface | |
| iface = gr.Interface(fn=generate_image, | |
| inputs=gr.Textbox(label="Enter a prompt"), | |
| outputs=gr.Image(label="Generated Image"), | |
| live=True) | |
| # Launch the interface | |
| iface.launch() | |