File size: 2,404 Bytes
7f4441c
 
 
 
 
6974cbe
7f4441c
5e95e64
7f4441c
5e95e64
 
 
 
 
 
 
 
6974cbe
5e95e64
 
 
 
6974cbe
5e95e64
 
fc94876
 
5e95e64
7f4441c
5e95e64
fc94876
5e95e64
 
 
6974cbe
 
 
 
 
5e95e64
 
7f4441c
 
 
6974cbe
7f4441c
 
 
5e95e64
7f4441c
 
57a4e23
7f4441c
 
 
5e95e64
fc94876
 
6974cbe
fc94876
 
 
 
 
 
 
 
 
7f4441c
5e95e64
7f4441c
 
6974cbe
7f4441c
 
 
5e95e64
7f4441c
fc94876
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
74
75
76
77
78
79
80
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 get_recorded_list(question):
    if question in recordings:
        return recordings[question]
    else:
        return []

# μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
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"
)

list_interface = gr.Interface(
    fn=get_recorded_list,
    inputs=gr.Textbox(placeholder="Question"),
    outputs=gr.Dropdown(label="Select a recording to play"),
    title="List Recorded Voices"
)

play_interface = gr.Interface(
    fn=lambda file_path: file_path,
    inputs=gr.Dropdown(label="Select a recording to play"),
    outputs=gr.Audio(type="filepath"),
    title="Play Selected Voice"
)

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, list_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "List Voices", "Play Voice", "Write Comment"]).launch()