Spaces:
Running
Running
add shaded color pickers
Browse files- myapp/pall_app.py +11 -3
myapp/pall_app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
|
@@ -11,10 +13,16 @@ with gr.Blocks() as demo:
|
|
11 |
@gr.render(inputs=[image, n_colors])
|
12 |
def render_palette(image_array: np.ndarray, n_clusers: int):
|
13 |
model = extract_color_clusters(image_array, n_clusers)
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
gr.ColorPicker(array_to_hex(cluster))
|
18 |
|
19 |
|
20 |
if __name__ == "__main__":
|
|
|
1 |
+
from contextlib import ExitStack
|
2 |
+
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
|
|
|
13 |
@gr.render(inputs=[image, n_colors])
|
14 |
def render_palette(image_array: np.ndarray, n_clusers: int):
|
15 |
model = extract_color_clusters(image_array, n_clusers)
|
16 |
+
cluster_shades = iter_color_shades(model, (0, 0.2, 0.4, 0.6))
|
17 |
+
|
18 |
+
with ExitStack() as stack:
|
19 |
+
for i, cluster in enumerate(cluster_shades):
|
20 |
+
if i % n_clusers == 0:
|
21 |
+
stack.pop_all().close()
|
22 |
+
stack.enter_context(gr.Group())
|
23 |
+
stack.enter_context(gr.Row())
|
24 |
|
25 |
+
gr.ColorPicker(array_to_hex(cluster))
|
|
|
26 |
|
27 |
|
28 |
if __name__ == "__main__":
|