File size: 2,094 Bytes
9b2295f
 
 
 
 
0670d1c
9b2295f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42b2652
73c920e
be7ed61
 
9b2295f
 
 
 
 
 
 
be7ed61
 
 
9b2295f
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio as gr
from diffusers import DiffusionPipeline
from PIL import Image
import numpy as np

pipeline = DiffusionPipeline.from_pretrained("Qilex/VirtualPetDiffusion2")

def generate_pets(num_to_generate):
    images = pipeline(num_to_generate)["sample"]
    return images

def concatenate_imgs(imgs):
    length = len(imgs)
    if length == 1:
        return imgs[0]
    top = Image.fromarray(np.concatenate([np.array(x) for x in imgs[:2]],axis=1))
    if length == 2:
        return top
    if len(imgs)==3:
        fake = np.zeros([128,128,3],dtype=np.uint8)
        fake[:] = 255
        bottom = Image.fromarray(np.concatenate([imgs[2], fake],axis=1))
    elif len(imgs)==4:
        bottom = Image.fromarray(np.concatenate([imgs[2], imgs[3]],axis=1))
    return Image.fromarray(np.concatenate([top,bottom],axis=0))

def go(num):
    imgs = generate_pets(num)
    grid = concatenate_imgs(imgs)
    print(type(grid))
    return grid

title = "VirtualPet Dream"
description = """
This AI will 'dream' you up a virtual pet.
\nThis is a denoising diffusion model trained in 48 hours for a hackathon, so the images can be pretty wonky.
\nImages are 128x128px.

\nBecause we're running on CPU, it takes 10-15 minutes to generate an image. Quick inference can be run in the <a href="https://colab.research.google.com/drive/19QtPOHv6HCpexyCMGXowX4vyZlF4ZZYN?usp=sharing">colab notebook</a>.
\n <a href="https://github.com/ke7osm/VirtualPet-Dream">Github Repo</a>

"""
article = '''Here's a gallery of some of the better pets:
<div style="display: flex; justify-content:space-evenly">
<img src="https://alexlyman.org/external_images/sample_10.png">
<img src="https://alexlyman.org/external_images/sample_5.png" >
<img src="https://alexlyman.org/external_images/sample_4.png" >
<img src="https://alexlyman.org/external_images/sample_8.png" >
</div>
\n
'''
gr.Interface(
    fn=go,
    inputs= gr.Slider(1, 4, value = 2, step = 1, label="Number of images to generate (more takes longer)"),
    outputs=gr.Image(),
    title=title,
    description=description,
    article = article,
).launch()