File size: 2,305 Bytes
7f4441c
 
f96fb77
2457131
 
7f4441c
5e95e64
2457131
 
 
5e95e64
1746c02
2457131
 
 
 
 
 
 
 
 
 
c558203
2457131
c558203
7f4441c
b6eca85
2457131
 
 
 
b6eca85
2457131
 
f96fb77
b6eca85
 
2457131
b6eca85
 
 
2457131
b6eca85
2457131
 
 
 
 
 
 
 
 
 
 
 
 
 
f96fb77
 
b6eca85
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
import gradio as gr

# μ „μ—­ λ³€μˆ˜
questions = {}
recordings = {}

# μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
def submit_question(teacher_name, question):
    questions[teacher_name] = question
    return f"Question submitted successfully by {teacher_name}!"

# ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
def record_and_submit_voice(student_name, voice):
    recordings.setdefault(student_name, []).append(voice)
    return f"Voice recorded and submitted successfully by {student_name}!"

# μ½”λ©˜νŠΈ μž‘μ„±
def write_comment(student_name, teacher_name, comment):
    if teacher_name in questions:
        comment_list = questions.setdefault(teacher_name, [])
        comment_list.append((student_name, comment))
        return f"Comment added successfully by {student_name}!"
    else:
        return "No question submitted by teacher yet!"

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
with gr.Blocks() as app:
    teacher_name_input = gr.Textbox(placeholder="Enter teacher's name", label="Teacher's Name")
    question_input = gr.Textbox(placeholder="Enter your question here...", label="Teacher's Question")
    submit_question_button = gr.Button("Submit Question")
    student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
    voice_input = gr.Audio(type="numpy", label="Record your voice")
    submit_voice_button = gr.Button("Submit Voice")
    play_recording_dropdown = gr.Dropdown(label="Select recording to play")

    @app
    def submit_question_handler():
        return submit_question(teacher_name_input.value, question_input.value)

    @app
    def submit_voice_handler():
        return record_and_submit_voice(student_name_input.value, voice_input.value)

    @app
    def play_recording_handler(selected_recording):
        return recordings.get(selected_recording, [])

    comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
    submit_comment_button = gr.Button("Submit Comment")

    @app
    def submit_comment_handler():
        return write_comment(student_name_input.value, play_recording_dropdown.value, comment_input.value)

    submit_question_button.click(submit_question_handler)
    submit_voice_button.click(submit_voice_handler)
    submit_comment_button.click(submit_comment_handler)

# μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
app.launch()