Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,174 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
# from logic import Speaker_speech_analysis
|
3 |
-
from scipy.io import wavfile
|
4 |
-
from wav2vec_aligen import speaker_pronunciation_assesment
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def create_html_from_scores(word_levels):
|
9 |
-
html_output = ''
|
10 |
-
for word, level in word_levels:
|
11 |
-
if level == '/':
|
12 |
-
html_output += f'<span style="color: #0000ff;">{level}</span> '
|
13 |
-
elif level == 'Wrong':
|
14 |
-
html_output += f'<span style="color: #dc3545;">{word}</span> '
|
15 |
-
elif level == 'Understandable':
|
16 |
-
html_output += f'<span style="color: #ffc107;">{word}</span> '
|
17 |
-
else:
|
18 |
-
html_output += f'<span style="color: #28a745;">{word}</span> '
|
19 |
-
return html_output
|
20 |
-
|
21 |
-
def generate_progress_bar(score, label):
|
22 |
-
score = round(score, 2)
|
23 |
-
score_text = f"{score:.2f}" if score < 100 else "100"
|
24 |
-
if score < 30:
|
25 |
-
bar_color = "#dc3545"
|
26 |
-
elif score < 60:
|
27 |
-
bar_color = "#dc6545"
|
28 |
-
elif score < 80:
|
29 |
-
bar_color = "#ffc107"
|
30 |
-
else:
|
31 |
-
bar_color = "#28a745"
|
32 |
-
bar_length = f"{(score / 100) * 100}%"
|
33 |
-
return f"""
|
34 |
-
<div class="progress-label">{label}:</div>
|
35 |
-
<div class="progress-container">
|
36 |
-
<div class="progress-bar" style="width: {bar_length}; background-color: {bar_color};">
|
37 |
-
<div class="progress-score">{score_text}</div>
|
38 |
-
</div>
|
39 |
-
</div>
|
40 |
-
<div class="progress-max">Max: 100</div>
|
41 |
-
"""
|
42 |
-
# CSS to be used in the Gradio Interface
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
def analyze_audio(text, audio):
|
48 |
-
# Write the processed audio to a temporary WAV file
|
49 |
-
if text is None or audio is None:
|
50 |
-
return 'the audio or the text is missing'
|
51 |
-
temp_filename = 'temp_audio.wav'
|
52 |
-
wavfile.write(temp_filename, audio[0], audio[1])
|
53 |
-
|
54 |
-
|
55 |
-
result = speaker_pronunciation_assesment(temp_filename, text)
|
56 |
-
accuracy_score = result['pronunciation_accuracy']
|
57 |
-
fluency_score = result['fluency_score']
|
58 |
-
word_levels = result['word_levels']
|
59 |
-
content_scores = result['content_scores']
|
60 |
-
wpm = result['wpm']
|
61 |
-
|
62 |
-
html_content = create_html_from_scores(word_levels)
|
63 |
-
pronunciation_progress_bar = generate_progress_bar(accuracy_score, "Pronunciation Accuracy")
|
64 |
-
fluency_progress_bar = generate_progress_bar(fluency_score, "Fluency Score")
|
65 |
-
content_progress_bar = generate_progress_bar(content_scores, "Content Score")
|
66 |
-
|
67 |
-
|
68 |
-
html_with_css = f"""
|
69 |
-
<style>
|
70 |
-
.legend {{
|
71 |
-
font-size: 22px;
|
72 |
-
display: flex;
|
73 |
-
align-items: center;
|
74 |
-
gap: 12px;
|
75 |
-
}}
|
76 |
-
|
77 |
-
.legend-dot {{
|
78 |
-
height: 15px;
|
79 |
-
width: 15px;
|
80 |
-
border-radius: 50%;
|
81 |
-
display: inline-block;
|
82 |
-
}}
|
83 |
-
|
84 |
-
.good {{ color: #28a745;
|
85 |
-
}}
|
86 |
-
.average {{ color: #ffc107;
|
87 |
-
}}
|
88 |
-
.bad {{ color: #dc3545;
|
89 |
-
}}
|
90 |
-
|
91 |
-
.wrong {{ color: #dc3545;
|
92 |
-
}}
|
93 |
-
|
94 |
-
.text {{
|
95 |
-
font-size: 20px;
|
96 |
-
margin-bottom: 20px;
|
97 |
-
}}
|
98 |
-
|
99 |
-
.progress-container {{
|
100 |
-
width: 100%;
|
101 |
-
background-color: #ddd;
|
102 |
-
border-radius: 13px;
|
103 |
-
overflow: hidden;
|
104 |
-
}}
|
105 |
-
|
106 |
-
.progress-bar {{
|
107 |
-
height: 30px;
|
108 |
-
line-height: 30px;
|
109 |
-
text-align: center;
|
110 |
-
font-size: 16px;
|
111 |
-
border-radius: 15px;
|
112 |
-
transition: width 1s ease;
|
113 |
-
}}
|
114 |
-
|
115 |
-
.progress-label {{
|
116 |
-
font-weight: bold;
|
117 |
-
font-size: 22px;
|
118 |
-
margin-bottom: 20px;
|
119 |
-
margin-top: 5px;
|
120 |
-
text-align: center;
|
121 |
-
}}
|
122 |
-
|
123 |
-
.progress-score {{
|
124 |
-
display: inline-block;
|
125 |
-
color: black;
|
126 |
-
}}
|
127 |
-
|
128 |
-
.progress-max {{
|
129 |
-
text-align: right;
|
130 |
-
margin: 10px;
|
131 |
-
font-size: 16px;
|
132 |
-
}}
|
133 |
-
|
134 |
-
</style>
|
135 |
-
|
136 |
-
|
137 |
-
<div class="legend">
|
138 |
-
<span class="legend-dot" style="background-color: #28a745;"></span><span>Good</span>
|
139 |
-
<span class="legend-dot" style="background-color: #ffc107;"></span><span>Understandable</span>
|
140 |
-
<span class="legend-dot" style="background-color: #dc3545;"></span><span>Bad</span>
|
141 |
-
<span class="legend-dot" style="background-color: #0000ff;"></span><span>No Speech</span>
|
142 |
-
</div>
|
143 |
-
|
144 |
-
<p class="text">
|
145 |
-
{html_content}
|
146 |
-
</p>
|
147 |
-
|
148 |
-
<p class="text">
|
149 |
-
<span style="color: #0000ff;">Word Per Minute {wpm:0.2f}</span>
|
150 |
-
</p>
|
151 |
-
|
152 |
-
{pronunciation_progress_bar}
|
153 |
-
{fluency_progress_bar}
|
154 |
-
{content_progress_bar}
|
155 |
-
"""
|
156 |
-
#
|
157 |
-
|
158 |
-
return html_with_css
|
159 |
-
|
160 |
-
# Define the Gradio interface
|
161 |
-
iface = gr.Interface(fn=analyze_audio,
|
162 |
-
inputs=[gr.Textbox(label='Training Text', placeholder='Write the text for pronunciation task', interactive=True, visible=True, show_copy_button=True,),
|
163 |
-
gr.Audio(label="Recoreded Audio", sources=['microphone', 'upload'])
|
164 |
-
],
|
165 |
-
outputs=[gr.HTML(label="Analysis of pronunciation"),
|
166 |
-
],
|
167 |
-
# css=additional_css,
|
168 |
-
# title="Audio Analysis Tool",
|
169 |
-
description="Write any text and recored an audio to predict pronunciation erors"
|
170 |
-
)
|
171 |
-
|
172 |
-
# Run the Gradio app
|
173 |
-
if __name__ == "__main__":
|
174 |
-
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|