Spaces:
Running
Running
add clusters
Browse files- myapp/pall_app.py +14 -0
myapp/pall_app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
with gr.Blocks() as demo:
|
4 |
image = gr.Image("vulture.webp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
if __name__ == "__main__":
|
7 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from sklearn.cluster import KMeans
|
4 |
|
5 |
with gr.Blocks() as demo:
|
6 |
image = gr.Image("vulture.webp")
|
7 |
+
n_colors = gr.Slider(1, 16, 4)
|
8 |
+
button = gr.Button()
|
9 |
+
plot = gr.Plot()
|
10 |
+
|
11 |
+
@button.click(inputs=image, outputs=gr.JSON())
|
12 |
+
def get_palette(image_array: np.ndarray):
|
13 |
+
w, h, d = image_array.shape
|
14 |
+
pixels = image_array.reshape(w * h, d)
|
15 |
+
model = KMeans(n_clusters=4).fit(pixels)
|
16 |
+
|
17 |
+
return model.cluster_centers_
|
18 |
+
|
19 |
|
20 |
if __name__ == "__main__":
|
21 |
demo.launch()
|