Spaces:
Runtime error
Runtime error
jaekookang
commited on
Commit
โข
6172439
1
Parent(s):
5b1481d
update callback
Browse files- examples/monroe.jpg +0 -0
- examples/pikachu.jpg +0 -0
- examples/sky.jpg +0 -0
- gradio_pyxelate.py +27 -6
- gradio_queue.db +0 -0
- pixel.png +0 -0
- requirements.txt +1 -0
examples/monroe.jpg
ADDED
examples/pikachu.jpg
ADDED
examples/sky.jpg
ADDED
gradio_pyxelate.py
CHANGED
@@ -7,13 +7,22 @@
|
|
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
|
@@ -36,18 +45,30 @@ DITHER_CHOICES = ['none', 'naive', 'bayer', 'floyd', 'atkinson']
|
|
36 |
|
37 |
|
38 |
def predict(image_obj, sampling_param, color_param, palette_param, dither_param):
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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'),
|
@@ -57,7 +78,7 @@ iface = gr.Interface(
|
|
57 |
outputs=[
|
58 |
gr.outputs.Image(label='๊ฒฐ๊ณผ ์ด๋ฏธ์ง ์
๋๋ค')
|
59 |
],
|
60 |
-
|
61 |
enable_queue=True,
|
62 |
article='<p style="text-align:center">Credits to <a href="https://github.com/sedthh/pyxelate">GitHub</a></p>',
|
63 |
)
|
|
|
7 |
'''
|
8 |
|
9 |
import os
|
|
|
10 |
from glob import glob
|
11 |
+
from loguru import logger
|
12 |
|
13 |
import gradio as gr
|
14 |
from skimage import io as sio
|
15 |
from pyxelate import Pyx, Pal
|
16 |
|
17 |
+
|
18 |
+
# ----------- Settings -----------
|
19 |
+
examples = sorted(glob(os.path.join('examples', '*.jpg')))
|
20 |
+
|
21 |
+
# ----------- Logging -----------
|
22 |
+
logger.add('app.log', mode='a')
|
23 |
+
logger.info('===== APP RESTARTED =====')
|
24 |
+
|
25 |
+
# ----------- Params -----------
|
26 |
DOWNSAMPLE_MIN = 1
|
27 |
DOWNSAMPLE_MAX = 10
|
28 |
COLOR_MIN = 1
|
|
|
45 |
|
46 |
|
47 |
def predict(image_obj, sampling_param, color_param, palette_param, dither_param):
|
48 |
+
img = sio.imread(image_obj.name)
|
49 |
+
logger.info('--- image loaded')
|
50 |
+
|
51 |
+
if palette_param != 'none':
|
52 |
+
color_param = 'none'
|
53 |
+
palette = Pal[palette_param]
|
54 |
+
else:
|
55 |
+
palette = color_param
|
56 |
+
|
57 |
+
pyx = Pyx(factor=sampling_param, palette=palette, dither=dither_param)
|
58 |
+
pyx.fit(img)
|
59 |
+
img_out = pyx.transform(img)
|
60 |
+
logger.info('--- output generated')
|
61 |
+
return img_out
|
62 |
|
63 |
iface = gr.Interface(
|
64 |
predict,
|
65 |
title='์ด๋ฏธ์ง๋ฅผ ํฝ์
ํ ์ํค๋ ๋ฐ๋ชจ์
๋๋ค.',
|
66 |
description='์ด๋ฏธ์ง๊ฐ ์ฃผ์ด์ก์ ๋ ์ด๋ฏธ์ง๋ฅผ ์ค์ผ์ผ๋งํ๊ณ ์๊ฐ์ ๋ฐ๊พธ์ด ํฝ์
ํ ์ํฌ ์ ์์ต๋๋ค.',
|
67 |
inputs=[
|
68 |
+
gr.inputs.Image(label='์ธํ ์ด๋ฏธ์ง๋ฅผ ์ค๋นํด์ฃผ์ธ์', type='file'),
|
69 |
gr.inputs.Slider(label='๋ค์ด์ํํ ํฌ๊ธฐ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์ (ํด์๋ก ํฝ์
ํฌ๊ธฐ๊ฐ ์ปค์ง = ์ ํ์ง)',
|
70 |
minimum=DOWNSAMPLE_MIN, maximum=DOWNSAMPLE_MAX, step=1, default=5),
|
71 |
+
gr.inputs.Slider(label='์ฌ์ฉํ ์๊น์ ๊ฐ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์ (์ ํ ์ ์๋ ํ๋ ํธ ์ค์ ์ "none"์ผ๋ก ํด์ฃผ์ธ์)',
|
72 |
minimum=DOWNSAMPLE_MIN, maximum=DOWNSAMPLE_MAX, step=1, default=5),
|
73 |
gr.inputs.Dropdown(label='์๊น ํ๋ ํธ๋ฅผ ์ ํํ์ธ์ (์ ํ ์ ์์ ์๊น ๊ฐ์๋ ๋ฌด์๋ฉ๋๋ค)',
|
74 |
choices=PALETTE_CHOICES, default='none', type='value'),
|
|
|
78 |
outputs=[
|
79 |
gr.outputs.Image(label='๊ฒฐ๊ณผ ์ด๋ฏธ์ง ์
๋๋ค')
|
80 |
],
|
81 |
+
examples=examples,
|
82 |
enable_queue=True,
|
83 |
article='<p style="text-align:center">Credits to <a href="https://github.com/sedthh/pyxelate">GitHub</a></p>',
|
84 |
)
|
gradio_queue.db
CHANGED
Binary files a/gradio_queue.db and b/gradio_queue.db differ
|
|
pixel.png
DELETED
Binary file (3.28 kB)
|
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ gradio==2.4.6
|
|
2 |
scikit-learn>=0.24.1
|
3 |
scikit-image>=0.18.1
|
4 |
numba>=0.53.1
|
|
|
5 |
git+https://github.com/sedthh/pyxelate.git
|
|
|
2 |
scikit-learn>=0.24.1
|
3 |
scikit-image>=0.18.1
|
4 |
numba>=0.53.1
|
5 |
+
loguru==0.5.3
|
6 |
git+https://github.com/sedthh/pyxelate.git
|