jaekookang commited on
Commit
5a74a7f
โ€ข
1 Parent(s): bd5fc6d

first upload

Browse files
Files changed (8) hide show
  1. .gitignore +2 -0
  2. README.md +9 -26
  3. examples/car.jpg +0 -0
  4. gradio_pyxelate.py +65 -0
  5. gradio_queue.db +0 -0
  6. pixel.png +0 -0
  7. requirements.txt +4 -0
  8. 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: app.py
8
  pinned: false
9
  ---
10
 
11
- # Configuration
12
 
13
- `title`: _string_
14
- Display title for the Space
 
 
 
15
 
16
- `emoji`: _string_
17
- Space emoji (emoji-only character allowed)
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)