import gradio as gr from PIL import Image from diffusers import DiffusionPipeline # Load model and scheduler ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256") def generate_image(prompt, negative_prompt, width, height): # Run pipeline in inference (sample random noise and denoise) images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images # Resize image to desired width and height resized_images = [image.resize((width, height)) for image in images] # Save images for idx, image in enumerate(resized_images): image.save(f"squirrel-{idx}.png") return "Images generated successfully!" # Define the interface iface = gr.Interface( fn=generate_image, inputs=["text", "text", "number", "number"], outputs="text", layout="vertical", title="Image Generation", description="Generate images based on prompts.", article="For more information, visit the documentation: [link](https://docs.gradio.app/)", ) # Launch the interface iface.launch()