clr commited on
Commit
8eab7fb
·
verified ·
1 Parent(s): 7e22e22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -76,9 +76,9 @@ def refresh_prompt_fn():
76
  # based on how users should speak short vs longer prompts
77
  def _user_instructions(to_speak):
78
  if (len(to_speak.split(' '))<2) or ' – ' in to_speak:
79
- instr = "Lestu eftirfarandi texta. Talaðu skýrt:"
80
  else:
81
- instr = "Lestu eftirfarandi texta eins og þu segir í venjulegu samtali:"
82
 
83
 
84
  def recal_fb_fn(cslider):
@@ -86,7 +86,7 @@ def recal_fb_fn(cslider):
86
  return FeedbackConverter(fb_params['t_key'], fb_params['p_key'], lowr, uppr)
87
 
88
 
89
- def score_speech_fn(current_prompt, user_wav, fbc):
90
 
91
  task_id, norm_text = current_prompt
92
  task_text, task_model = scorer.task_scorer(task_id)
@@ -133,16 +133,16 @@ def score_speech_fn(current_prompt, user_wav, fbc):
133
  #print('WORD FB:', word_feedback)
134
  #print('PHONE FB', phone_feedback)
135
 
136
- disp_fb = f'## Einkunn/gæði: {task_feedback}'
137
 
138
  #return ''.join([ hc_from_3(self.phone_3sort_monophone(score,label)) for label,score in scores_list ])
139
  disp_fb2 = ' '.join([''.join([fbc.hc_from_3(sc3,phid) for sc3,phid in wphones]) for wrd, wphones in phone_feedback])
140
  #disp_fb2 = ' '.join([htxt for wrd, htxt in phone_feedback])
141
  disp_fb2 = f'## {disp_fb2}'
142
 
143
- disp_plot1 = fbc.generate_graphic_feedback_0(user_wav, word_aligns, phone_aligns, phone_feedback)
144
 
145
- disp_blocksplot = fbc.generate_graphic_feedback_blocks(phone_scores)
146
 
147
  else:
148
  disp_fb = "Failure. If this happens every time try a different device/browser, "
@@ -167,7 +167,7 @@ def _disp_scorertype(scorertype):
167
  # toggle on/off some components
168
  def dev_opts_fn(check_box,phone_output_keyinfo):
169
  energy_key = """, <span style='color:#F49098;'>--- Hljóðstyrkur (root mean square energy)</span>"""
170
- reset_fb = gr.State(FeedbackConverter(fb_params['t_key'], fb_params['p_key'], fb_params['lb'], fb_params['ub']))
171
  if check_box: # user has just turned ON extra options
172
  new_key = phone_output_keyinfo + energy_key
173
  new_vis = True
@@ -178,7 +178,10 @@ def dev_opts_fn(check_box,phone_output_keyinfo):
178
  gr.update(value= _disp_scorertype('...'),visible=new_vis),
179
  gr.update(value=(fb_params['lb'], fb_params['ub']),visible=new_vis),
180
  reset_fb,
181
- gr.update(visible=new_vis), gr.update(visible=new_vis), gr.update(visible=new_vis), gr.update(visible=new_vis)]
 
 
 
182
 
183
 
184
  def display0(score_output):
@@ -239,7 +242,9 @@ with bl:
239
 
240
  with gr.Row():
241
  with gr.Column(scale=2):
242
- phone_output_keyinfo = gr.Markdown("""### Lykill: <span style='color:#26701C;'>Meira nálægt</span>, <span style='color:#E85907;'>Minna nálægt</span>, <span style='color:#BBBBBB;'>Ekki hægt að greina (of stutt hljóð)</span>, <span style='color:#88447F;'>••• Ítónun (tónhæð)</span>""")
 
 
243
  with gr.Column(scale=1):
244
  dev_checkbox = gr.Checkbox(label="[Sýna villuleitarverkfæri]", value=False)
245
 
@@ -266,7 +271,7 @@ with bl:
266
  outputs = [fb] )
267
 
268
  score_speech_button.click(score_speech_fn,
269
- inputs=[current_prompt, user_speech, fb],
270
  outputs = [placeholder_output, modeltype_info, plot_output, blocks_output])
271
  #outputs = [placeholder_output, phone_output, modeltype_info, plot_output])
