|
import gradio as gr |
|
import os |
|
|
|
|
|
recordings = {} |
|
comments = {} |
|
|
|
|
|
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): |
|
if question in comments: |
|
comments[question].append(comment) |
|
else: |
|
comments[question] = [comment] |
|
|
|
return f"Comment '{comment}' added successfully for question '{question}'." |
|
|
|
|
|
question_interface = gr.Interface( |
|
fn=teacher_question, |
|
inputs=gr.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.Textbox(placeholder="Your name"), gr.Textbox(placeholder="Question"), gr.Audio(type="file")], |
|
outputs="text", |
|
title="Record Your Voice" |
|
) |
|
|
|
play_interface = gr.Interface( |
|
fn=play_recorded_voice, |
|
inputs=gr.Textbox(placeholder="Question"), |
|
outputs=gr.Audio(type="file", label="Recorded Voices", multiple=True), |
|
title="Play Recorded Voices" |
|
) |
|
|
|
comment_interface = gr.Interface( |
|
fn=write_comment, |
|
inputs=[gr.Textbox(placeholder="Question"), gr.Textbox(placeholder="Your comment")], |
|
outputs="text", |
|
title="Write Comment" |
|
) |
|
|
|
|
|
gr.TabbedInterface([question_interface, record_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "Play Voices", "Write Comment"]).launch() |
|
|