seba3y commited on
Commit
5e1bbb9
1 Parent(s): 36b6d5c

Delete app.py

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