File size: 2,217 Bytes
7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c 5e95e64 7f4441c |
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 62 63 64 65 66 67 68 |
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()
|