Spaces:
Sleeping
Sleeping
jinggujiwoo7
commited on
Commit
•
80164bf
1
Parent(s):
506fabe
Update app.py
Browse files
app.py
CHANGED
@@ -38,109 +38,15 @@ def pronunciation_correction(expected_text, file_info):
|
|
38 |
|
39 |
return feedback, description
|
40 |
|
41 |
-
def grammar_check(sentence):
|
42 |
-
# Example implementation of a grammar checker function
|
43 |
-
# Ideally, you would use a grammar checking API or tool
|
44 |
-
# This is a placeholder to show the structure
|
45 |
-
if not sentence.endswith("."):
|
46 |
-
return "Sentence should end with a period."
|
47 |
-
if len(sentence.split()) < 3:
|
48 |
-
return "Sentence is too short. Please provide more details."
|
49 |
-
return "No grammar issues found."
|
50 |
-
|
51 |
-
with gr.Blocks() as app:
|
52 |
-
with gr.Column():
|
53 |
-
text_input = gr.Textbox(label="Type your sentence here", lines=5, placeholder="Type here...")
|
54 |
-
grammar_check_button = gr.Button("Check Grammar")
|
55 |
-
grammar_feedback = gr.Textbox(label="Grammar Feedback", interactive=False)
|
56 |
-
|
57 |
-
audio_input = gr.Audio(label="Upload Audio File", type="numpy")
|
58 |
-
check_pronunciation_button = gr.Button("Check Pronunciation")
|
59 |
-
|
60 |
-
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
|
61 |
-
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
|
62 |
-
|
63 |
-
grammar_check_button.click(
|
64 |
-
grammar_check,
|
65 |
-
inputs=text_input,
|
66 |
-
outputs=grammar_feedback
|
67 |
-
)
|
68 |
-
|
69 |
-
check_pronunciation_button.click(
|
70 |
-
pronunciation_correction,
|
71 |
-
inputs=[text_input, audio_input],
|
72 |
-
outputs=[pronunciation_feedback, pronunciation_score]
|
73 |
-
)
|
74 |
-
|
75 |
-
app.launch(debug=True)
|
76 |
-
# app.py
|
77 |
-
|
78 |
-
import gradio as gr
|
79 |
-
import speech_recognition as sr
|
80 |
-
from Levenshtein import ratio
|
81 |
-
import tempfile
|
82 |
-
import numpy as np
|
83 |
-
import soundfile as sf
|
84 |
-
|
85 |
-
def transcribe_audio(file_info):
|
86 |
-
r = sr.Recognizer()
|
87 |
-
with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as tmpfile:
|
88 |
-
sf.write(tmpfile.name, data=file_info, samplerate=44100, format='WAV')
|
89 |
-
tmpfile.seek(0)
|
90 |
-
with sr.AudioFile(tmpfile.name) as source:
|
91 |
-
audio_data = r.record(source)
|
92 |
-
try:
|
93 |
-
text = r.recognize_google(audio_data)
|
94 |
-
return text
|
95 |
-
except sr.UnknownValueError:
|
96 |
-
return "Could not understand audio"
|
97 |
-
except sr.RequestError as e:
|
98 |
-
return f"Could not request results; {e}"
|
99 |
-
|
100 |
-
def pronunciation_correction(expected_text, file_info):
|
101 |
-
user_spoken_text = transcribe_audio(file_info)
|
102 |
-
similarity = ratio(expected_text.lower(), user_spoken_text.lower())
|
103 |
-
description = f"{similarity:.2f}"
|
104 |
-
|
105 |
-
if similarity >= 0.9:
|
106 |
-
feedback = "Excellent pronunciation!"
|
107 |
-
elif similarity >= 0.7:
|
108 |
-
feedback = "Good pronunciation!"
|
109 |
-
elif similarity >= 0.5:
|
110 |
-
feedback = "Needs improvement."
|
111 |
-
else:
|
112 |
-
feedback = "Poor pronunciation, try to focus more on clarity."
|
113 |
-
|
114 |
-
return feedback, description
|
115 |
-
|
116 |
-
def grammar_check(sentence):
|
117 |
-
# Example implementation of a grammar checker function
|
118 |
-
# Ideally, you would use a grammar checking API or tool
|
119 |
-
# This is a placeholder to show the structure
|
120 |
-
if not sentence.endswith("."):
|
121 |
-
return "Sentence should end with a period."
|
122 |
-
if len(sentence.split()) < 3:
|
123 |
-
return "Sentence is too short. Please provide more details."
|
124 |
-
return "No grammar issues found."
|
125 |
-
|
126 |
with gr.Blocks() as app:
|
127 |
with gr.Column():
|
128 |
text_input = gr.Textbox(label="Type your sentence here", lines=5, placeholder="Type here...")
|
129 |
-
grammar_check_button = gr.Button("Check Grammar")
|
130 |
-
grammar_feedback = gr.Textbox(label="Grammar Feedback", interactive=False)
|
131 |
-
|
132 |
audio_input = gr.Audio(label="Upload Audio File", type="numpy")
|
133 |
check_pronunciation_button = gr.Button("Check Pronunciation")
|
134 |
|
135 |
-
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
|
136 |
-
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
|
137 |
|
138 |
-
grammar_check_button.click(
|
139 |
-
grammar_check,
|
140 |
-
inputs=text_input,
|
141 |
-
outputs=grammar_feedback
|
142 |
-
)
|
143 |
-
|
144 |
check_pronunciation_button.click(
|
145 |
pronunciation_correction,
|
146 |
inputs=[text_input, audio_input],
|
|
|
38 |
|
39 |
return feedback, description
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
with gr.Blocks() as app:
|
42 |
with gr.Column():
|
43 |
text_input = gr.Textbox(label="Type your sentence here", lines=5, placeholder="Type here...")
|
|
|
|
|
|
|
44 |
audio_input = gr.Audio(label="Upload Audio File", type="numpy")
|
45 |
check_pronunciation_button = gr.Button("Check Pronunciation")
|
46 |
|
47 |
+
pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback", interactive=False)
|
48 |
+
pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)", interactive=False)
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
check_pronunciation_button.click(
|
51 |
pronunciation_correction,
|
52 |
inputs=[text_input, audio_input],
|