Mostafa Shahin commited on
Commit
b5336bb
1 Parent(s): 1bd17d3

Only Attribute error in Assessment

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -35,25 +35,22 @@ def diff_fn():
35
  return [('H','+'),('E','-'),('N',None),('\n', None),('F','-'),('Fgo','-'),('M','+')]
36
 
37
  def recognizeAudio(audio_file, attributes, is_ipa=False):
38
- #print(','.join(attributes))
39
  global df_output
40
  if is_ipa:
41
  p2att_matrix = 'data/p2att_en_us-ipa.csv'
42
  else:
43
  p2att_matrix = 'data/p2att_en_us-arpa.csv'
44
- output = engine.transcribe(audio_file, attributes= tuple(attributes), phonological_matrix_file=p2att_matrix, human_readable=False)
45
  records = []
46
  d = json.loads(output)
47
  phonemes = d['Phoneme']['symbols']
48
- #if is_ipa:
49
- # phonemes = [arpa2ipa[arpa2ipa.arpa==ph].ipa.values[0] for ph in phonemes]
50
  records.append(['Phoneme']+phonemes)
51
  for att in d['Attributes']:
52
  records.append([att['Name']]+att['Pattern'])
53
  df = pd.DataFrame.from_records(records)
54
  df.fillna('', inplace=True)
55
  df_output = df
56
- return df.to_html(header=False, index=False)
57
 
58
 
59
  #Get error by matching the expected sequence with the recognized one and return the output in a format that can be visualized by the gradio HighlightedText box
@@ -159,8 +156,6 @@ with gr.Blocks() as gui:
159
 
160
  process.click(fn=recognizeAudio, inputs=[record_audio,att_list, is_ipa], outputs=recognition)
161
 
162
-
163
-
164
  with gr.Tab("Assessment"):
165
  assess = gr.Button("Assessment")
166
  diff = []
@@ -171,24 +166,26 @@ with gr.Blocks() as gui:
171
  color_map={"S": "red", "I": "green", "D":"blue"}, visible=False))
172
 
173
  def get_assessment(prompt_phonemes):#, recognized_phonemes, recognized_attributes):
174
- outputs = [gr.HighlightedText(visible=False)]*(len(Attributes)+1)
175
  outputs[0] = gr.HighlightedText(label=f"Phoneme Assessment",
176
  value=get_error(prompt_phonemes.split(), df_output.iloc[0].values[1:]),
177
  visible=True)
178
  i = 1
179
- for i,r in df_output.iloc[1:].iterrows():
180
  convert = lambda ph: '-' if f'n_{att}' in engine.p2att_map[ph] else '+'
181
  att = r.iloc[0]
182
  exp_att = [convert(ph) for ph in prompt_phonemes.split()]
183
  rec_att = r.iloc[1:].values
184
- outputs[i] = gr.HighlightedText(label=f"{att} Assessment",
 
185
  value=get_error(exp_att, rec_att),
186
  visible=True)
187
- i += 1
188
 
189
  return outputs
190
 
191
- assess.click(fn=get_assessment, inputs= [prompt_phonemes], outputs=diff)
 
192
 
193
  with gr.Tab("Analysis"):
194
  selected_att = gr.Dropdown( sorted(Attributes), label="Select an Attribute to plot", value='voiced', interactive=True)
 
35
  return [('H','+'),('E','-'),('N',None),('\n', None),('F','-'),('Fgo','-'),('M','+')]
36
 
37
  def recognizeAudio(audio_file, attributes, is_ipa=False):
 
38
  global df_output
39
  if is_ipa:
40
  p2att_matrix = 'data/p2att_en_us-ipa.csv'
41
  else:
42
  p2att_matrix = 'data/p2att_en_us-arpa.csv'
43
+ output = engine.transcribe(audio_file, attributes= 'all', phonological_matrix_file=p2att_matrix, human_readable=False)
44
  records = []
45
  d = json.loads(output)
46
  phonemes = d['Phoneme']['symbols']
 
 
47
  records.append(['Phoneme']+phonemes)
48
  for att in d['Attributes']:
49
  records.append([att['Name']]+att['Pattern'])
50
  df = pd.DataFrame.from_records(records)
51
  df.fillna('', inplace=True)
52
  df_output = df
53
+ return df[df[0].isin(['Phoneme']+list(attributes))].to_html(header=False, index=False)
54
 
55
 
56
  #Get error by matching the expected sequence with the recognized one and return the output in a format that can be visualized by the gradio HighlightedText box
 
156
 
157
  process.click(fn=recognizeAudio, inputs=[record_audio,att_list, is_ipa], outputs=recognition)
158
 
 
 
159
  with gr.Tab("Assessment"):
160
  assess = gr.Button("Assessment")
161
  diff = []
 
166
  color_map={"S": "red", "I": "green", "D":"blue"}, visible=False))
167
 
168
  def get_assessment(prompt_phonemes):#, recognized_phonemes, recognized_attributes):
169
+ outputs = [gr.HighlightedText(visible=False)]*(df_output.shape[0])
170
  outputs[0] = gr.HighlightedText(label=f"Phoneme Assessment",
171
  value=get_error(prompt_phonemes.split(), df_output.iloc[0].values[1:]),
172
  visible=True)
173
  i = 1
174
+ for j,r in df_output.iloc[1:].iterrows():
175
  convert = lambda ph: '-' if f'n_{att}' in engine.p2att_map[ph] else '+'
176
  att = r.iloc[0]
177
  exp_att = [convert(ph) for ph in prompt_phonemes.split()]
178
  rec_att = r.iloc[1:].values
179
+ if ''.join(exp_att) != ''.join(rec_att):
180
+ outputs[i] = gr.HighlightedText(label=f"{att} Assessment",
181
  value=get_error(exp_att, rec_att),
182
  visible=True)
183
+ i += 1
184
 
185
  return outputs
186
 
187
+ assess.click(fn=get_assessment, inputs= [prompt_phonemes], outputs=diff)
188
+
189
 
190
  with gr.Tab("Analysis"):
191
  selected_att = gr.Dropdown( sorted(Attributes), label="Select an Attribute to plot", value='voiced', interactive=True)