codingchobo / app.py
jinggujiwoo7's picture
Update app.py
7f4441c verified
raw
history blame
2.22 kB
import gradio as gr
import os
# μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
recordings = {}
# μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
def teacher_question(question):
return 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 play_recorded_voice(question):
if question in recordings:
return recordings[question]
else:
return "No recordings available for this question."
# μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
def write_comment(question, comment):
# μ½”λ©˜νŠΈ μ €μž₯ λ“±μ˜ 좔가적인 μž‘μ—… μˆ˜ν–‰ κ°€λŠ₯
return f"Comment '{comment}' added successfully for question '{question}'."
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
question_interface = gr.Interface(
fn=teacher_question,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
outputs="text",
title="Teacher's Question Input"
)
record_interface = gr.Interface(
fn=record_student_voice,
inputs=[gr.inputs.Textbox(placeholder="Your name"), gr.inputs.Textbox(placeholder="Question"), gr.inputs.Audio(source="microphone", type="file")],
outputs="text",
title="Record Your Voice"
)
play_interface = gr.Interface(
fn=play_recorded_voice,
inputs=gr.inputs.Textbox(placeholder="Question"),
outputs=gr.outputs.Audio(type="file", label="Recorded Voices"),
title="Play Recorded Voices"
)
comment_interface = gr.Interface(
fn=write_comment,
inputs=[gr.inputs.Textbox(placeholder="Question"), gr.inputs.Textbox(placeholder="Your comment")],
outputs="text",
title="Write Comment"
)
# Gradio μ•± μ‹€ν–‰
gr.TabbedInterface([question_interface, record_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "Play Voices", "Write Comment"]).launch()