alessandro trinca tornidor commited on
Commit
0931910
·
1 Parent(s): 88d40e4

refactor: read the app description from app_description.md

Browse files
aip_trainer/lambdas/app_description.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # AI Pronunciation Trainer
2
+
3
+ See [my fork](https://github.com/trincadev/ai-pronunciation-trainer) of [AI Pronunciation Trainer](https://github.com/Thiagohgl/ai-pronunciation-trainer) repositroy
4
+ for more details.
5
+
6
+ Selecting a new example invalidates all previous inputs (Text-to-Speech audio and Speech-to-Text recordings): in that case you should recorder again your audio speeceh.
7
+
8
+ Right now this tool uses {} as sample rate value. From empirical tests the best sample rate value is 48000...
aip_trainer/lambdas/js.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ js_update_ipa_output = """
2
+ function updateCssText(text, letters) {
3
+ let wordsArr = text.split(" ")
4
+ let lettersWordsArr = letters.split(" ")
5
+ let speechOutputContainer = document.querySelector('#speech-output');
6
+ speechOutputContainer.textContent = ""
7
+
8
+ for (let idx in wordsArr) {
9
+ let word = wordsArr[idx]
10
+ let letterIsCorrect = lettersWordsArr[idx]
11
+ for (let idx1 in word) {
12
+ let letterCorrect = letterIsCorrect[idx1] == "1"
13
+ let containerLetter = document.createElement("span")
14
+ containerLetter.style.color = letterCorrect ? 'green' : "red"
15
+ containerLetter.innerText = word[idx1];
16
+ speechOutputContainer.appendChild(containerLetter)
17
+ }
18
+ let containerSpace = document.createElement("span")
19
+ containerSpace.textContent = " "
20
+ speechOutputContainer.appendChild(containerSpace)
21
+ }
22
+ }
23
+ """
app.py CHANGED
@@ -1,32 +1,8 @@
 
1
  import gradio as gr
2
 
3
- from aip_trainer import app_logger
4
- from aip_trainer.lambdas import lambdaGetSample, lambdaSpeechToScore, lambdaTTS
5
-
6
-
7
- js = """
8
- function updateCssText(text, letters) {
9
- let wordsArr = text.split(" ")
10
- let lettersWordsArr = letters.split(" ")
11
- let speechOutputContainer = document.querySelector('#speech-output');
12
- speechOutputContainer.textContent = ""
13
-
14
- for (let idx in wordsArr) {
15
- let word = wordsArr[idx]
16
- let letterIsCorrect = lettersWordsArr[idx]
17
- for (let idx1 in word) {
18
- let letterCorrect = letterIsCorrect[idx1] == "1"
19
- let containerLetter = document.createElement("span")
20
- containerLetter.style.color = letterCorrect ? 'green' : "red"
21
- containerLetter.innerText = word[idx1];
22
- speechOutputContainer.appendChild(containerLetter)
23
- }
24
- let containerSpace = document.createElement("span")
25
- containerSpace.textContent = " "
26
- speechOutputContainer.appendChild(containerSpace)
27
- }
28
- }
29
- """
30
 
31
 
32
  def clear():
@@ -40,14 +16,10 @@ def clear2():
40
  with gr.Blocks() as gradio_app:
41
  app_logger.info("start gradio app building...")
42
 
43
- gr.Markdown(
44
- """
45
- # AI Pronunciation Trainer
46
-
47
- See [my fork](https://github.com/trincadev/ai-pronunciation-trainer) of [AI Pronunciation Trainer](https://github.com/Thiagohgl/ai-pronunciation-trainer) repositroy
48
- for more details.
49
- """
50
- )
51
  with gr.Row():
52
  with gr.Column(scale=4, min_width=300):
53
  with gr.Row():
@@ -90,12 +62,12 @@ with gr.Blocks() as gradio_app:
90
  with gr.Column(scale=4, min_width=320):
91
  examples_text = gr.Examples(
92
  examples=[
93
- ["Hi there, how are you?", "en", 1],
94
  ["Hallo, wie geht es dir?", "de", 1],
 
95
  ["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau.", "de", 2,],
96
  ["Rome is home to some of the most beautiful monuments in the world.", "en", 2],
97
- ["Some machine learning models are designed to understand and generate human-like text based on the input they receive.", "en", 3],
98
  ["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau, einem Ortsteil des drei Kilometer nordöstlich gelegenen Bad Brückenau im Landkreis Bad Kissingen in Bayern.", "de", 3],
 
99
  ],
100
  inputs=[learner_transcription, language, difficulty],
101
  )
@@ -161,7 +133,7 @@ with gr.Blocks() as gradio_app:
161
  None,
162
  inputs=[transcripted_text, letter_correctness],
163
  outputs=[html_output],
164
- js=js,
165
  )
166
 
167
 
 
1
+ from pathlib import Path
2
  import gradio as gr
3
 
4
+ from aip_trainer import PROJECT_ROOT_FOLDER, app_logger
5
+ from aip_trainer.lambdas import js, lambdaGetSample, lambdaSpeechToScore, lambdaTTS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  def clear():
 
16
  with gr.Blocks() as gradio_app:
17
  app_logger.info("start gradio app building...")
18
 
19
+ project_root_folder = Path(PROJECT_ROOT_FOLDER)
20
+ with open(project_root_folder / "aip_trainer" / "lambdas" / "app_description.md", "r", encoding="utf-8") as app_description_src:
21
+ app_description = app_description_src.read()
22
+ gr.Markdown(app_description)
 
 
 
 
23
  with gr.Row():
24
  with gr.Column(scale=4, min_width=300):
25
  with gr.Row():
 
62
  with gr.Column(scale=4, min_width=320):
63
  examples_text = gr.Examples(
64
  examples=[
 
65
  ["Hallo, wie geht es dir?", "de", 1],
66
+ ["Hi there, how are you?", "en", 1],
67
  ["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau.", "de", 2,],
68
  ["Rome is home to some of the most beautiful monuments in the world.", "en", 2],
 
69
  ["Die König-Ludwig-Eiche ist ein Naturdenkmal im Staatsbad Brückenau, einem Ortsteil des drei Kilometer nordöstlich gelegenen Bad Brückenau im Landkreis Bad Kissingen in Bayern.", "de", 3],
70
+ ["Some machine learning models are designed to understand and generate human-like text based on the input they receive.", "en", 3],
71
  ],
72
  inputs=[learner_transcription, language, difficulty],
73
  )
 
133
  None,
134
  inputs=[transcripted_text, letter_correctness],
135
  outputs=[html_output],
136
+ js=js.js_update_ipa_output,
137
  )
138
 
139