Spaces:
Runtime error
Runtime error
jaekookang
commited on
Commit
·
5a74a7f
1
Parent(s):
bd5fc6d
first upload
Browse files- .gitignore +2 -0
- README.md +9 -26
- examples/car.jpg +0 -0
- gradio_pyxelate.py +65 -0
- gradio_queue.db +0 -0
- pixel.png +0 -0
- requirements.txt +4 -0
- test.py +21 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
*.log
|
README.md
CHANGED
@@ -4,34 +4,17 @@ emoji: 👀
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
-
app_file:
|
8 |
pinned: false
|
9 |
---
|
10 |
|
11 |
-
#
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
`colorFrom`: _string_
|
20 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
21 |
-
|
22 |
-
`colorTo`: _string_
|
23 |
-
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
24 |
-
|
25 |
-
`sdk`: _string_
|
26 |
-
Can be either `gradio` or `streamlit`
|
27 |
-
|
28 |
-
`sdk_version` : _string_
|
29 |
-
Only applicable for `streamlit` SDK.
|
30 |
-
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
31 |
-
|
32 |
-
`app_file`: _string_
|
33 |
-
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
34 |
-
Path is relative to the root of the repository.
|
35 |
-
|
36 |
-
`pinned`: _boolean_
|
37 |
-
Whether the Space stays on top of your list.
|
|
|
4 |
colorFrom: indigo
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
+
app_file: gradio_pyxelate.py
|
8 |
pinned: false
|
9 |
---
|
10 |
|
11 |
+
# Pixelate Demo (in Korean)
|
12 |
|
13 |
+
- 그림을 픽셀화 시켜주는 데모 (demo for the personal testing of pyxelate)
|
14 |
+
- 호스팅: https://huggingface.co/spaces/jkang/demo-image-pyxelate (HuggingFace + Spaces)
|
15 |
+
- 참조:
|
16 |
+
- Code: https://github.com/sedthh/pyxelate (where all credits go to)
|
17 |
+
- Original demo: https://huggingface.co/spaces/akhaliq/Pyxelate/blob/main/app.py
|
18 |
|
19 |
+
---
|
20 |
+
- 2021-12-16 first created
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
examples/car.jpg
ADDED
![]() |
gradio_pyxelate.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'''Pyxelate Demo
|
2 |
+
|
3 |
+
- Based on https://huggingface.co/spaces/akhaliq/Pyxelate
|
4 |
+
- Credits to akhaliq
|
5 |
+
|
6 |
+
2021-12-16 first created for testing
|
7 |
+
'''
|
8 |
+
|
9 |
+
import os
|
10 |
+
import io
|
11 |
+
from glob import glob
|
12 |
+
|
13 |
+
import gradio as gr
|
14 |
+
from skimage import io as sio
|
15 |
+
from pyxelate import Pyx, Pal
|
16 |
+
|
17 |
+
DOWNSAMPLE_MIN = 1
|
18 |
+
DOWNSAMPLE_MAX = 10
|
19 |
+
COLOR_MIN = 1
|
20 |
+
COLOR_MAX = 20
|
21 |
+
PALETTE_CHOICES = [
|
22 |
+
'none', # if not chosen
|
23 |
+
'TELETEXT', 'BBC_MICRO', 'CGA_MODE4_PAL1', 'CGA_MODE5_PAL1',
|
24 |
+
'CGA_MODE4_PAL2', 'ZX_SPECTRUM', 'APPLE_II_LO', 'APPLE_II_HI',
|
25 |
+
'COMMODORE_64', 'GAMEBOY_COMBO_UP', 'GAMEBOY_COMBO_DOWN', 'GAMEBOY_COMBO_LEFT',
|
26 |
+
'GAMEBOY_COMBO_RIGHT', 'GAMEBOY_A_UP', 'GAMEBOY_A_DOWN', 'GAMEBOY_A_LEFT',
|
27 |
+
'GAMEBOY_A_RIGHT', 'GAMEBOY_B_UP', 'GAMEBOY_B_DOWN', 'GAMEBOY_B_LEFT',
|
28 |
+
'GAMEBOY_B_RIGHT', 'GAMEBOY_ORIGINAL', 'GAMEBOY_POCKET', 'GAMEBOY_VIRTUALBOY',
|
29 |
+
'MICROSOFT_WINDOWS_16', 'MICROSOFT_WINDOWS_20', 'MICROSOFT_WINDOWS_PAINT',
|
30 |
+
'PICO_8', 'MSX', 'MONO_OBRADINN_IBM', 'MONO_OBRADINN_MAC', 'MONO_BJG', 'MONO_BW',
|
31 |
+
'MONO_PHOSPHOR_AMBER', 'MONO_PHOSPHOR_LTAMBER', 'MONO_PHOSPHOR_GREEN1',
|
32 |
+
'MONO_PHOSPHOR_GREEN2', 'MONO_PHOSPHOR_GREEN3', 'MONO_PHOSPHOR_APPLE', 'APPLE_II_MONO',
|
33 |
+
'MONO_PHOSPHOR_APPLEC', 'APPLE_II_MONOC'
|
34 |
+
]
|
35 |
+
DITHER_CHOICES = ['none', 'naive', 'bayer', 'floyd', 'atkinson']
|
36 |
+
|
37 |
+
|
38 |
+
def predict(image_obj, sampling_param, color_param, palette_param, dither_param):
|
39 |
+
|
40 |
+
return None
|
41 |
+
|
42 |
+
iface = gr.Interface(
|
43 |
+
predict,
|
44 |
+
title='이미지를 픽셀화 시키는 데모입니다.',
|
45 |
+
description='이미지가 주어졌을 때 이미지를 스케일링하고 색감을 바꾸어 픽셀화 시킬 수 있습니다.',
|
46 |
+
inputs=[
|
47 |
+
gr.inputs.Image(label='인풋 이미지를 준비해주세요'),
|
48 |
+
gr.inputs.Slider(label='다운샘플할 크기를 입력해주세요 (클수록 픽셀크기가 커짐 = 저화질)',
|
49 |
+
minimum=DOWNSAMPLE_MIN, maximum=DOWNSAMPLE_MAX, step=1, default=5),
|
50 |
+
gr.inputs.Slider(label='사용할 색깔의 개수를 입력해주세요 (선택 시 아래 팔레트 설정은 무시됩니다)',
|
51 |
+
minimum=DOWNSAMPLE_MIN, maximum=DOWNSAMPLE_MAX, step=1, default=5),
|
52 |
+
gr.inputs.Dropdown(label='색깔 팔레트를 선택하세요 (선택 시 위의 색깔 개수는 무시됩니다)',
|
53 |
+
choices=PALETTE_CHOICES, default='none', type='value'),
|
54 |
+
gr.inputs.Dropdown(label='결과 이미지의 부드러움 정도를 나타냅니다 ("dithering")',
|
55 |
+
choices=DITHER_CHOICES, default='none', type='value'),
|
56 |
+
],
|
57 |
+
outputs=[
|
58 |
+
gr.outputs.Image(label='결과 이미지 입니다')
|
59 |
+
],
|
60 |
+
# examples=examples,
|
61 |
+
enable_queue=True,
|
62 |
+
article='<p style="text-align:center">Credits to <a href="https://github.com/sedthh/pyxelate">GitHub</a></p>',
|
63 |
+
)
|
64 |
+
|
65 |
+
iface.launch(debug=True)
|
gradio_queue.db
ADDED
Binary file (16.4 kB). View file
|
|
pixel.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==2.4.6
|
2 |
+
scikit_image==0.19.0
|
3 |
+
pyxelate==2.0.4
|
4 |
+
skimage==0.0
|
test.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from skimage import io
|
2 |
+
from pyxelate import Pyx, Pal
|
3 |
+
|
4 |
+
# load image with 'skimage.io.imread()'
|
5 |
+
image = io.imread("examples/car.jpg")
|
6 |
+
|
7 |
+
downsample_by = 1 # new image will be 1/14th of the original in size
|
8 |
+
palette = 7 # find 7 colors
|
9 |
+
palette = Pal.APPLE_II_HI # = 42
|
10 |
+
|
11 |
+
# 1) Instantiate Pyx transformer
|
12 |
+
pyx = Pyx(factor=downsample_by, palette=palette)
|
13 |
+
|
14 |
+
# 2) fit an image, allow Pyxelate to learn the color palette
|
15 |
+
pyx.fit(image)
|
16 |
+
|
17 |
+
# 3) transform image to pixel art using the learned color palette
|
18 |
+
new_image = pyx.transform(image)
|
19 |
+
|
20 |
+
# save new image with 'skimage.io.imsave()'
|
21 |
+
io.imsave("pixel.png", new_image)
|