File size: 2,756 Bytes
2f23f07
d5f2bf5
 
2f23f07
d63c6cd
d2bf1cc
d5f2bf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f23f07
 
 
 
 
 
 
 
 
 
 
 
2ba277c
 
 
 
 
03888cd
2ba277c
 
1e99cb9
 
 
 
 
 
 
ef99204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f23f07
6d65efa
2f23f07
 
2ba277c
2f23f07
2ba277c
d5f2bf5
e174116
2bc17ff
1e99cb9
c082871
95ec167
2c43fbf
95ec167
2c43fbf
2ba90cf
c082871
8bba89b
95ec167
7654258
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gradio as gr
import torch
from torch import nn
import imageio


class Generator(nn.Module):
    # Refer to the link below for explanations about nc, nz, and ngf
    # https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#inputs
    def __init__(self, nc=4, nz=100, ngf=64):
        super(Generator, self).__init__()
        self.network = nn.Sequential(
            nn.ConvTranspose2d(nz, ngf * 4, 3, 1, 0, bias=False),
            nn.BatchNorm2d(ngf * 4),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf * 4, ngf * 2, 3, 2, 1, bias=False),
            nn.BatchNorm2d(ngf * 2),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 0, bias=False),
            nn.BatchNorm2d(ngf),
            nn.ReLU(True),
            nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=False),
            nn.Tanh(),
        )

    def forward(self, input):
        output = self.network(input)
        return output


def display_gif(file_name):
    images = []

    for frame in range(8):
        frame_name = '_%d' % (frame)
        image_filename = file_name + frame_name + '.png'
        images.append(imageio.imread(image_filename))

    gif_filename = 'avatar.gif'
    return imageio.mimsave(gif_filename, images)


def display_image(file_name):

    image_filename = file_name + '0' + '.png'
    print(image_filename)
    image = imageio.imread(image_filename)
    imageio.imwrite('image.png', image)
    

def path(action, body, hair, top, bottom):

    # body
    if body == "human": body = '0'
    elif body == "alien": body = '1'
    
    # hair
    if hair == "green": hair = '0'
    elif hair == "yellow": hair = '2'
    elif hair == "rose": hair = '4'
    elif hair == "red": hair = '7'
    elif hair == "wine": hair = '8'
    
    # top
    if top == "brown": top = '0'
    elif top == "blue": top = '1'
    elif top == "white": top = '2'
    
    # bottom
    if bottom == "white": bottom = '0'
    elif bottom == "golden": bottom = '1'
    elif bottom == "red": bottom = '2'
    elif bottom == "silver": bottom = '3'
    
    name = './Sprite/frames/domain_1/' + action + '/'
    name = name + 'front' + '_' + str(body) + str(bottom) + str(top) + str(hair) + '_'
    
    gif = display_image(name)
    
    return 'image.png'


gr.Interface(
    path,
    inputs=[
        gr.Radio(choices=["shoot", "slash", "spellcard", "thrust", "walk"], value="shoot"),
        gr.Radio(choices=["human", "alien"], value="human"),
        gr.Radio(choices=["green", "yellow", "rose", "red", "wine"], value="green"),
        gr.Radio(choices=["brown", "blue", "white"], value="brown"),
        gr.Radio(choices=["white", "golden", "red", "silver"], value="white"),
    ],
    outputs="image",
    live=False,
).launch()