Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,8 @@ def setup():
|
|
| 34 |
#print('about to setup')
|
| 35 |
setup()
|
| 36 |
|
| 37 |
-
#
|
|
|
|
| 38 |
# (because gradio pagination is currently broken)
|
| 39 |
# and reset all filter menus
|
| 40 |
def pick_lang(langname):
|
|
@@ -44,24 +45,37 @@ def pick_lang(langname):
|
|
| 44 |
elif langname =="Faroese":
|
| 45 |
df = datas.ds_f
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
return (df[:15],"all") #(df, df[:50])
|
| 50 |
|
| 51 |
|
| 52 |
|
|
|
|
| 53 |
|
| 54 |
-
def f1(langname,gender):
|
| 55 |
if langname=="Icelandic":
|
| 56 |
-
|
| 57 |
-
lang_aligner = datas.a_i
|
| 58 |
elif langname =="Faroese":
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
maxdat=len(ds)
|
| 67 |
|
|
@@ -94,16 +108,17 @@ with bl:
|
|
| 94 |
The random example can be from the whole corpus, not necessarily one of the visible rows. More information below.
|
| 95 |
""" )
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
| 100 |
with gr.Row():
|
| 101 |
gmenu = gr.Dropdown(["all", "f", "m"], label="Gender", value="all")
|
| 102 |
amenu = gr.Dropdown(["all", '15-35', '36-60', '61+'], label="Age", value="all")
|
|
|
|
| 103 |
|
|
|
|
|
|
|
| 104 |
|
| 105 |
with gr.Row():
|
| 106 |
-
#invisidata = gr.DataFrame(interactive=False, visible=False)
|
| 107 |
databrowser = gr.DataFrame(wrap=True, max_rows=50, interactive=False, overflow_row_behaviour='paginate')
|
| 108 |
|
| 109 |
|
|
@@ -121,13 +136,18 @@ with bl:
|
|
| 121 |
|
| 122 |
|
| 123 |
# when user selects a language,
|
| 124 |
-
#
|
|
|
|
| 125 |
# and reset all filter menus
|
| 126 |
-
langmenu.change(pick_lang,langmenu,[databrowser,gmenu])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
#
|
| 130 |
-
btn1.click(f1, [langmenu,
|
| 131 |
|
| 132 |
|
| 133 |
|
|
|
|
| 34 |
#print('about to setup')
|
| 35 |
setup()
|
| 36 |
|
| 37 |
+
# return the whole corpus as a state
|
| 38 |
+
# display some of it
|
| 39 |
# (because gradio pagination is currently broken)
|
| 40 |
# and reset all filter menus
|
| 41 |
def pick_lang(langname):
|
|
|
|
| 45 |
elif langname =="Faroese":
|
| 46 |
df = datas.ds_f
|
| 47 |
|
| 48 |
+
dfd = df.data.to_pandas()
|
| 49 |
+
dfd = dfd.drop(columns=['audio', 'speaker_id','duration'])
|
| 50 |
+
return (df, dfd[:15], "all") #(df, df[:50])
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
+
def apply_filters(df,langname,gender):#,ageIS,ageFO):
|
| 55 |
|
|
|
|
| 56 |
if langname=="Icelandic":
|
| 57 |
+
df = datas.ds_i
|
|
|
|
| 58 |
elif langname =="Faroese":
|
| 59 |
+
df = datas.ds_f
|
| 60 |
+
|
| 61 |
+
if gender != "all":
|
| 62 |
+
df = df.filter(lambda x: x["gender"].startswith(gender))
|
| 63 |
|
| 64 |
+
#if age != "all":
|
| 65 |
+
# df = df.filter(lambda x: x["age"] == age)
|
| 66 |
+
|
| 67 |
+
#if age != "all":
|
| 68 |
+
|
| 69 |
+
dfd = df.data.to_pandas()
|
| 70 |
+
dfd = dfd.drop(columns=['audio', 'speaker_id','duration'])
|
| 71 |
+
return (df,dfd[:15])
|
| 72 |
|
| 73 |
+
|
| 74 |
+
def f1(langname,ds):
|
| 75 |
+
if langname=="Icelandic":
|
| 76 |
+
lang_aligner = datas.a_i
|
| 77 |
+
elif langname =="Faroese":
|
| 78 |
+
lang_aligner = datas.a_f
|
| 79 |
|
| 80 |
maxdat=len(ds)
|
| 81 |
|
|
|
|
| 108 |
The random example can be from the whole corpus, not necessarily one of the visible rows. More information below.
|
| 109 |
""" )
|
| 110 |
|
| 111 |
+
ds = gr.State()
|
|
|
|
| 112 |
|
| 113 |
with gr.Row():
|
| 114 |
gmenu = gr.Dropdown(["all", "f", "m"], label="Gender", value="all")
|
| 115 |
amenu = gr.Dropdown(["all", '15-35', '36-60', '61+'], label="Age", value="all")
|
| 116 |
+
btn0 = gr.Button(value="Apply filters")
|
| 117 |
|
| 118 |
+
# use 2 age menus
|
| 119 |
+
# and set 1 of them visible at a time dependeing on the language.....
|
| 120 |
|
| 121 |
with gr.Row():
|
|
|
|
| 122 |
databrowser = gr.DataFrame(wrap=True, max_rows=50, interactive=False, overflow_row_behaviour='paginate')
|
| 123 |
|
| 124 |
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
# when user selects a language,
|
| 139 |
+
# reset the dataset
|
| 140 |
+
# display some data from it
|
| 141 |
# and reset all filter menus
|
| 142 |
+
langmenu.change(pick_lang,langmenu,[ds,databrowser,gmenu])
|
| 143 |
+
|
| 144 |
+
# filter the current data and change the state based on this
|
| 145 |
+
# and display the update
|
| 146 |
+
btn0.click(apply_filters,[ds,langmenu,gmenu],[ds,databrowser])
|
| 147 |
|
| 148 |
|
| 149 |
#
|
| 150 |
+
btn1.click(f1, [langmenu,ds], [pl1,audio1,ainfo])
|
| 151 |
|
| 152 |
|
| 153 |
|