jaekookang commited on
Commit
6172439
โ€ข
1 Parent(s): 5b1481d

update callback

Browse files
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
- 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'),
@@ -57,7 +78,7 @@ iface = gr.Interface(
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
  )
 
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