Spaces:
Sleeping
Sleeping
jinggujiwoo7
commited on
Commit
β’
74e03af
1
Parent(s):
e5af005
Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,73 @@
|
|
1 |
import gradio as gr
|
2 |
-
import speech_recognition as sr
|
3 |
-
from Levenshtein import ratio
|
4 |
-
import tempfile
|
5 |
-
import numpy as np
|
6 |
-
import soundfile as sf
|
7 |
-
from transformers import pipeline
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
text = r.recognize_google(audio_data)
|
21 |
-
return text
|
22 |
-
except sr.UnknownValueError:
|
23 |
-
return "Could not understand audio"
|
24 |
-
except sr.RequestError as e:
|
25 |
-
return f"Could not request results; {e}"
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
description = f"{similarity:.2f}"
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
feedback = "Needs improvement."
|
38 |
-
else:
|
39 |
-
feedback = "Poor pronunciation, try to focus more on clarity."
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
if
|
46 |
-
return "
|
47 |
-
|
48 |
-
return "
|
|
|
|
|
49 |
|
|
|
50 |
with gr.Blocks() as app:
|
51 |
-
with gr.
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
-
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
# μ μ λ³μ
|
4 |
+
recordings = {}
|
5 |
|
6 |
+
# μμ± λ
Ήμ λ° μ μ₯
|
7 |
+
def record_and_submit_voice(student_name, voice):
|
8 |
+
if not student_name:
|
9 |
+
return "Please enter your name."
|
10 |
+
if student_name not in recordings:
|
11 |
+
recordings[student_name] = []
|
12 |
+
recordings[student_name].append({"voice": voice, "comments": []})
|
13 |
+
return f"Voice recorded and submitted successfully by {student_name}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# λ
Ήμ μ ν
|
16 |
+
def get_student_recordings():
|
17 |
+
return list(recordings.keys())
|
|
|
18 |
|
19 |
+
# λ
Ήμλ μμ± μ¬μ
|
20 |
+
def play_recording(selected_student):
|
21 |
+
if selected_student not in recordings:
|
22 |
+
return [], []
|
23 |
+
return [rec["voice"] for rec in recordings[selected_student]], recordings[selected_student][0]["comments"]
|
|
|
|
|
|
|
24 |
|
25 |
+
# λκΈ μμ±
|
26 |
+
def write_comment(selected_student, commenter_name, comment):
|
27 |
+
if not selected_student or selected_student not in recordings:
|
28 |
+
return "Selected student's recording not found."
|
29 |
+
if not commenter_name:
|
30 |
+
return "Please enter your name."
|
31 |
+
if not comment:
|
32 |
+
return "Please enter a comment."
|
33 |
+
recordings[selected_student][0]["comments"].append(f"{commenter_name}: {comment}")
|
34 |
+
return f"Comment added successfully by {commenter_name}!"
|
35 |
|
36 |
+
# Gradio μΈν°νμ΄μ€ μ μ
|
37 |
with gr.Blocks() as app:
|
38 |
+
with gr.Tab("Record Voice"):
|
39 |
+
student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
|
40 |
+
voice_input = gr.Audio(source="microphone", type="numpy", label="Record your voice")
|
41 |
+
submit_voice_button = gr.Button("Submit Voice")
|
42 |
+
voice_output = gr.Textbox(label="Status")
|
43 |
+
|
44 |
+
submit_voice_button.click(
|
45 |
+
record_and_submit_voice,
|
46 |
+
inputs=[student_name_input, voice_input],
|
47 |
+
outputs=voice_output
|
48 |
+
)
|
49 |
+
|
50 |
+
with gr.Tab("Listen and Comment"):
|
51 |
+
student_selector = gr.Dropdown(choices=get_student_recordings, label="Select a student to listen")
|
52 |
+
play_voice_button = gr.Button("Play Voice")
|
53 |
+
recording_output = gr.Audio(label="Selected Recording", interactive=False)
|
54 |
+
comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
|
55 |
+
commenter_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
|
56 |
+
submit_comment_button = gr.Button("Submit Comment")
|
57 |
+
comment_status_output = gr.Textbox(label="Comment Status")
|
58 |
+
comments_display = gr.Textbox(label="Comments", interactive=False)
|
59 |
|
60 |
+
play_voice_button.click(
|
61 |
+
play_recording,
|
62 |
+
inputs=student_selector,
|
63 |
+
outputs=[recording_output, comments_display]
|
64 |
+
)
|
65 |
|
66 |
+
submit_comment_button.click(
|
67 |
+
write_comment,
|
68 |
+
inputs=[student_selector, commenter_name_input, comment_input],
|
69 |
+
outputs=comment_status_output
|
70 |
+
)
|
71 |
|
72 |
+
# μΈν°νμ΄μ€ μ€ν
|
73 |
+
app.launch()
|