codingchobo / app.py
jinggujiwoo7's picture
Update app.py
45b9570 verified
raw
history blame
2.38 kB
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()