import gradio as gr # 저장된 음성 파일을 관리하는 딕셔너리 recordings = {} # 저장된 답글을 관리하는 딕셔너리 comments = {} # 선생님의 질문 입력 받기 def teacher_question(question): global submitted_question submitted_question = question return "", question # 학생들의 음성 녹음 및 저장 def record_student_voice(question, voice): global recordings if question in recordings: recordings[question].append(voice) else: recordings[question] = [voice] return "Voice recorded successfully!" # 답글 작성 def write_comment(question, comment): global comments if question in comments: comments[question].append(comment) else: comments[question] = [comment] return "Comment added successfully!" # 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") submit_question.click(teacher_question, inputs=question_input, outputs=[output_question]) with gr.Tab("Record Voice"): question_select = gr.Dropdown(label="Select a question to record voice") 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(record_student_voice, inputs=[question_select, voice_input], outputs=output_voice) with gr.Tab("Write Comment"): comment_question_input = gr.Dropdown(label="Select a question to write comment") 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) def update_question_select(question): question_select.choices = [question] def update_comment_select(question): comment_question_input.choices = [question] demo.load(update_question_select, inputs=output_question) demo.load(update_comment_select, inputs=output_question) demo.launch()