Ahsen Khaliq
commited on
Commit
•
b4fbd36
1
Parent(s):
77109c0
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from skimage import io
|
3 |
+
from pyxelate import Pyx, Pal
|
4 |
+
|
5 |
+
def pixel(image):
|
6 |
+
image = io.imread(image.name)
|
7 |
+
downsample_by = 14 # new image will be 1/14th of the original in size
|
8 |
+
palette = 7 # find 7 colors
|
9 |
+
# 1) Instantiate Pyx transformer
|
10 |
+
pyx = Pyx(factor=downsample_by, palette=palette)
|
11 |
+
# 2) fit an image, allow Pyxelate to learn the color palette
|
12 |
+
pyx.fit(image)
|
13 |
+
# 3) transform image to pixel art using the learned color palette
|
14 |
+
new_image = pyx.transform(image)
|
15 |
+
# save new image with 'skimage.io.imsave()'
|
16 |
+
io.imsave("pixel.png", new_image)
|
17 |
+
return "pixel.png"
|
18 |
+
|
19 |
+
title = "Anime2Sketch"
|
20 |
+
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."
|
21 |
+
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>"
|
22 |
+
|
23 |
+
gr.Interface(
|
24 |
+
pixel,
|
25 |
+
[gr.inputs.Image(type="file", label="Input")],
|
26 |
+
gr.outputs.Image(type="file", label="Output"),
|
27 |
+
title=title,
|
28 |
+
description=description,
|
29 |
+
article=article
|
30 |
+
).launch(debug=True)
|