File size: 1,633 Bytes
7854755
 
 
 
3c7cefd
4bfdae4
7854755
3c7cefd
7854755
912f1cb
ea59a12
2187818
7854755
 
 
 
3c7cefd
 
7854755
 
 
3c7cefd
 
7854755
3c7cefd
 
 
 
7854755
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
from diffusers import LatentDiffusionUncondPipeline
import torch
import PIL.Image
import gradio as gr
import random
import numpy as np

pipeline = LatentDiffusionUncondPipeline.from_pretrained("CompVis/ldm-celebahq-256")

def predict(steps=1, seed=42):
    generator = torch.manual_seed(seed)
    image = pipeline(generator=generator, num_inference_steps=steps)["sample"]
    image_processed = image.cpu().permute(0, 2, 3, 1)
    image_processed = (image_processed + 1.0) * 127.5
    image_processed = image_processed.clamp(0, 255).numpy().astype(np.uint8)
    return PIL.Image.fromarray(image_processed[0])

random_seed = random.randint(0, 2147483647)
gr.Interface(
    predict,
    inputs=[
        gr.inputs.Slider(1, 100, label='Inference Steps', default=5, step=1),
        gr.inputs.Slider(0, 2147483647, label='Seed', default=random_seed, step=1),
    ],
    outputs=gr.Image(shape=[256,256], type="pil", elem_id="output_image"),
    css="#output_image{width: 256px}",
    title="ldm-celebahq-256 - 🧨 diffusers library",
    description="This Spaces contains an unconditional Latent Diffusion process for the <a href=\"https://huggingface.co./CompVis/ldm-celebahq-256\">ldm-celebahq-256</a> face generator model by <a href=\"https://huggingface.co./CompVis\">CompVis</a> using the <a href=\"https://github.com/huggingface/diffusers\">diffusers library</a>. The goal of this demo is to showcase the diffusers library capabilities. If you want the state-of-the-art experience with Latent Diffusion text-to-image check out the <a href=\"https://huggingface.co./spaces/multimodalart/latentdiffusion\">main Spaces</a>.",
).launch()