jinggujiwoo7 commited on
Commit
6974cbe
β€’
1 Parent(s): 7f4441c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
 
4
  # μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
5
  recordings = {}
 
6
 
7
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
8
  def teacher_question(question):
@@ -14,12 +15,12 @@ def record_student_voice(student_name, question, voice):
14
  os.makedirs("recordings", exist_ok=True)
15
  with open(file_path, "wb") as f:
16
  f.write(voice)
17
-
18
  if question in recordings:
19
  recordings[question].append(file_path)
20
  else:
21
  recordings[question] = [file_path]
22
-
23
  return "Voice recorded successfully!"
24
 
25
  # μ €μž₯된 μŒμ„± μž¬μƒ
@@ -27,38 +28,42 @@ def play_recorded_voice(question):
27
  if question in recordings:
28
  return recordings[question]
29
  else:
30
- return "No recordings available for this question."
31
 
32
  # μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
33
  def write_comment(question, comment):
34
- # μ½”λ©˜νŠΈ μ €μž₯ λ“±μ˜ 좔가적인 μž‘μ—… μˆ˜ν–‰ κ°€λŠ₯
 
 
 
 
35
  return f"Comment '{comment}' added successfully for question '{question}'."
36
 
37
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
38
  question_interface = gr.Interface(
39
  fn=teacher_question,
40
- inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
41
  outputs="text",
42
  title="Teacher's Question Input"
43
  )
44
 
45
  record_interface = gr.Interface(
46
  fn=record_student_voice,
47
- inputs=[gr.inputs.Textbox(placeholder="Your name"), gr.inputs.Textbox(placeholder="Question"), gr.inputs.Audio(source="microphone", type="file")],
48
  outputs="text",
49
  title="Record Your Voice"
50
  )
51
 
52
  play_interface = gr.Interface(
53
  fn=play_recorded_voice,
54
- inputs=gr.inputs.Textbox(placeholder="Question"),
55
- outputs=gr.outputs.Audio(type="file", label="Recorded Voices"),
56
  title="Play Recorded Voices"
57
  )
58
 
59
  comment_interface = gr.Interface(
60
  fn=write_comment,
61
- inputs=[gr.inputs.Textbox(placeholder="Question"), gr.inputs.Textbox(placeholder="Your comment")],
62
  outputs="text",
63
  title="Write Comment"
64
  )
 
3
 
4
  # μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
5
  recordings = {}
6
+ comments = {}
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
 
15
  os.makedirs("recordings", exist_ok=True)
16
  with open(file_path, "wb") as f:
17
  f.write(voice)
18
+
19
  if question in recordings:
20
  recordings[question].append(file_path)
21
  else:
22
  recordings[question] = [file_path]
23
+
24
  return "Voice recorded successfully!"
25
 
26
  # μ €μž₯된 μŒμ„± μž¬μƒ
 
28
  if question in recordings:
29
  return recordings[question]
30
  else:
31
+ return ["No recordings available for this question."]
32
 
33
  # μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
34
  def write_comment(question, comment):
35
+ if question in comments:
36
+ comments[question].append(comment)
37
+ else:
38
+ comments[question] = [comment]
39
+
40
  return f"Comment '{comment}' added successfully for question '{question}'."
41
 
42
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
43
  question_interface = gr.Interface(
44
  fn=teacher_question,
45
+ inputs=gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
46
  outputs="text",
47
  title="Teacher's Question Input"
48
  )
49
 
50
  record_interface = gr.Interface(
51
  fn=record_student_voice,
52
+ inputs=[gr.Textbox(placeholder="Your name"), gr.Textbox(placeholder="Question"), gr.Audio(source="microphone", type="file")],
53
  outputs="text",
54
  title="Record Your Voice"
55
  )
56
 
57
  play_interface = gr.Interface(
58
  fn=play_recorded_voice,
59
+ inputs=gr.Textbox(placeholder="Question"),
60
+ outputs=gr.Audio(type="file", label="Recorded Voices", multiple=True),
61
  title="Play Recorded Voices"
62
  )
63
 
64
  comment_interface = gr.Interface(
65
  fn=write_comment,
66
+ inputs=[gr.Textbox(placeholder="Question"), gr.Textbox(placeholder="Your comment")],
67
  outputs="text",
68
  title="Write Comment"
69
  )