File size: 2,416 Bytes
7f4441c
 
f681712
f087849
7f4441c
5e95e64
7f4441c
f681712
f087849
 
c558203
5e95e64
1746c02
cbfbd5b
f681712
f087849
f681712
1746c02
cbfbd5b
 
c558203
 
f681712
f087849
f681712
c558203
 
 
7f4441c
17411ab
 
 
 
f087849
 
17411ab
1746c02
92ea409
3d50c56
1746c02
 
f087849
c558203
 
92ea409
c558203
 
 
f087849
17411ab
f087849
f681712
 
 
f087849
f681712
92ea409
f681712
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
import gradio as gr

# μ „μ—­ μƒνƒœλ₯Ό μœ μ§€ν•˜λŠ” λ³€μˆ˜
state = {"question": "", "recordings": [], "comments": []}

# μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
def teacher_question(question):
    state["question"] = question
    state["recordings"] = []
    state["comments"] = []
    return question

# ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
def record_student_voice(voice):
    if state["question"]:
        state["recordings"].append(voice)
        return f"Voice recorded successfully for question: {state['question']}"
    else:
        return "Please submit a question first."

# λŒ“κΈ€ μ €μž₯
def write_comment(comment):
    if state["question"]:
        state["comments"].append(comment)
        return f"Comment added successfully for question: {state['question']}"
    else:
        return "Please submit a question first."

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
with gr.Blocks() as demo:
    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", interactive=False)
        submit_question.click(fn=teacher_question, inputs=question_input, outputs=output_question)

    with gr.Tab("Record Voice"):
        question_display = gr.Markdown(value="Question will appear here after submission")
        voice_input = gr.Audio(type="numpy", label="Record your voice")
        submit_voice = gr.Button("Submit Voice")
        output_voice = gr.Textbox(label="Status")
        submit_voice.click(fn=record_student_voice, inputs=voice_input, outputs=output_voice)

    with gr.Tab("Write Comment"):
        comment_display = gr.Markdown(value="Question will appear here after submission")
        comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
        submit_comment = gr.Button("Submit Comment")
        output_comment = gr.Textbox(label="Status")
        submit_comment.click(fn=write_comment, inputs=comment_input, outputs=output_comment)

    # μ—…λ°μ΄νŠΈ ν•¨μˆ˜ μ •μ˜
    def update_question_display():
        return state["question"]

    # νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ 질문 μ—…λ°μ΄νŠΈ
    demo.load(fn=update_question_display, outputs=[question_display, comment_display])
    submit_question.click(fn=update_question_display, outputs=[question_display, comment_display])

demo.launch()