ankush-003 commited on
Commit
edd2633
·
verified ·
1 Parent(s): d57d2e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -126,6 +126,9 @@ model = FastText.load(
126
 
127
  restaurant_embeddings = extract_restaurant_embeddings(model, df)
128
 
 
 
 
129
  def run_clustering(num_clusters, clusters_to_display):
130
  kmeans = KMeans(n_clusters=num_clusters, random_state=42)
131
  restaurant_clusters = cluster_embeddings(restaurant_embeddings, kmeans)
@@ -157,6 +160,20 @@ def run_clustering(num_clusters, clusters_to_display):
157
 
158
  return analysis, m
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # Create Gradio interface
161
  with gr.Blocks(title="Restaurant Clustering Tool") as app:
162
  gr.Markdown("# Restaurant K-Means Clustering Analysis")
@@ -194,6 +211,8 @@ with gr.Blocks(title="Restaurant Clustering Tool") as app:
194
  inputs=[num_clusters_input, display_clusters_input],
195
  outputs=[output_text, output_plot]
196
  )
 
 
197
 
198
  gr.Markdown("""
199
  ## About this app
 
126
 
127
  restaurant_embeddings = extract_restaurant_embeddings(model, df)
128
 
129
+ clusters_jsons = None
130
+
131
+
132
  def run_clustering(num_clusters, clusters_to_display):
133
  kmeans = KMeans(n_clusters=num_clusters, random_state=42)
134
  restaurant_clusters = cluster_embeddings(restaurant_embeddings, kmeans)
 
160
 
161
  return analysis, m
162
 
163
+ def update_display(clusters_to_display):
164
+
165
+ if clusters_jsons is None:
166
+ return "Please run clustering first", None
167
+
168
+ # Ensure we don't try to show more clusters than exist
169
+ if clusters_to_display > len(clusters_jsons):
170
+ clusters_to_display = len(clusters_jsons)
171
+
172
+ # Create map visualization with selected number of clusters
173
+ m = visualise_on_map(clusters_jsons[:clusters_to_display])
174
+
175
+ return m
176
+
177
  # Create Gradio interface
178
  with gr.Blocks(title="Restaurant Clustering Tool") as app:
179
  gr.Markdown("# Restaurant K-Means Clustering Analysis")
 
211
  inputs=[num_clusters_input, display_clusters_input],
212
  outputs=[output_text, output_plot]
213
  )
214
+
215
+ display_clusters_input.change(update_display, inputs=[display_clusters_input], outputs=[output_plot])
216
 
217
  gr.Markdown("""
218
  ## About this app