speechfeedback / app.py
jinggujiwoo7's picture
Update app.py
51fc0a6 verified
raw
history blame
No virus
3.05 kB
import gradio as gr
# μ „μ—­ λ³€μˆ˜
recordings = {}
# μŒμ„± λ…ΉμŒ 및 μ €μž₯
def record_and_submit_voice(student_name, voice):
if not student_name:
return "Please enter your name."
if student_name not in recordings:
recordings[student_name] = []
recordings[student_name].append({"voice": voice, "comments": []})
return f"Voice recorded and submitted successfully by {student_name}!"
# 학생 λͺ©λ‘ κ°€μ Έμ˜€κΈ°
def get_student_recordings():
return list(recordings.keys())
# λ…ΉμŒλœ μŒμ„± μž¬μƒ 및 λŒ“κΈ€ κ°€μ Έμ˜€κΈ°
def play_recording(selected_student):
if selected_student not in recordings:
return [], "No recordings found for this student."
voices = [rec["voice"] for rec in recordings[selected_student]]
comments = "\n".join(
[f"{c[0]}: {c[1]}" for rec in recordings[selected_student] for c in rec["comments"]]
)
return voices[0] if voices else None, comments
# λŒ“κΈ€ μž‘μ„±
def write_comment(selected_student, commenter_name, comment):
if not selected_student or selected_student not in recordings:
return "Selected student's recording not found."
if not commenter_name:
return "Please enter your name."
if not comment:
return "Please enter a comment."
recordings[selected_student][0]["comments"].append((commenter_name, comment))
return f"Comment added successfully by {commenter_name}!"
# Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
with gr.Blocks() as app:
with gr.Tab("Record Voice"):
student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
voice_input = gr.Audio(type="filepath", label="Record your voice")
submit_voice_button = gr.Button("Submit Voice")
voice_output = gr.Textbox(label="Status")
submit_voice_button.click(
record_and_submit_voice,
inputs=[student_name_input, voice_input],
outputs=voice_output
)
with gr.Tab("Listen and Comment"):
student_selector = gr.Dropdown(choices=get_student_recordings(), label="Select a student to listen", interactive=True)
play_voice_button = gr.Button("Play Voice")
recording_output = gr.Audio(label="Selected Recording", interactive=False)
comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
commenter_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
submit_comment_button = gr.Button("Submit Comment")
comment_status_output = gr.Textbox(label="Comment Status")
comments_display = gr.Textbox(label="Comments", interactive=False)
play_voice_button.click(
play_recording,
inputs=student_selector,
outputs=[recording_output, comments_display]
)
submit_comment_button.click(
write_comment,
inputs=[student_selector, commenter_name_input, comment_input],
outputs=comment_status_output
)
# μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
app.launch()