clr commited on
Commit
64d7c56
·
1 Parent(s): 750e743

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -38,37 +38,41 @@ setup()
38
  # display some of it
39
  # (because gradio pagination is currently broken)
40
  # and reset all filter menus
 
41
  def pick_lang(langname):
42
  if langname=="Icelandic":
43
  df = datas.ds_i
 
 
44
 
45
  elif langname =="Faroese":
46
  df = datas.ds_f
 
 
47
 
48
  dfd = df.drop(columns=['audio', 'speaker_id','duration'])
49
- return (df, dfd[:15], "all") #(df, df[:50])
50
 
51
 
52
 
53
- def apply_filters(df,langname,gender):#,ageIS,ageFO):
54
 
55
  if langname=="Icelandic":
56
  df = datas.ds_i
57
- # ++ age by lang here...
58
  elif langname =="Faroese":
59
  df = datas.ds_f
60
- # filter by ages
61
- # filter by dialect
62
 
63
  if gender != "all":
64
  df = df[df.gender.str.startswith(gender)]
65
 
66
- #if age != "all":
67
- # df = df.filter(lambda x: x["age"] == age)
68
 
69
 
70
  dfd = df.drop(columns=['audio', 'speaker_id','duration'])
71
- return (df,dfd[:15])
72
 
73
 
74
  def f1(langname,ds):
@@ -111,11 +115,12 @@ with bl:
111
 
112
  with gr.Row():
113
  gmenu = gr.Dropdown(["all", "f", "m"], label="Gender", value="all")
114
- amenu = gr.Dropdown(["all", '15-35', '36-60', '61+'], label="Age", value="all")
 
 
 
115
  btn0 = gr.Button(value="Apply filters")
116
 
117
- # use 2 age menus
118
- # and set 1 of them visible at a time dependeing on the language.....
119
 
120
  with gr.Row():
121
  databrowser = gr.DataFrame(wrap=True, max_rows=50, interactive=False, overflow_row_behaviour='paginate')
@@ -138,11 +143,11 @@ with bl:
138
  # reset the dataset
139
  # display some data from it
140
  # and reset all filter menus
141
- langmenu.change(pick_lang,langmenu,[ds,databrowser,gmenu])
142
 
143
  # filter the current data and change the state based on this
144
  # and display the update
145
- btn0.click(apply_filters,[ds,langmenu,gmenu],[ds,databrowser])
146
 
147
 
148
  #
 
38
  # display some of it
39
  # (because gradio pagination is currently broken)
40
  # and reset all filter menus
41
+ # return [ds,databrowser,gmenu,amenu,dmenu]
42
  def pick_lang(langname):
43
  if langname=="Icelandic":
44
  df = datas.ds_i
45
+ ages = ["all", '18-19', '20-29', '30-39', '40-49', '50-59', '60-69', '70-79', '80-89', '90']
46
+ diaVis = False
47
 
48
  elif langname =="Faroese":
49
  df = datas.ds_f
50
+ ages = ["all", '15-35', '36-60', '61+']
51
+ diaVis = True
52
 
53
  dfd = df.drop(columns=['audio', 'speaker_id','duration'])
54
+ return (df, dfd[:15], "all", gr.update(choices=ages,value="all"),gr.update(visible=diaVis,value="all"))
55
 
56
 
57
 
58
+ def apply_filters(df,langname,gender,age,dia):
59
 
60
  if langname=="Icelandic":
61
  df = datas.ds_i
 
62
  elif langname =="Faroese":
63
  df = datas.ds_f
64
+ if dia != all:
65
+ df = df[df.dialect.lower() == dia.lower()]
66
 
67
  if gender != "all":
68
  df = df[df.gender.str.startswith(gender)]
69
 
70
+ if age != "all":
71
+ df = df[df.age == age]
72
 
73
 
74
  dfd = df.drop(columns=['audio', 'speaker_id','duration'])
75
+ return (df,dfd[:max(15,len(dfd))])
76
 
77
 
78
  def f1(langname,ds):
 
115
 
116
  with gr.Row():
117
  gmenu = gr.Dropdown(["all", "f", "m"], label="Gender", value="all")
118
+ amenu = gr.Dropdown(["all"], label="Age", value="all")
119
+ dmenu = gr.Dropdown(["all", "Norðuroyggjar (inklusive of Eiði, Gjógv og Funningur)",
120
+ 'Norðurstreymoy/Eysturoy (exclusive of Eiði, Gjógv og Funningur)',
121
+ 'Vágar', 'Sandoy', 'Suðuroy', 'Suðurstreymoy'], label="Dialect", value = "all", visible = False)
122
  btn0 = gr.Button(value="Apply filters")
123
 
 
 
124
 
125
  with gr.Row():
126
  databrowser = gr.DataFrame(wrap=True, max_rows=50, interactive=False, overflow_row_behaviour='paginate')
 
143
  # reset the dataset
144
  # display some data from it
145
  # and reset all filter menus
146
+ langmenu.change(pick_lang,langmenu,[ds,databrowser,gmenu,amenu,dmenu])
147
 
148
  # filter the current data and change the state based on this
149
  # and display the update
150
+ btn0.click(apply_filters,[ds,langmenu,gmenu,amenu,dmenu],[ds,databrowser])
151
 
152
 
153
  #