File size: 2,379 Bytes
a97d770
 
 
f1f0d48
 
c215104
a97d770
 
f1f0d48
 
 
 
 
a97d770
 
 
 
 
 
 
 
 
 
 
b533b98
8ce02d1
3e99869
 
4c257a6
996477d
 
b533b98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
996477d
 
 
b533b98
 
 
996477d
 
 
 
b533b98
996477d
2376fb4
b533b98
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
import gradio as gr
from skimage import io
from pyxelate import Pyx, Pal
from uuid import uuid1
from PIL import Image
import os

def pixel(image,downsample,palette,depth,upscale):
    #image = io.imread(image.name)
    path = "{}.png".format(uuid1())
    Image.fromarray(image).save(path)
    image = io.imread(path)
    os.remove(path)
    downsample_by = int(downsample)  # new image will be 1/14th of the original in size
    palette = int(palette)  # find 7 colors
    # 1) Instantiate Pyx transformer
    pyx = Pyx(factor=downsample_by, palette=palette,depth=int(depth),upscale = int(upscale))
    # 2) fit an image, allow Pyxelate to learn the color palette
    pyx.fit(image)
    # 3) transform image to pixel art using the learned color palette
    new_image = pyx.transform(image)
    # save new image with 'skimage.io.imsave()'
    io.imsave("pixel.png", new_image)
    return "pixel.png"

title = "Pixelar Imagen"
description = ""
article = ""

with gr.Blocks() as demo:
    gr.HTML("<h1><center> 🔥 Pixelar Imagen </center></h1>")
    with gr.Row():
        with gr.Column():
            input_image = gr.Image(label="Input", height = 512 + 128)
            with gr.Row():
                gr.HTML('''
                        <h1>pyxelate⚡</h1>
                        <container>
                            <a href="https://github.com/sedthh/pyxelate" target="_blank">
                                <button id="website_button" class="external-link">Website</button>
                            </a>
                        </container>
                    ''')
        with gr.Column():
            with gr.Row():
                downsample = gr.Number(value=4, label="downsample by")
                palette = gr.Number(value=7, label="palette")
                depth = gr.Number(value=1, label="depth")
                upscale = gr.Number(value=4, label="upscale")
                run_button = gr.Button("run")
            output_image = gr.Image(label="Output")

    gr.Examples(
        [
            ['mona.jpeg',14,7,1, 4],
            ['artistic sky in space.jpg',7,7,1, 4],
            ['Paint me a picture of the Great Wall of China in t.jpg',4, 6, 1, 4],
        ],
        inputs = [input_image, downsample, palette, depth, upscale]
    )

    run_button.click(pixel, [input_image, downsample, palette, depth, upscale], output_image)


demo.launch()