Pyxelate / app.py
Ahsen Khaliq
Update app.py
d10880f
raw
history blame
No virus
1.25 kB
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 = 5 # find 7 colors
# 1) Instantiate Pyx transformer
pyx = Pyx(factor=downsample_by, palette=palette)
# 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 = "Anime2Sketch"
description = "demo for Anime2Sketch. 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://arxiv.org/abs/2104.05703'>Adversarial Open Domain Adaption for Sketch-to-Photo Synthesis</a> | <a href='https://github.com/Mukosame/Anime2Sketch'>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
).launch(debug=True)