jinggujiwoo7
commited on
Commit
β’
6974cbe
1
Parent(s):
7f4441c
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
|
4 |
# μ μ₯λ μμ± νμΌκ³Ό μ½λ©νΈλ₯Ό κ΄λ¦¬νλ λμ
λ리
|
5 |
recordings = {}
|
|
|
6 |
|
7 |
# μ μλμ μ§λ¬Έ μ
λ ₯ λ°κΈ°
|
8 |
def teacher_question(question):
|
@@ -14,12 +15,12 @@ def record_student_voice(student_name, question, voice):
|
|
14 |
os.makedirs("recordings", exist_ok=True)
|
15 |
with open(file_path, "wb") as f:
|
16 |
f.write(voice)
|
17 |
-
|
18 |
if question in recordings:
|
19 |
recordings[question].append(file_path)
|
20 |
else:
|
21 |
recordings[question] = [file_path]
|
22 |
-
|
23 |
return "Voice recorded successfully!"
|
24 |
|
25 |
# μ μ₯λ μμ± μ¬μ
|
@@ -27,38 +28,42 @@ def play_recorded_voice(question):
|
|
27 |
if question in recordings:
|
28 |
return recordings[question]
|
29 |
else:
|
30 |
-
return "No recordings available for this question."
|
31 |
|
32 |
# μμ±μ λν μ½λ©νΈ μμ±
|
33 |
def write_comment(question, comment):
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
return f"Comment '{comment}' added successfully for question '{question}'."
|
36 |
|
37 |
# Gradio μΈν°νμ΄μ€ μ μ
|
38 |
question_interface = gr.Interface(
|
39 |
fn=teacher_question,
|
40 |
-
inputs=gr.
|
41 |
outputs="text",
|
42 |
title="Teacher's Question Input"
|
43 |
)
|
44 |
|
45 |
record_interface = gr.Interface(
|
46 |
fn=record_student_voice,
|
47 |
-
inputs=[gr.
|
48 |
outputs="text",
|
49 |
title="Record Your Voice"
|
50 |
)
|
51 |
|
52 |
play_interface = gr.Interface(
|
53 |
fn=play_recorded_voice,
|
54 |
-
inputs=gr.
|
55 |
-
outputs=gr.
|
56 |
title="Play Recorded Voices"
|
57 |
)
|
58 |
|
59 |
comment_interface = gr.Interface(
|
60 |
fn=write_comment,
|
61 |
-
inputs=[gr.
|
62 |
outputs="text",
|
63 |
title="Write Comment"
|
64 |
)
|
|
|
3 |
|
4 |
# μ μ₯λ μμ± νμΌκ³Ό μ½λ©νΈλ₯Ό κ΄λ¦¬νλ λμ
λ리
|
5 |
recordings = {}
|
6 |
+
comments = {}
|
7 |
|
8 |
# μ μλμ μ§λ¬Έ μ
λ ₯ λ°κΈ°
|
9 |
def teacher_question(question):
|
|
|
15 |
os.makedirs("recordings", exist_ok=True)
|
16 |
with open(file_path, "wb") as f:
|
17 |
f.write(voice)
|
18 |
+
|
19 |
if question in recordings:
|
20 |
recordings[question].append(file_path)
|
21 |
else:
|
22 |
recordings[question] = [file_path]
|
23 |
+
|
24 |
return "Voice recorded successfully!"
|
25 |
|
26 |
# μ μ₯λ μμ± μ¬μ
|
|
|
28 |
if question in recordings:
|
29 |
return recordings[question]
|
30 |
else:
|
31 |
+
return ["No recordings available for this question."]
|
32 |
|
33 |
# μμ±μ λν μ½λ©νΈ μμ±
|
34 |
def write_comment(question, comment):
|
35 |
+
if question in comments:
|
36 |
+
comments[question].append(comment)
|
37 |
+
else:
|
38 |
+
comments[question] = [comment]
|
39 |
+
|
40 |
return f"Comment '{comment}' added successfully for question '{question}'."
|
41 |
|
42 |
# Gradio μΈν°νμ΄μ€ μ μ
|
43 |
question_interface = gr.Interface(
|
44 |
fn=teacher_question,
|
45 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
|
46 |
outputs="text",
|
47 |
title="Teacher's Question Input"
|
48 |
)
|
49 |
|
50 |
record_interface = gr.Interface(
|
51 |
fn=record_student_voice,
|
52 |
+
inputs=[gr.Textbox(placeholder="Your name"), gr.Textbox(placeholder="Question"), gr.Audio(source="microphone", type="file")],
|
53 |
outputs="text",
|
54 |
title="Record Your Voice"
|
55 |
)
|
56 |
|
57 |
play_interface = gr.Interface(
|
58 |
fn=play_recorded_voice,
|
59 |
+
inputs=gr.Textbox(placeholder="Question"),
|
60 |
+
outputs=gr.Audio(type="file", label="Recorded Voices", multiple=True),
|
61 |
title="Play Recorded Voices"
|
62 |
)
|
63 |
|
64 |
comment_interface = gr.Interface(
|
65 |
fn=write_comment,
|
66 |
+
inputs=[gr.Textbox(placeholder="Question"), gr.Textbox(placeholder="Your comment")],
|
67 |
outputs="text",
|
68 |
title="Write Comment"
|
69 |
)
|