Spaces:
Runtime error
Runtime error
Adding reading level based synonym generation
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import csv
|
| 2 |
import string
|
|
|
|
| 3 |
|
| 4 |
import gensim.downloader as api
|
| 5 |
import matplotlib.pyplot as plt
|
|
@@ -405,57 +406,82 @@ def speech_to_score(speech):
|
|
| 405 |
def my_i_func(text):
|
| 406 |
return {"original": "", "interpretation": [('', 0.0), ('what', -0.2), ('great', 0.3), ('day', 0.5), ('', 0.0)]}
|
| 407 |
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
with gr.Blocks() as demo:
|
| 412 |
-
|
| 413 |
-
with gr.Row():
|
| 414 |
-
with gr.Box():
|
| 415 |
-
with gr.Column():
|
| 416 |
-
with gr.Group():
|
| 417 |
-
with gr.Tabs():
|
| 418 |
-
with gr.TabItem("Text"):
|
| 419 |
-
in_text = gr.Textbox(label="In Text")
|
| 420 |
-
grade = gr.Button("Grade Your Text")
|
| 421 |
-
with gr.TabItem("Speech"):
|
| 422 |
-
audio_file = gr.Audio(source="microphone", type="filepath")
|
| 423 |
-
audio_trans = gr.Textbox(label="Transcription")
|
| 424 |
-
grade1 = gr.Button("Grade Your Speech")
|
| 425 |
-
|
| 426 |
-
with gr.Box():
|
| 427 |
-
gr.Markdown("Requires 25-50 Words")
|
| 428 |
-
diff_output = gr.Label(label='Difficulty Level', show_label=True)
|
| 429 |
-
plotter = gr.Plot()
|
| 430 |
-
|
| 431 |
-
with gr.Row():
|
| 432 |
-
with gr.Box():
|
| 433 |
-
div_output = gr.Label(label='Lexical Diversity Score', show_label=False)
|
| 434 |
-
gr.Markdown("Lexical Diversity Heatmap | Blue cells are omitted from score")
|
| 435 |
-
interpretation = gr.components.Interpretation(in_text, label="Diversity Heatmap")
|
| 436 |
-
|
| 437 |
-
with gr.Box():
|
| 438 |
-
gr.Markdown("Relative Difficulty Heatmap")
|
| 439 |
-
interpretation2 = gr.components.Interpretation(in_text, label="Difficulty Heatmap")
|
| 440 |
with gr.Row():
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
demo.launch(debug=True)
|
|
|
|
| 1 |
import csv
|
| 2 |
import string
|
| 3 |
+
import json
|
| 4 |
|
| 5 |
import gensim.downloader as api
|
| 6 |
import matplotlib.pyplot as plt
|
|
|
|
| 406 |
def my_i_func(text):
|
| 407 |
return {"original": "", "interpretation": [('', 0.0), ('what', -0.2), ('great', 0.3), ('day', 0.5), ('', 0.0)]}
|
| 408 |
|
| 409 |
+
def gen_syns(word, level):
|
| 410 |
+
with open('balanced_synonym_data.json') as f:
|
| 411 |
+
data = json.loads(f.read())
|
| 412 |
+
level = str(level)
|
| 413 |
+
pins = wn_syns(word)
|
| 414 |
+
reko = []
|
| 415 |
+
for i in pins:
|
| 416 |
+
if i in data[level]:
|
| 417 |
+
reko.append(i)
|
| 418 |
+
str_reko = ""
|
| 419 |
+
for idx, i in enumerate(reko):
|
| 420 |
+
if idx != len(reko) -1:
|
| 421 |
+
str_reko+= i + ' | '
|
| 422 |
+
else:
|
| 423 |
+
str_reko+= i
|
| 424 |
+
return str_reko
|
| 425 |
|
| 426 |
with gr.Blocks() as demo:
|
| 427 |
+
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
with gr.Row():
|
| 429 |
+
with gr.Box():
|
| 430 |
+
|
| 431 |
+
with gr.Column():
|
| 432 |
+
with gr.Group():
|
| 433 |
+
with gr.Tabs():
|
| 434 |
+
|
| 435 |
+
with gr.TabItem("Text"):
|
| 436 |
+
in_text = gr.Textbox(label="In Text")
|
| 437 |
+
grade = gr.Button("Grade Your Text")
|
| 438 |
+
with gr.TabItem("Speech"):
|
| 439 |
+
audio_file = gr.Audio(source="microphone",type="filepath")
|
| 440 |
+
grade1 = gr.Button("Grade Your Speech")
|
| 441 |
+
with gr.Group():
|
| 442 |
+
gr.Markdown("Reading Level Based Synonyms")
|
| 443 |
+
words = gr.Textbox(label="Word For Synonyms")
|
| 444 |
+
lvl = gr.Slider(minimum=1, maximum=4, step=1, label="Intended Reading Level For Synonym")
|
| 445 |
+
get_syns = gr.Button("Get Synonyms")
|
| 446 |
+
reccos = gr.Label()
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
with gr.Box():
|
| 450 |
+
diff_output = gr.Label(label='Difficulty Level',show_label=True)
|
| 451 |
+
gr.Markdown("Diversity Score Across Text")
|
| 452 |
+
plotter = gr.Plot()
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
with gr.Row():
|
| 458 |
+
with gr.Box():
|
| 459 |
+
div_output = gr.Label(label='Diversity Score', show_label=False)
|
| 460 |
+
gr.Markdown("Diversity Heamap | Blue cells are omitted from score")
|
| 461 |
+
interpretation = gr.components.Interpretation(in_text, label="Diversity Heapmap")
|
| 462 |
+
with gr.Box():
|
| 463 |
+
interpretation2 = gr.components.Interpretation(in_text, label="Difficulty Heapmap")
|
| 464 |
+
with gr.Row():
|
| 465 |
+
with gr.Box():
|
| 466 |
+
with gr.Group():
|
| 467 |
+
target = gr.Textbox(label="Target Text")
|
| 468 |
+
with gr.Group():
|
| 469 |
+
audio_file1 = gr.Audio(source="microphone",type="filepath")
|
| 470 |
+
b1 = gr.Button("Grade Your Pronunciation")
|
| 471 |
+
with gr.Box():
|
| 472 |
+
some_val = gr.Label()
|
| 473 |
+
text = gr.Textbox()
|
| 474 |
+
phones = gr.Textbox()
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
|
| 479 |
+
grade.click(reading_difficulty, inputs=in_text, outputs=diff_output)
|
| 480 |
+
grade.click(get_mean_score, inputs=in_text, outputs=div_output)
|
| 481 |
+
grade.click(diversity_inter, inputs=in_text, outputs=interpretation)
|
| 482 |
+
grade.click(get_dif_inter, inputs=in_text, outputs=interpretation2)
|
| 483 |
+
grade.click(get_plot, inputs=in_text, outputs=plotter)
|
| 484 |
+
grade1.click(speech_to_score, inputs=audio_file, outputs=diff_output)
|
| 485 |
+
b1.click(speech_to_text, inputs=[audio_file1, target], outputs=[text, some_val, phones])
|
| 486 |
+
get_syns.click(gen_syns, inputs=[words, lvl], outputs=reccos)
|
| 487 |
demo.launch(debug=True)
|