CoolFace
Apppublic

wavingtide/image-processing

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py19 linesDownload Raw Back to root
1import os2 3import gradio as gr4from sklearn.cluster import KMeans5 6 7def clustering(image, n_clusters):8    X = image.reshape(-1, 3)9    kmeans = KMeans(n_clusters=n_clusters, random_state=42).fit(X)10    segmented_img = kmeans.cluster_centers_[kmeans.labels_]11    segmented_img = segmented_img.reshape(image.shape)12    return segmented_img / 255.013 14 15# Write 1 line of Python to create a simple GUI16demo = gr.Interface(fn=clustering, inputs=["image", gr.Slider(3, 20, step=1)], outputs="image")17 18demo.launch()19