File size: 1,085 Bytes
8e5c6f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

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