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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -20
app.py CHANGED
@@ -1,49 +1,67 @@
 
 
 
 
 
 
1
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
2
- def teacher_question():
3
- question = input("Enter your question: ")
4
  return question
5
 
6
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
7
  def record_student_voice(student_name, question, voice):
8
- # μŒμ„± 파일 μ €μž₯
9
  file_path = f"recordings/{student_name}_{question}.wav"
10
  os.makedirs("recordings", exist_ok=True)
11
  with open(file_path, "wb") as f:
12
  f.write(voice)
13
-
14
- # μŒμ„± 파일 경둜 μ €μž₯
15
  if question in recordings:
16
  recordings[question].append(file_path)
17
  else:
18
  recordings[question] = [file_path]
19
-
20
  return "Voice recorded successfully!"
21
 
22
  # μ €μž₯된 μŒμ„± μž¬μƒ
23
  def play_recorded_voice(question):
24
  if question in recordings:
25
- print("Available recordings:")
26
- for index, file_path in enumerate(recordings[question], start=1):
27
- print(f"{index}. {file_path}")
28
  else:
29
- print("No recordings available for this question.")
30
 
31
  # μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
32
  def write_comment(question, comment):
33
  # μ½”λ©˜νŠΈ μ €μž₯ λ“±μ˜ 좔가적인 μž‘μ—… μˆ˜ν–‰ κ°€λŠ₯
34
  return f"Comment '{comment}' added successfully for question '{question}'."
35
 
 
 
 
 
 
 
 
36
 
37
- # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯
38
- question = teacher_question()
 
 
 
 
39
 
40
- # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
41
- student_name = input("Enter your name: ")
42
- record_student_voice(student_name, question, b"Dummy voice data")
 
 
 
43
 
44
- # μ €μž₯된 μŒμ„± μž¬μƒ
45
- play_recorded_voice(question)
 
 
 
 
46
 
47
- # μ½”λ©˜νŠΈ μž‘μ„±
48
- comment = input("Write your comment: ")
49
- write_comment(question, comment)
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ # μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
5
+ recordings = {}
6
+
7
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
8
+ def teacher_question(question):
 
9
  return question
10
 
11
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
12
  def record_student_voice(student_name, question, voice):
 
13
  file_path = f"recordings/{student_name}_{question}.wav"
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
  # μ €μž₯된 μŒμ„± μž¬μƒ
26
  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
+ )
65
 
66
+ # Gradio μ•± μ‹€ν–‰
67
+ gr.TabbedInterface([question_interface, record_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "Play Voices", "Write Comment"]).launch()