aliabd HF staff commited on
Commit
a5af52a
·
1 Parent(s): 739532e

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. DESCRIPTION.md +1 -0
  2. README.md +1 -1
  3. app.py +0 -12
DESCRIPTION.md ADDED
@@ -0,0 +1 @@
 
 
1
+ This demo built with Blocks generates 9 plots based on the input.
README.md CHANGED
@@ -1,7 +1,7 @@
1
 
2
  ---
3
  title: clustering
4
- emoji: 🤗
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
 
1
 
2
  ---
3
  title: clustering
4
+ emoji: 🔥
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
app.py CHANGED
@@ -1,6 +1,3 @@
1
- # URL: https://huggingface.co/spaces/gradio/clustering
2
- # DESCRIPTION: This demo built with Blocks generates 9 plots based on the input.
3
- # imports
4
  import gradio as gr
5
  import math
6
  from functools import partial
@@ -14,7 +11,6 @@ from sklearn.mixture import GaussianMixture
14
  from sklearn.neighbors import kneighbors_graph
15
  from sklearn.preprocessing import StandardScaler
16
 
17
- # loading models and setting up
18
  plt.style.use('seaborn')
19
  SEED = 0
20
  MAX_CLUSTERS = 10
@@ -27,12 +23,10 @@ COLORS = [
27
  assert len(COLORS) >= MAX_CLUSTERS, "Not enough different colors for all clusters"
28
  np.random.seed(SEED)
29
 
30
- # defining core fns
31
 
32
  def normalize(X):
33
  return StandardScaler().fit_transform(X)
34
 
35
-
36
  def get_regular(n_clusters):
37
  # spiral pattern
38
  centers = [
@@ -254,14 +248,10 @@ def iter_grid(n_rows, n_cols):
254
  with gr.Column():
255
  yield
256
 
257
- # starting a block
258
-
259
  with gr.Blocks(title=title) as demo:
260
- # adding text as HTML and Markdown
261
  gr.HTML(f"<b>{title}</b>")
262
  gr.Markdown(description)
263
 
264
- # setting up the inputs
265
  input_models = list(MODEL_MAPPING)
266
  input_data = gr.Radio(
267
  list(DATA_MAPPING),
@@ -282,12 +272,10 @@ with gr.Blocks(title=title) as demo:
282
  break
283
 
284
  input_model = input_models[counter]
285
- # defining the output
286
  plot = gr.Plot(label=input_model)
287
  fn = partial(cluster, clustering_algorithm=input_model)
288
  input_data.change(fn=fn, inputs=[input_data, input_n_clusters], outputs=plot)
289
  input_n_clusters.change(fn=fn, inputs=[input_data, input_n_clusters], outputs=plot)
290
  counter += 1
291
 
292
- # launch
293
  demo.launch()
 
 
 
 
1
  import gradio as gr
2
  import math
3
  from functools import partial
 
11
  from sklearn.neighbors import kneighbors_graph
12
  from sklearn.preprocessing import StandardScaler
13
 
 
14
  plt.style.use('seaborn')
15
  SEED = 0
16
  MAX_CLUSTERS = 10
 
23
  assert len(COLORS) >= MAX_CLUSTERS, "Not enough different colors for all clusters"
24
  np.random.seed(SEED)
25
 
 
26
 
27
  def normalize(X):
28
  return StandardScaler().fit_transform(X)
29
 
 
30
  def get_regular(n_clusters):
31
  # spiral pattern
32
  centers = [
 
248
  with gr.Column():
249
  yield
250
 
 
 
251
  with gr.Blocks(title=title) as demo:
 
252
  gr.HTML(f"<b>{title}</b>")
253
  gr.Markdown(description)
254
 
 
255
  input_models = list(MODEL_MAPPING)
256
  input_data = gr.Radio(
257
  list(DATA_MAPPING),
 
272
  break
273
 
274
  input_model = input_models[counter]
 
275
  plot = gr.Plot(label=input_model)
276
  fn = partial(cluster, clustering_algorithm=input_model)
277
  input_data.change(fn=fn, inputs=[input_data, input_n_clusters], outputs=plot)
278
  input_n_clusters.change(fn=fn, inputs=[input_data, input_n_clusters], outputs=plot)
279
  counter += 1
280
 
 
281
  demo.launch()