CoolFace
Apppublic

Kvikontent/kandinsky2.2

sourceHugging Faceopenrailupdated 3y agoView on Hugging Face
3likes
app.py36 linesDownload Raw Back to root
1import gradio as gr2from PIL import Image3from diffusers import DiffusionPipeline4import time5 6# Load model and scheduler7ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")8 9def generate_image(prompt, negative_prompt="Low quality", width=512, height=512):10    # Run pipeline in inference (sample random noise and denoise)11    start_time = time.time()12    images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images13    # Resize image to desired width and height14    resized_images = [image.resize((int(width), int(height))) for image in images]15    # Save images16    for idx, image in enumerate(resized_images):17        image.save(f"squirrel-{idx}.png")18    end_time = time.time()19    elapsed_time = round(end_time - start_time, 2)20    return resized_images[0]21 22# Define the interface23iface = gr.Interface(24    fn=generate_image,25    inputs=["text", "text", "number", "number"],26    outputs=gr.outputs.Image(type="pil", label="Generated Image"),27    layout="vertical",28    title="Image Generation",29    description="Generate images based on prompts",30    article="For more information, visit the documentation: [link](https://docs.gradio.app/)",31    examples=[["A painting of a squirrel eating a burger", "Low quality", 512, 512]]32)33 34# Launch the interface35iface.launch()36