jinggujiwoo7 commited on
Commit
51fc0a6
β€’
1 Parent(s): 25a98f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -12,15 +12,19 @@ def record_and_submit_voice(student_name, voice):
12
  recordings[student_name].append({"voice": voice, "comments": []})
13
  return f"Voice recorded and submitted successfully by {student_name}!"
14
 
15
- # λ…ΉμŒ 선택
16
  def get_student_recordings():
17
  return list(recordings.keys())
18
 
19
- # λ…ΉμŒλœ μŒμ„± μž¬μƒ
20
  def play_recording(selected_student):
21
  if selected_student not in recordings:
22
- return [], []
23
- return [rec["voice"] for rec in recordings[selected_student]], recordings[selected_student][0]["comments"]
 
 
 
 
24
 
25
  # λŒ“κΈ€ μž‘μ„±
26
  def write_comment(selected_student, commenter_name, comment):
@@ -30,25 +34,25 @@ def write_comment(selected_student, commenter_name, comment):
30
  return "Please enter your name."
31
  if not comment:
32
  return "Please enter a comment."
33
- recordings[selected_student][0]["comments"].append(f"{commenter_name}: {comment}")
34
  return f"Comment added successfully by {commenter_name}!"
35
 
36
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
37
  with gr.Blocks() as app:
38
  with gr.Tab("Record Voice"):
39
  student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
40
- voice_input = gr.Audio(source="microphone", type="numpy", label="Record your voice")
41
  submit_voice_button = gr.Button("Submit Voice")
42
  voice_output = gr.Textbox(label="Status")
43
 
44
  submit_voice_button.click(
45
- record_and_submit_voice,
46
- inputs=[student_name_input, voice_input],
47
  outputs=voice_output
48
  )
49
 
50
  with gr.Tab("Listen and Comment"):
51
- student_selector = gr.Dropdown(choices=get_student_recordings, label="Select a student to listen")
52
  play_voice_button = gr.Button("Play Voice")
53
  recording_output = gr.Audio(label="Selected Recording", interactive=False)
54
  comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
@@ -58,14 +62,14 @@ with gr.Blocks() as app:
58
  comments_display = gr.Textbox(label="Comments", interactive=False)
59
 
60
  play_voice_button.click(
61
- play_recording,
62
- inputs=student_selector,
63
  outputs=[recording_output, comments_display]
64
  )
65
 
66
  submit_comment_button.click(
67
- write_comment,
68
- inputs=[student_selector, commenter_name_input, comment_input],
69
  outputs=comment_status_output
70
  )
71
 
 
12
  recordings[student_name].append({"voice": voice, "comments": []})
13
  return f"Voice recorded and submitted successfully by {student_name}!"
14
 
15
+ # 학생 λͺ©λ‘ κ°€μ Έμ˜€κΈ°
16
  def get_student_recordings():
17
  return list(recordings.keys())
18
 
19
+ # λ…ΉμŒλœ μŒμ„± μž¬μƒ 및 λŒ“κΈ€ κ°€μ Έμ˜€κΈ°
20
  def play_recording(selected_student):
21
  if selected_student not in recordings:
22
+ return [], "No recordings found for this student."
23
+ voices = [rec["voice"] for rec in recordings[selected_student]]
24
+ comments = "\n".join(
25
+ [f"{c[0]}: {c[1]}" for rec in recordings[selected_student] for c in rec["comments"]]
26
+ )
27
+ return voices[0] if voices else None, comments
28
 
29
  # λŒ“κΈ€ μž‘μ„±
30
  def write_comment(selected_student, commenter_name, comment):
 
34
  return "Please enter your name."
35
  if not comment:
36
  return "Please enter a comment."
37
+ recordings[selected_student][0]["comments"].append((commenter_name, comment))
38
  return f"Comment added successfully by {commenter_name}!"
39
 
40
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
41
  with gr.Blocks() as app:
42
  with gr.Tab("Record Voice"):
43
  student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
44
+ voice_input = gr.Audio(type="filepath", label="Record your voice")
45
  submit_voice_button = gr.Button("Submit Voice")
46
  voice_output = gr.Textbox(label="Status")
47
 
48
  submit_voice_button.click(
49
+ record_and_submit_voice,
50
+ inputs=[student_name_input, voice_input],
51
  outputs=voice_output
52
  )
53
 
54
  with gr.Tab("Listen and Comment"):
55
+ student_selector = gr.Dropdown(choices=get_student_recordings(), label="Select a student to listen", interactive=True)
56
  play_voice_button = gr.Button("Play Voice")
57
  recording_output = gr.Audio(label="Selected Recording", interactive=False)
58
  comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
 
62
  comments_display = gr.Textbox(label="Comments", interactive=False)
63
 
64
  play_voice_button.click(
65
+ play_recording,
66
+ inputs=student_selector,
67
  outputs=[recording_output, comments_display]
68
  )
69
 
70
  submit_comment_button.click(
71
+ write_comment,
72
+ inputs=[student_selector, commenter_name_input, comment_input],
73
  outputs=comment_status_output
74
  )
75