File size: 2,232 Bytes
7f4441c
 
 
 
 
6974cbe
7f4441c
5e95e64
7f4441c
5e95e64
 
 
 
 
 
 
 
6974cbe
5e95e64
 
 
 
6974cbe
5e95e64
 
 
 
 
7f4441c
5e95e64
6974cbe
5e95e64
 
 
6974cbe
 
 
 
 
5e95e64
 
7f4441c
 
 
6974cbe
7f4441c
 
 
5e95e64
7f4441c
 
57a4e23
7f4441c
 
 
5e95e64
7f4441c
 
6974cbe
57a4e23
7f4441c
 
5e95e64
7f4441c
 
6974cbe
7f4441c
 
 
5e95e64
7f4441c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import gradio as gr
import os

# μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
recordings = {}
comments = {}

# μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
def teacher_question(question):
    return question

# ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
def record_student_voice(student_name, question, voice):
    file_path = f"recordings/{student_name}_{question}.wav"
    os.makedirs("recordings", exist_ok=True)
    with open(file_path, "wb") as f:
        f.write(voice)

    if question in recordings:
        recordings[question].append(file_path)
    else:
        recordings[question] = [file_path]

    return "Voice recorded successfully!"

# μ €μž₯된 μŒμ„± μž¬μƒ
def play_recorded_voice(question):
    if question in recordings:
        return recordings[question]
    else:
        return ["No recordings available for this question."]

# μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
def write_comment(question, comment):
    if question in comments:
        comments[question].append(comment)
    else:
        comments[question] = [comment]
    
    return f"Comment '{comment}' added successfully for question '{question}'."

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
question_interface = gr.Interface(
    fn=teacher_question,
    inputs=gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
    outputs="text",
    title="Teacher's Question Input"
)

record_interface = gr.Interface(
    fn=record_student_voice,
    inputs=[gr.Textbox(placeholder="Your name"), gr.Textbox(placeholder="Question"), gr.Audio(type="filepath")],
    outputs="text",
    title="Record Your Voice"
)

play_interface = gr.Interface(
    fn=play_recorded_voice,
    inputs=gr.Textbox(placeholder="Question"),
    outputs=gr.Audio(type="filepath", label="Recorded Voices", multiple=True),
    title="Play Recorded Voices"
)

comment_interface = gr.Interface(
    fn=write_comment,
    inputs=[gr.Textbox(placeholder="Question"), gr.Textbox(placeholder="Your comment")],
    outputs="text",
    title="Write Comment"
)

# Gradio μ•± μ‹€ν–‰
gr.TabbedInterface([question_interface, record_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "Play Voices", "Write Comment"]).launch()