File size: 1,225 Bytes
b4fbd36
 
 
 
 
 
bfafadf
bd2744f
b4fbd36
85f7abe
b4fbd36
 
 
 
 
 
 
 
ec97849
 
 
b4fbd36
 
 
 
 
 
 
77631bb
 
b4fbd36
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
import gradio as gr
from skimage import io
from pyxelate import Pyx, Pal

def pixel(image):
    image = io.imread(image.name)  
    downsample_by = 14  # new image will be 1/14th of the original in size
    palette = 7  # find 7 colors
    # 1) Instantiate Pyx transformer
    pyx = Pyx(factor=downsample_by, palette=palette,depth=2,upscale = 14)
    # 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 = "Pyxelate"
description = "Gradio demo for Pyxelate: converts images to 8-bit pixel art. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
article = "<p style='text-align: center'><a href='https://github.com/sedthh/pyxelate' target='_blank'>Github Repo</a></p>"

gr.Interface(
    pixel, 
    [gr.inputs.Image(type="file", label="Input")], 
    gr.outputs.Image(type="file", label="Output"),
    title=title,
    description=description,
    article=article,
    enable_queue=True
    ).launch(debug=True)