svjack's picture
Update app.py
a85aa1e
raw
history blame
2.55 kB
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.Column():
input_image = gr.Image(label="Input")
downsample = gr.Number(default=4, label="downsample by")
palette = gr.Number(default=7, label="palette")
depth = gr.Number(default=1, label="depth")
upscale = gr.Number(default=4, label="upscale")
with gr.Column():
output_image = gr.Image(label="Output")
gr.Examples(
[
['mona.jpeg',14,7,1, 4]
],
inputs = [input_image, downsample, palette, depth, upscale]
)
demo.launch()
'''
gr.Interface(
pixel,
[gr.Image(label="Input"),
gr.Number(default=4, label="downsample by"),
gr.Number(default=7, label="palette"),
gr.Number(default=1, label="depth"),
gr.Number(default=14, label="upscale")
],
gr.Image(label="Output"),
title=title,
description=description,
article=article,
examples=[['mona.jpeg',14,7,1,14]],
css="footer {visibility: hidden}"
).launch(enable_queue=True)
gr.Interface(
pixel,
[gr.inputs.Image(type="file", label="Input", shape=(512,512)),gr.inputs.Number(default=14, label="downsample by"),gr.inputs.Number(default=7, label="palette"),gr.inputs.Number(default=1, label="depth"),gr.inputs.Number(default=14, label="upscale")
],
gr.outputs.Image(type="file", label="Output"),
title=title,
description=description,
article=article,
examples=[['mona.jpeg',14,7,1,14]],
css="footer {visibility: hidden}"
).launch(enable_queue=True)
'''