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