liewchooichin commited on
Commit
6b9866e
1 Parent(s): de034d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -33
app.py CHANGED
@@ -5,25 +5,46 @@ import time
5
 
6
  def get_random_color(rng):
7
  for i in range(1):
 
8
  color1 = rng.integers(low=0, high=255, size=(1, 1, 3))
9
  color2 = rng.integers(low=0, high=255, size=(1, 1, 3))
10
  color3 = rng.integers(low=0, high=255, size=(1, 1, 3))
11
  color4 = rng.integers(low=0, high=255, size=(1, 1, 3))
12
- block1 = np.concatenate((color1, color2), axis=0)
13
- #print(f"Shape of block: {block1.shape}")
14
- block2 = np.concatenate((color3, color4), axis=0)
15
- #print(f"Shape of block: {block2.shape}")
16
- block3 = np.concatenate((block1, block2), axis=1)
17
- #print(f"Shape of block: {block3.shape}")
18
- return color1, color2, color3, color4, block3
19
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  def color_me(num1):
22
  # Make some random color
23
  rng1 = np.random.default_rng(seed=num1)
24
  return get_random_color(rng1)
25
 
26
-
27
  def auto_color_me():
28
  # Make some random color
29
  # Get time to be the seed
@@ -31,11 +52,12 @@ def auto_color_me():
31
  rng1 = np.random.default_rng(seed=seed)
32
  return get_random_color(rng1)
33
 
 
34
  # Title of the blocks
35
  with gr.Blocks() as demo1:
36
  image_width = 64
37
  image_height = 64
38
-
39
  with gr.Row():
40
  gr.Markdown(
41
  """
@@ -53,39 +75,88 @@ with gr.Blocks() as demo1:
53
  corner to the image.
54
  """
55
  )
56
-
57
  with gr.Row():
58
  num1 = gr.Slider(value=10, minimum=0, maximum=1000, step=1,
59
- label="Value", info="Slide the bar or enter a value to change the color.")
60
-
61
  with gr.Row():
62
- btn_auto = gr.Button(value="Auto change color")
63
- examples = gr.Examples(examples = [[82], [333], [590]], inputs=[num1])
64
-
65
 
66
- with gr.Row():
67
- with gr.Column():
68
- color1 = gr.Image(height=image_height, width=image_width, show_label=False)
69
- color2 = gr.Image(height=image_height, width=image_width, show_label=False)
70
- color3 = gr.Image(height=image_height, width=image_width, show_label=False)
71
- color4 = gr.Image(height=image_height, width=image_width, show_label=False)
72
  with gr.Column():
