File size: 3,323 Bytes
7f4441c
 
 
 
 
6974cbe
7f4441c
5e95e64
7f4441c
17411ab
5e95e64
 
 
 
 
 
 
6974cbe
5e95e64
 
 
 
6974cbe
5e95e64
 
fc94876
 
5e95e64
7f4441c
5e95e64
fc94876
5e95e64
 
 
6974cbe
 
 
 
 
5e95e64
 
7f4441c
17411ab
 
5e95e64
17411ab
 
 
 
 
5e95e64
17411ab
 
 
 
 
 
 
fc94876
17411ab
5e95e64
17411ab
 
 
 
 
5e95e64
17411ab
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
import gradio as gr
import os

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

# μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
def teacher_question(question):
    return question, gr.update(value=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 μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
with gr.Blocks() as demo:
    state_question = gr.State()

    with gr.Tab("Teacher's Question"):
        question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
        submit_question = gr.Button("Submit")
        output_question = gr.Textbox(label="Submitted Question")
        submit_question.click(teacher_question, inputs=question_input, outputs=[output_question, state_question])

    with gr.Tab("Record Voice"):
        student_name_input = gr.Textbox(placeholder="Your name", label="Your name")
        question_display = gr.Textbox(label="Question", interactive=False)
        voice_input = gr.Audio(type="filepath", label="Record your voice")
        submit_voice = gr.Button("Submit Voice")
        output_voice = gr.Textbox(label="Status")
        submit_voice.click(record_student_voice, inputs=[student_name_input, state_question, voice_input], outputs=output_voice)

        gr.Textbox.update(question_display, value=state_question)

    with gr.Tab("List Voices"):
        question_list_input = gr.Textbox(placeholder="Question", label="Enter question to list recordings")
        submit_list = gr.Button("Get Recordings")
        recordings_list = gr.Dropdown(label="Select a recording to play")
        submit_list.click(get_recorded_list, inputs=question_list_input, outputs=recordings_list)

    with gr.Tab("Play Voice"):
        recording_select = gr.Dropdown(label="Select a recording to play")
        play_audio = gr.Audio(type="filepath", label="Recorded Voice")
        recordings_list.change(lambda x: x, inputs=recordings_list, outputs=recording_select)
        recording_select.change(lambda x: x, inputs=recording_select, outputs=play_audio)

    with gr.Tab("Write Comment"):
        comment_question_input = gr.Textbox(placeholder="Question", label="Question")
        comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
        submit_comment = gr.Button("Submit Comment")
        output_comment = gr.Textbox(label="Status")
        submit_comment.click(write_comment, inputs=[comment_question_input, comment_input], outputs=output_comment)

demo.launch()