aliabd HF staff commited on
Commit
c359e7a
·
1 Parent(s): e3e10cf

Upload with huggingface_hub

Browse files
Files changed (6) hide show
  1. README.md +6 -6
  2. app.py +44 -0
  3. rabbit.png +0 -0
  4. requirements.txt +1 -0
  5. screenshot.gif +0 -0
  6. screenshot.png +0 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Color Picker
3
- emoji: 🐨
4
- colorFrom: pink
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 3.3.1
 
8
  app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: color_picker
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.3.1
9
+
10
  app_file: app.py
11
  pinned: false
12
  ---
 
 
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import os
4
+ from PIL import Image, ImageColor
5
+
6
+
7
+ def change_color(icon, color):
8
+
9
+ """
10
+ Function that given an icon in .png format changes its color
11
+ Args:
12
+ icon: Icon whose color needs to be changed.
13
+ color: Chosen color with which to edit the input icon.
14
+ Returns:
15
+ edited_image: Edited icon.
16
+ """
17
+ img = icon.convert("LA")
18
+ img = img.convert("RGBA")
19
+ image_np = np.array(icon)
20
+ _, _, _, alpha = image_np.T
21
+ mask = alpha > 0
22
+ image_np[..., :-1][mask.T] = ImageColor.getcolor(color, "RGB")
23
+ edited_image = Image.fromarray(image_np)
24
+ return edited_image
25
+
26
+
27
+ inputs = [
28
+ gr.Image(label="icon", type="pil", image_mode="RGBA"),
29
+ gr.ColorPicker(label="color"),
30
+ ]
31
+ outputs = gr.Image(label="colored icon")
32
+
33
+ demo = gr.Interface(
34
+ fn=change_color,
35
+ inputs=inputs,
36
+ outputs=outputs,
37
+ examples=[
38
+ [os.path.join(os.path.dirname(__file__), "rabbit.png"), "#ff0000"],
39
+ [os.path.join(os.path.dirname(__file__), "rabbit.png"), "#0000FF"],
40
+ ],
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ demo.launch()
rabbit.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Pillow
screenshot.gif ADDED
screenshot.png ADDED