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)
|