aliabd HF Staff commited on
Commit
14fea91
·
1 Parent(s): f3f6c8b

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +6 -7
  2. requirements.txt +2 -0
  3. run.py +63 -0
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Color Generator Main
3
- emoji: 🐠
4
- colorFrom: pink
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.6
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_generator_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.6
9
+ app_file: run.py
10
  pinned: false
11
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ opencv-python
2
+ numpyhttps://gradio-main-build.s3.amazonaws.com/c3bec6153737855510542e8154391f328ac72606/gradio-3.6-py3-none-any.whl
run.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import random
5
+
6
+
7
+ # Convert decimal color to hexadecimal color
8
+ def RGB_to_Hex(rgb):
9
+ color = "#"
10
+ for i in rgb:
11
+ num = int(i)
12
+ color += str(hex(num))[-2:].replace("x", "0").upper()
13
+ return color
14
+
15
+
16
+ # Randomly generate light or dark colors
17
+ def random_color(is_light=True):
18
+ return (
19
+ random.randint(0, 127) + int(is_light) * 128,
20
+ random.randint(0, 127) + int(is_light) * 128,
21
+ random.randint(0, 127) + int(is_light) * 128,
22
+ )
23
+
24
+
25
+ def switch_color(color_style):
26
+ if color_style == "light":
27
+ is_light = True
28
+ elif color_style == "dark":
29
+ is_light = False
30
+ back_color_ = random_color(is_light) # Randomly generate colors
31
+ back_color = RGB_to_Hex(back_color_) # Convert to hexadecimal
32
+
33
+ # Draw color pictures.
34
+ w, h = 50, 50
35
+ img = np.zeros((h, w, 3), np.uint8)
36
+ cv2.rectangle(img, (0, 0), (w, h), back_color_, thickness=-1)
37
+
38
+ return back_color, back_color, img
39
+
40
+
41
+ inputs = [gr.Radio(["light", "dark"], value="light")]
42
+
43
+ outputs = [
44
+ gr.ColorPicker(label="color"),
45
+ gr.Textbox(label="hexadecimal color"),
46
+ gr.Image(type="numpy", label="color picture"),
47
+ ]
48
+
49
+ title = "Color Generator"
50
+ description = (
51
+ "Click the Submit button, and a dark or light color will be randomly generated."
52
+ )
53
+
54
+ demo = gr.Interface(
55
+ fn=switch_color,
56
+ inputs=inputs,
57
+ outputs=outputs,
58
+ title=title,
59
+ description=description,
60
+ )
61
+
62
+ if __name__ == "__main__":
63
+ demo.launch()