maringetxway commited on
Commit
bd6cbd3
·
verified ·
1 Parent(s): 11bbce2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -238,11 +238,40 @@ with gr.Blocks(css=".gr-dropdown { max-height: 100px; overflow-y: auto; font-siz
238
  language_filter = gr.Dropdown(label="Filter by Language", choices=["All", "English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"], value="All")
239
  table_html = gr.HTML(label="Matching Participants")
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  country_filter.change(fn=update_city_filter, inputs=[country_filter], outputs=[city_filter])
242
  country_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
243
  city_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
244
  language_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
245
-
246
 
247
  submit_btn.click(
248
  fn=submit_profile,
 
238
  language_filter = gr.Dropdown(label="Filter by Language", choices=["All", "English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"], value="All")
239
  table_html = gr.HTML(label="Matching Participants")
240
 
241
+
242
+ def update_dropdown_choices():
243
+ with open(DATA_FILE, "r") as f:
244
+ data = json.load(f)
245
+ df = pd.DataFrame(data)
246
+
247
+ country_choices = sorted(df["Country"].dropna().unique()) if "Country" in df else []
248
+ city_choices = sorted(df["City"].dropna().unique()) if "City" in df else []
249
+ language_set = set()
250
+ if "Languages" in df:
251
+ for lang_list in df["Languages"].dropna():
252
+ if isinstance(lang_list, list):
253
+ language_set.update(lang_list)
254
+ elif isinstance(lang_list, str):
255
+ language_set.update(lang_list.split(", "))
256
+ return (
257
+ gr.update(choices=["All"] + list(country_choices), value="All"),
258
+ gr.update(choices=["All"] + list(city_choices), value="All"),
259
+ gr.update(choices=["All"] + sorted(language_set), value="All")
260
+ )
261
+
262
+ with demo:
263
+ demo.load(
264
+ fn=lambda: filter_by_fields("All", "All", "All"),
265
+ inputs=[],
266
+ outputs=[table_html]
267
+ )
268
+
269
+ demo.load(fn=update_dropdown_choices, outputs=[country_filter, city_filter, language_filter])
270
+
271
  country_filter.change(fn=update_city_filter, inputs=[country_filter], outputs=[city_filter])
272
  country_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
273
  city_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
274
  language_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
 
275
 
276
  submit_btn.click(
277
  fn=submit_profile,