File size: 968 Bytes
9bbba8c
 
 
75ece5a
 
 
 
 
 
9bbba8c
75ece5a
9bbba8c
75ece5a
9bbba8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
"""See https://huggingface.co/fusing/latent-diffusion-text2im-large."""
import gradio as gr
import PIL
from diffusers import DiffusionPipeline

ldm = DiffusionPipeline.from_pretrained("fusing/latent-diffusion-text2im-large")

generator = torch.manual_seed(42)

examples = ["A street sign that reads Huggingface", "A painting of a squirrel eating a burger"]

prompt_ = "A painting of a squirrel eating a burger"

def fn(prompt=prompt_):
  image = ldm(
    [prompt], 
    generator=generator, 
    eta=0.3, 
    guidance_scale=6.0, 
    num_inference_steps=50,
  )
  
  image_processed = image.cpu().permute(0, 2, 3, 1)
  image_processed = image_processed  * 255.
  image_processed = image_processed.numpy().astype(np.uint8)
  image_pil = PIL.Image.fromarray(image_processed[0])
  
  # save image
  # image_pil.save("test.png")
  return image_pil 
  
iface = gr.Interface(
  fn=fn, 
  inputs="text", 
  outputs="image",
  examples=examples,
  live=True,
)
iface.launch()