m3g4p0p commited on
Commit
7147807
·
1 Parent(s): cc4a288

add clusters

Browse files
Files changed (1) hide show
  1. 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()