Setup layouts using blocks
Browse filesUsing blocks allows for automatic updates when the user changes a value in one of the components
app.py
CHANGED
@@ -50,35 +50,59 @@ def get_clusters_plot(n_blobs, quantile, cluster_std):
|
|
50 |
return fig, message
|
51 |
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
if __name__ == "__main__":
|
84 |
demo.launch()
|
|
|
50 |
return fig, message
|
51 |
|
52 |
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
with gr.Row():
|
55 |
+
with gr.Column(scale=1):
|
56 |
+
n_blobs = gr.Slider(
|
57 |
+
minimum=2,
|
58 |
+
maximum=10,
|
59 |
+
label="Number of clusters in the data",
|
60 |
+
step=1,
|
61 |
+
value=3,
|
62 |
+
)
|
63 |
+
quantile = gr.Slider(
|
64 |
+
minimum=0,
|
65 |
+
maximum=1,
|
66 |
+
step=0.05,
|
67 |
+
value=0.2,
|
68 |
+
label="Quantile",
|
69 |
+
info="Used to determine clustering's bandwidth.",
|
70 |
+
)
|
71 |
+
cluster_std = gr.Slider(
|
72 |
+
minimum=0.1,
|
73 |
+
maximum=1,
|
74 |
+
label="Clusters' standard deviation",
|
75 |
+
step=0.1,
|
76 |
+
value=0.6,
|
77 |
+
)
|
78 |
+
with gr.Column(scale=4):
|
79 |
+
clusters_plots = gr.Plot(label="Clusters' Plot")
|
80 |
+
message = gr.HTML()
|
81 |
+
|
82 |
+
n_blobs.change(
|
83 |
+
get_clusters_plot,
|
84 |
+
[n_blobs, quantile, cluster_std],
|
85 |
+
[clusters_plots, message],
|
86 |
+
queue=False,
|
87 |
+
)
|
88 |
+
quantile.change(
|
89 |
+
get_clusters_plot,
|
90 |
+
[n_blobs, quantile, cluster_std],
|
91 |
+
[clusters_plots, message],
|
92 |
+
queue=False,
|
93 |
+
)
|
94 |
+
cluster_std.change(
|
95 |
+
get_clusters_plot,
|
96 |
+
[n_blobs, quantile, cluster_std],
|
97 |
+
[clusters_plots, message],
|
98 |
+
queue=False,
|
99 |
+
)
|
100 |
+
demo.load(
|
101 |
+
get_clusters_plot,
|
102 |
+
[n_blobs, quantile, cluster_std],
|
103 |
+
[clusters_plots, message],
|
104 |
+
queue=False,
|
105 |
+
)
|
106 |
|
107 |
if __name__ == "__main__":
|
108 |
demo.launch()
|