File size: 1,200 Bytes
8e5c6f4
 
 
 
 
 
 
bc7cf63
8e5c6f4
bc7cf63
8e5c6f4
e55ec3c
8e5c6f4
 
 
 
 
 
 
 
bc7cf63
8e5c6f4
 
 
bc7cf63
 
 
8e5c6f4
 
 
d31991f
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
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="Low quality", width=512, height=512):
    # 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((int(width), int(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/)",
    examples=[["A painting of a squirrel eating a burger", "Low quality", 512, 512]]
)

# Launch the interface
iface.launch()