73
- image1 = gr.Image(height=image_height*4, width=image_width*4, show_label=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Events
76
  # Release of slider
77
  num1.change(
78
- fn=color_me,
79
- inputs=[num1],
80
- outputs=[color1, color2, color3, color4, image1]
81
- )
 
 
 
82
  # Clicking on auto change color
83
  # Input = -1 indicate autochanging of color
84
- btn_auto.click(fn=auto_color_me,
85
- inputs=[],
86
- outputs=[color1, color2, color3, color4, image1],
87
- every=1)
88
-
 
 
 
 
 
 
 
 
89
  # Main
90
  if __name__ == "__main__":
91
- demo1.launch()
 
5
 
6
  def get_random_color(rng):
7
  for i in range(1):
8
+ # Only want one solid color
9
  color1 = rng.integers(low=0, high=255, size=(1, 1, 3))
10
  color2 = rng.integers(low=0, high=255, size=(1, 1, 3))
11
  color3 = rng.integers(low=0, high=255, size=(1, 1, 3))
12
  color4 = rng.integers(low=0, high=255, size=(1, 1, 3))
13
+ color5 = rng.integers(low=0, high=255, size=(1, 1, 3))
14
+ color6 = rng.integers(low=0, high=255, size=(1, 1, 3))
15
+ color7 = rng.integers(low=0, high=255, size=(1, 1, 3))
16
+ color8 = rng.integers(low=0, high=255, size=(1, 1, 3))
17
+ color9 = rng.integers(low=0, high=255, size=(1, 1, 3))
18
+ # Make the image resolution higher
19
+ color1 = np.resize(color1, new_shape=(256, 256, 3))
20
+ color2 = np.resize(color2, new_shape=(256, 256, 3))
21
+ color3 = np.resize(color3, new_shape=(256, 256, 3))
22
+ color4 = np.resize(color4, new_shape=(256, 256, 3))
23
+ color5 = np.resize(color5, new_shape=(256, 256, 3))
24
+ color6 = np.resize(color6, new_shape=(256, 256, 3))
25
+ color7 = np.resize(color7, new_shape=(256, 256, 3))
26
+ color8 = np.resize(color8, new_shape=(256, 256, 3))
27
+ color9 = np.resize(color9, new_shape=(256, 256, 3))
28
+ # Mix the color into blocks
29
+ block1 = np.concatenate((color1, color2, color3), axis=0)
30
+ # print(f"Shape of block: {block1.shape}")
31
+ block2 = np.concatenate((color4, color5, color6), axis=0)
32
+ block3 = np.concatenate((color7, color8, color9), axis=0)
33
+ # print(f"Shape of block: {block2.shape}")
34
+ block4 = np.concatenate((block1, block2, block3), axis=1)
35
+ # print(f"Shape of block: {block3.shape}")
36
+ return color1, color2, color3, \
37
+ color4, color5, color6, \
38
+ color7, color8, color9, \
39
+ block4
40
+
41
 
42
  def color_me(num1):
43
  # Make some random color
44
  rng1 = np.random.default_rng(seed=num1)
45
  return get_random_color(rng1)
46
 
47
+
48
  def auto_color_me():
49
  # Make some random color
50
  # Get time to be the seed
 
52
  rng1 = np.random.default_rng(seed=seed)
53
  return get_random_color(rng1)
54
 
55
+
56
  # Title of the blocks
57
  with gr.Blocks() as demo1:
58
  image_width = 64
59
  image_height = 64
60
+
61
  with gr.Row():
62
  gr.Markdown(
63
  """
 
75
  corner to the image.
76
  """
77
  )
78
+
79
  with gr.Row():
80
  num1 = gr.Slider(value=10, minimum=0, maximum=1000, step=1,
81
+ label="Value", info="Slide the bar or enter a value to change the color.")
82
+
83
  with gr.Row():
84
+ #btn_auto = gr.Button(value="Auto change color")
85
+ #btn_stop = gr.Button(value="Stop")
86
+ examples = gr.Examples(examples=[[82], [333], [590]], inputs=[num1])
87
 
88
+ with gr.Row():
 
 
 
 
 
89
  with gr.Column():
90
+ image1 = gr.Image(height=image_height*4,
91
+ width=image_width*4, show_label=False)
92
+ # image2 = gr.Image(height=image_height, width=image_width, show_label=False)
93
+ # image3 = gr.Image(height=image_height, width=image_width, show_label=False)
94
+
95
+ with gr.Row():
96
+ color1 = gr.Image(height=image_height,
97
+ width=image_width,
98
+ show_label=False,
99
+ interactive=False)
100
+ color2 = gr.Image(height=image_height,
101
+ width=image_width,
102
+ show_label=False,
103
+ interactive=False)
104
+ color3 = gr.Image(height=image_height,
105
+ width=image_width,
106
+ show_label=False,
107
+ interactive=False)
108
+ with gr.Row():
109
+ color4 = gr.Image(height=image_height,
110
+ width=image_width,
111
+ show_label=False,
112
+ interactive=False)
113
+ color5 = gr.Image(height=image_height,
114
+ width=image_width,
115
+ show_label=False,
116
+ interactive=False)
117
+ color6 = gr.Image(height=image_height,
118
+ width=image_width,
119
+ show_label=False,
120
+ interactive=False)
121
+ with gr.Row():
122
+ color7 = gr.Image(height=image_height,
123
+ width=image_width,
124
+ show_label=False,
125
+ interactive=False)
126
+ color8 = gr.Image(height=image_height,
127
+ width=image_width,
128
+ show_label=False,
129
+ interactive=False)
130
+ color9 = gr.Image(height=image_height,
131
+ width=image_width,
132
+ show_label=False,
133
+ interactive=False)
134
 
135
  # Events
136
  # Release of slider
137
  num1.change(
138
+ fn=color_me,
139
+ inputs=[num1],
140
+ outputs=[color1, color2, color3,
141
+ color4, color5, color6,
142
+ color7, color8, color9,
143
+ image1]
144
+ )
145
  # Clicking on auto change color
146
  # Input = -1 indicate autochanging of color
147
+ # Need to figure out how to stop the event.
148
+ # Will disable the auto change of color for now.
149
+ """
150
+ btn_auto.click(
151
+ fn=auto_color_me,
152
+ inputs=[],
153
+ outputs=[color1, color2, color3,
154
+ color4, color5, color6,
155
+ color7, color8, color9,
156
+ image1],
157
+ every=1)
158
+ """
159
+
160
  # Main
161
  if __name__ == "__main__":
162
+ demo1.launch()