jinggujiwoo7 commited on
Commit
2457131
β€’
1 Parent(s): b6eca85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -19
app.py CHANGED
@@ -1,41 +1,60 @@
1
  import gradio as gr
2
 
3
  # μ „μ—­ λ³€μˆ˜
4
- question = ""
 
5
 
6
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
7
- def teacher_question(q):
8
- global question
9
- question = q
10
- return "Question submitted successfully!"
11
 
12
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
- def record_and_submit_voice(voice):
14
- global question
15
- if question:
16
- # μ—¬κΈ°μ„œ μŒμ„±μ„ μ²˜λ¦¬ν•˜κ³  μ €μž₯ν•˜λŠ” μ½”λ“œλ₯Ό μΆ”κ°€ν•˜μ„Έμš”
17
- return "Voice recorded and submitted successfully!"
 
 
 
 
 
18
  else:
19
- return "Please submit a question first."
20
 
21
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
22
  with gr.Blocks() as app:
23
- question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
24
- submit_question = gr.Button("Submit Question")
 
 
25
  voice_input = gr.Audio(type="numpy", label="Record your voice")
26
- submit_voice = gr.Button("Submit Voice")
27
- output = gr.Textbox(label="Status")
28
 
29
  @app
30
  def submit_question_handler():
31
- return teacher_question(question_input.value)
32
 
33
  @app
34
  def submit_voice_handler():
35
- return record_and_submit_voice(voice_input.value)
36
 
37
- submit_question.click(submit_question_handler, outputs=output)
38
- submit_voice.click(submit_voice_handler, outputs=output)
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
41
  app.launch()
 
1
  import gradio as gr
2
 
3
  # μ „μ—­ λ³€μˆ˜
4
+ questions = {}
5
+ recordings = {}
6
 
7
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
8
+ def submit_question(teacher_name, question):
9
+ questions[teacher_name] = question
10
+ return f"Question submitted successfully by {teacher_name}!"
 
11
 
12
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
+ def record_and_submit_voice(student_name, voice):
14
+ recordings.setdefault(student_name, []).append(voice)
15
+ return f"Voice recorded and submitted successfully by {student_name}!"
16
+
17
+ # μ½”λ©˜νŠΈ μž‘μ„±
18
+ def write_comment(student_name, teacher_name, comment):
19
+ if teacher_name in questions:
20
+ comment_list = questions.setdefault(teacher_name, [])
21
+ comment_list.append((student_name, comment))
22
+ return f"Comment added successfully by {student_name}!"
23
  else:
24
+ return "No question submitted by teacher yet!"
25
 
26
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
27
  with gr.Blocks() as app:
28
+ teacher_name_input = gr.Textbox(placeholder="Enter teacher's name", label="Teacher's Name")
29
+ question_input = gr.Textbox(placeholder="Enter your question here...", label="Teacher's Question")
30
+ submit_question_button = gr.Button("Submit Question")
31
+ student_name_input = gr.Textbox(placeholder="Enter your name", label="Your Name")
32
  voice_input = gr.Audio(type="numpy", label="Record your voice")
33
+ submit_voice_button = gr.Button("Submit Voice")
34
+ play_recording_dropdown = gr.Dropdown(label="Select recording to play")
35
 
36
  @app
37
  def submit_question_handler():
38
+ return submit_question(teacher_name_input.value, question_input.value)
39
 
40
  @app
41
  def submit_voice_handler():
42
+ return record_and_submit_voice(student_name_input.value, voice_input.value)
43
 
44
+ @app
45
+ def play_recording_handler(selected_recording):
46
+ return recordings.get(selected_recording, [])
47
+
48
+ comment_input = gr.Textbox(placeholder="Write your comment here...", label="Write Comment")
49
+ submit_comment_button = gr.Button("Submit Comment")
50
+
51
+ @app
52
+ def submit_comment_handler():
53
+ return write_comment(student_name_input.value, play_recording_dropdown.value, comment_input.value)
54
+
55
+ submit_question_button.click(submit_question_handler)
56
+ submit_voice_button.click(submit_voice_handler)
57
+ submit_comment_button.click(submit_comment_handler)
58
 
59
  # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
60
  app.launch()