File size: 1,351 Bytes
8e5c6f4
 
 
3432643
8e5c6f4
 
 
 
bc7cf63
8e5c6f4
3432643
bc7cf63
8e5c6f4
e55ec3c
8e5c6f4
 
 
3432643
 
af2eaf2
8e5c6f4
 
 
 
bc7cf63
af2eaf2
8e5c6f4
 
63fd899
bc7cf63
 
8e5c6f4
 
 
af2eaf2
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
33
34
35
36
import gradio as gr
from PIL import Image
from diffusers import DiffusionPipeline
import time

# 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)
    start_time = time.time()
    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")
    end_time = time.time()
    elapsed_time = round(end_time - start_time, 2)
    return resized_images[0]

# Define the interface
iface = gr.Interface(
    fn=generate_image,
    inputs=["text", "text", "number", "number"],
    outputs=gr.outputs.Image(type="pil", label="Generated Image"),
    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()