Spaces:
Build error
Build error
Commit
·
e69a8dd
1
Parent(s):
cf5577a
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,6 @@ from huggingface_hub.keras_mixin import from_pretrained_keras
|
|
| 16 |
from itertools import cycle, islice
|
| 17 |
|
| 18 |
|
| 19 |
-
model = from_pretrained_keras("tareknaous/unet-visual-clustering")
|
| 20 |
|
| 21 |
|
| 22 |
#Function that predicts on only 1 sample
|
|
@@ -50,6 +49,7 @@ def create_input_image(data, visualize=False):
|
|
| 50 |
|
| 51 |
return input
|
| 52 |
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
def get_instances(prediction, data, max_filter_size=1):
|
|
@@ -124,7 +124,7 @@ def get_instances(prediction, data, max_filter_size=1):
|
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
-
def visual_clustering(cluster_type, num_clusters, num_samples, random_state, median_kernel_size, max_kernel_size):
|
| 128 |
|
| 129 |
NUM_CLUSTERS = num_clusters
|
| 130 |
CLUSTER_STD = 4 * np.ones(NUM_CLUSTERS)
|
|
@@ -143,10 +143,10 @@ def visual_clustering(cluster_type, num_clusters, num_samples, random_state, med
|
|
| 143 |
data = (X_aniso, y)
|
| 144 |
|
| 145 |
elif cluster_type == "noisy moons":
|
| 146 |
-
data = datasets.make_moons(n_samples=num_samples, noise
|
| 147 |
|
| 148 |
elif cluster_type == "noisy circles":
|
| 149 |
-
data = datasets.make_circles(n_samples=num_samples, factor=.01, noise
|
| 150 |
|
| 151 |
max_x = max(data[0][:, 0])
|
| 152 |
min_x = min(data[0][:, 0])
|
|
@@ -184,6 +184,8 @@ def visual_clustering(cluster_type, num_clusters, num_samples, random_state, med
|
|
| 184 |
|
| 185 |
return fig1, fig2
|
| 186 |
|
|
|
|
|
|
|
| 187 |
|
| 188 |
iface = gr.Interface(
|
| 189 |
|
|
@@ -193,6 +195,7 @@ iface = gr.Interface(
|
|
| 193 |
gr.inputs.Dropdown(["blobs", "varied blobs", "aniso", "noisy moons", "noisy circles" ]),
|
| 194 |
gr.inputs.Slider(1, 10, step=1, label='Number of Clusters'),
|
| 195 |
gr.inputs.Slider(10000, 1000000, step=10000, label='Number of Samples'),
|
|
|
|
| 196 |
gr.inputs.Slider(1, 100, step=1, label='Random State'),
|
| 197 |
gr.inputs.Slider(1, 100, step=1, label='Denoising Filter Kernel Size'),
|
| 198 |
gr.inputs.Slider(1,100, step=1, label='Max Filter Kernel Size')
|
|
@@ -201,6 +204,9 @@ iface = gr.Interface(
|
|
| 201 |
outputs=[
|
| 202 |
gr.outputs.Image(type='plot', label='Dataset'),
|
| 203 |
gr.outputs.Image(type='plot', label='Clustering Result')
|
| 204 |
-
]
|
|
|
|
|
|
|
|
|
|
| 205 |
)
|
| 206 |
iface.launch(debug=True)
|
|
|
|
| 16 |
from itertools import cycle, islice
|
| 17 |
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
#Function that predicts on only 1 sample
|
|
|
|
| 49 |
|
| 50 |
return input
|
| 51 |
|
| 52 |
+
model = from_pretrained_keras("tareknaous/unet-visual-clustering")
|
| 53 |
|
| 54 |
|
| 55 |
def get_instances(prediction, data, max_filter_size=1):
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
+
def visual_clustering(cluster_type, num_clusters, num_samples, noise, random_state, median_kernel_size, max_kernel_size):
|
| 128 |
|
| 129 |
NUM_CLUSTERS = num_clusters
|
| 130 |
CLUSTER_STD = 4 * np.ones(NUM_CLUSTERS)
|
|
|
|
| 143 |
data = (X_aniso, y)
|
| 144 |
|
| 145 |
elif cluster_type == "noisy moons":
|
| 146 |
+
data = datasets.make_moons(n_samples=num_samples, noise=noise)
|
| 147 |
|
| 148 |
elif cluster_type == "noisy circles":
|
| 149 |
+
data = datasets.make_circles(n_samples=num_samples, factor=.01, noise=noise)
|
| 150 |
|
| 151 |
max_x = max(data[0][:, 0])
|
| 152 |
min_x = min(data[0][:, 0])
|
|
|
|
| 184 |
|
| 185 |
return fig1, fig2
|
| 186 |
|
| 187 |
+
title = "Clustering Plotted Data by Image Segmentation"
|
| 188 |
+
description = "Gradio Demo for Visual Clustering on synthetic datasets"
|
| 189 |
|
| 190 |
iface = gr.Interface(
|
| 191 |
|
|
|
|
| 195 |
gr.inputs.Dropdown(["blobs", "varied blobs", "aniso", "noisy moons", "noisy circles" ]),
|
| 196 |
gr.inputs.Slider(1, 10, step=1, label='Number of Clusters'),
|
| 197 |
gr.inputs.Slider(10000, 1000000, step=10000, label='Number of Samples'),
|
| 198 |
+
gr.inputs.Slider(0.03, 0.1, step=0.01, label='Noise'),
|
| 199 |
gr.inputs.Slider(1, 100, step=1, label='Random State'),
|
| 200 |
gr.inputs.Slider(1, 100, step=1, label='Denoising Filter Kernel Size'),
|
| 201 |
gr.inputs.Slider(1,100, step=1, label='Max Filter Kernel Size')
|
|
|
|
| 204 |
outputs=[
|
| 205 |
gr.outputs.Image(type='plot', label='Dataset'),
|
| 206 |
gr.outputs.Image(type='plot', label='Clustering Result')
|
| 207 |
+
],
|
| 208 |
+
|
| 209 |
+
title=title,
|
| 210 |
+
description=description,
|
| 211 |
)
|
| 212 |
iface.launch(debug=True)
|