272
 
 
76
  # based on how users should speak short vs longer prompts
77
  def _user_instructions(to_speak):
78
  if (len(to_speak.split(' '))<2) or ' – ' in to_speak:
79
+ return "Lestu eftirfarandi texta. Talaðu skýrt:"
80
  else:
81
+ return "Lestu eftirfarandi texta eins og þu segir í venjulegu samtali:"
82
 
83
 
84
  def recal_fb_fn(cslider):
 
86
  return FeedbackConverter(fb_params['t_key'], fb_params['p_key'], lowr, uppr)
87
 
88
 
89
+ def score_speech_fn(current_prompt, user_wav, fbc, devopts):
90
 
91
  task_id, norm_text = current_prompt
92
  task_text, task_model = scorer.task_scorer(task_id)
 
133
  #print('WORD FB:', word_feedback)
134
  #print('PHONE FB', phone_feedback)
135
 
136
+ disp_fb = f'## Einkunn/gæði framburðar: {task_feedback}'
137
 
138
  #return ''.join([ hc_from_3(self.phone_3sort_monophone(score,label)) for label,score in scores_list ])
139
  disp_fb2 = ' '.join([''.join([fbc.hc_from_3(sc3,phid) for sc3,phid in wphones]) for wrd, wphones in phone_feedback])
140
  #disp_fb2 = ' '.join([htxt for wrd, htxt in phone_feedback])
141
  disp_fb2 = f'## {disp_fb2}'
142
 
143
+ disp_plot1 = fbc.generate_graphic_feedback_0(user_wav, word_aligns, phone_aligns, phone_feedback, devopts)
144
 
145
+ disp_blocksplot = fbc.generate_graphic_feedback_blocks(phone_scores) if devopts else gr.Plot()
146
 
147
  else:
148
  disp_fb = "Failure. If this happens every time try a different device/browser, "
 
167
  # toggle on/off some components
168
  def dev_opts_fn(check_box,phone_output_keyinfo):
169
  energy_key = """, <span style='color:#F49098;'>--- Hljóðstyrkur (root mean square energy)</span>"""
170
+ reset_fb = FeedbackConverter(fb_params['t_key'], fb_params['p_key'], fb_params['lb'], fb_params['ub'])
171
  if check_box: # user has just turned ON extra options
172
  new_key = phone_output_keyinfo + energy_key
173
  new_vis = True
 
178
  gr.update(value= _disp_scorertype('...'),visible=new_vis),
179
  gr.update(value=(fb_params['lb'], fb_params['ub']),visible=new_vis),
180
  reset_fb,
181
+ gr.update(visible=new_vis),
182
+ gr.update(visible=new_vis),
183
+ gr.update(visible=new_vis), #gr.Plot(),
184
+ gr.update(visible=new_vis)]
185
 
186
 
187
  def display0(score_output):
 
242
 
243
  with gr.Row():
244
  with gr.Column(scale=2):
245
+ #phone_output_keyinfo = gr.Markdown("""### Lykill: <span style='color:#26701C;'>Meira nálægt</span>, <span style='color:#E85907;'>Minna nálægt</span>, <span style='color:#BBBBBB;'>Ekki hægt að greina (of stutt hljóð)</span>, <span style='color:#88447F;'>••• Ítónun (tónhæð)</span>""")
246
+ phone_output_keyinfo = gr.Markdown("""### Lykill: <span style='color:#26701C;'>Nálægt réttum framburði</span>, <span style='color:#E85907;'>Fjarri réttum framburði</span>, <span style='color:#BBBBBB;'>Ekki hægt að greina (of stutt hljóð)</span>, <span style='color:#88447F;'>••• Ítónun (tónhæð)</span>""")
247
+
248
  with gr.Column(scale=1):
249
  dev_checkbox = gr.Checkbox(label="[Sýna villuleitarverkfæri]", value=False)
250
 
 
271
  outputs = [fb] )
272
 
273
  score_speech_button.click(score_speech_fn,
274
+ inputs=[current_prompt, user_speech, fb, dev_checkbox],
275
  outputs = [placeholder_output, modeltype_info, plot_output, blocks_output])
276
  #outputs = [placeholder_output, phone_output, modeltype_info, plot_output])
277