RobPruzan commited on
Commit
4999642
·
1 Parent(s): bc60ca2

Adding vocabulary level

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -417,6 +417,31 @@ def gen_syns(word, level):
417
  str_reko+= i
418
  return str_reko
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  with gr.Blocks(title="Automatic Literacy and Speech Assesmen") as demo:
421
  gr.HTML("""<center><h7 style="font-size: 35px">Automatic Literacy and Speech Assesment</h7></center>""")
422
  with gr.Column():
@@ -460,8 +485,12 @@ with gr.Blocks(title="Automatic Literacy and Speech Assesmen") as demo:
460
  find_sim = gr.Button("Find Similar Words")
461
  sims = gr.Label()
462
  with gr.Box():
463
- gr.Markdown("Relative Difficulty Heatmap- How confusing the text is in that area")
464
- interpretation2 = gr.components.Interpretation(in_text, label="Difficulty Heatmap")
 
 
 
 
465
  with gr.Row():
466
  with gr.Box():
467
  with gr.Group():
@@ -499,6 +528,7 @@ with gr.Blocks(title="Automatic Literacy and Speech Assesmen") as demo:
499
  grade.click(reading_difficulty, inputs=in_text, outputs=diff_output)
500
  grade.click(calculate_diversity, inputs=in_text, outputs=[interpretation, div_output])
501
  grade.click(sliding_window, inputs=in_text, outputs=[plotter, interpretation2])
 
502
  grade1.click(speech_to_score, inputs=audio_file, outputs=diff_output)
503
  b1.click(speech_to_text, inputs=[audio_file1, target], outputs=[text, some_val, phones])
504
  get_syns.click(gen_syns, inputs=[words, lvl], outputs=reccos)
 
417
  str_reko+= i
418
  return str_reko
419
 
420
+ def get_level(word):
421
+ with open('balanced_synonym_data.json') as f:
422
+ word = word.strip(" ")
423
+ data = json.loads(f.read())
424
+ level = 0
425
+ for k, v in data.items():
426
+ if word in v:
427
+ level = k
428
+ if level == 0:
429
+ return -1
430
+ return level
431
+
432
+ def vocab_level_inter(text):
433
+ text = word_tokenize(text)
434
+ interp = [('',0)]
435
+ sum = 0
436
+ total = 0
437
+ for idx, i in enumerate(text):
438
+ lvl = int(get_level(i))/4
439
+ interp.append((i, lvl))
440
+ sum+= lvl
441
+ total += 1
442
+ interp.append(('', 0))
443
+ return interp, level(sum/total*4*2.5)
444
+
445
  with gr.Blocks(title="Automatic Literacy and Speech Assesmen") as demo:
446
  gr.HTML("""<center><h7 style="font-size: 35px">Automatic Literacy and Speech Assesment</h7></center>""")
447
  with gr.Column():
 
485
  find_sim = gr.Button("Find Similar Words")
486
  sims = gr.Label()
487
  with gr.Box():
488
+ gr.Markdown("Relative Difficulty Heatmap- How confusing the text is in that area")
489
+ interpretation2 = gr.components.Interpretation(in_text, label="Difficulty Heatmap")
490
+ with gr.Box():
491
+ vocab_output = gr.Label(label='Vocabulary Level', show_label=False)
492
+ gr.Markdown("Vocabulary Level Heatmap | Darker = Higher Level} Blue cells are not in vocabulary")
493
+ interpretation3 = gr.components.Interpretation(in_text, label="Interpretation of Text")
494
  with gr.Row():
495
  with gr.Box():
496
  with gr.Group():
 
528
  grade.click(reading_difficulty, inputs=in_text, outputs=diff_output)
529
  grade.click(calculate_diversity, inputs=in_text, outputs=[interpretation, div_output])
530
  grade.click(sliding_window, inputs=in_text, outputs=[plotter, interpretation2])
531
+ grade.click(vocab_level_inter, inputs=in_text, outputs=[interpretation3, vocab_output])
532
  grade1.click(speech_to_score, inputs=audio_file, outputs=diff_output)
533
  b1.click(speech_to_text, inputs=[audio_file1, target], outputs=[text, some_val, phones])
534
  get_syns.click(gen_syns, inputs=[words, lvl], outputs=reccos)