jinggujiwoo7 commited on
Commit
f681712
β€’
1 Parent(s): 59a89e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,33 +1,28 @@
1
  import gradio as gr
2
 
3
- # μƒνƒœλ₯Ό κ΄€λ¦¬ν•˜λŠ” μ „μ—­ λ³€μˆ˜
4
- submitted_question = ""
5
- recordings = {}
6
- comments = {}
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
10
- global submitted_question
11
- submitted_question = question
12
- recordings[submitted_question] = []
13
- comments[submitted_question] = []
14
  return question
15
 
16
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
17
  def record_student_voice(voice):
18
- global submitted_question
19
- if submitted_question:
20
- recordings[submitted_question].append(voice)
21
- return f"Voice recorded successfully for question: {submitted_question}"
22
  else:
23
  return "Please submit a question first."
24
 
25
  # λŒ“κΈ€ μ €μž₯
26
  def write_comment(comment):
27
- global submitted_question
28
- if submitted_question:
29
- comments[submitted_question].append(comment)
30
- return f"Comment added successfully for question: {submitted_question}"
31
  else:
32
  return "Please submit a question first."
33
 
@@ -40,17 +35,22 @@ with gr.Blocks() as demo:
40
  submit_question.click(teacher_question, inputs=question_input, outputs=output_question)
41
 
42
  with gr.Tab("Record Voice"):
43
- question_display = gr.Textbox(label="Question", interactive=False, value=lambda: submitted_question)
44
  voice_input = gr.Audio(type="numpy", label="Record your voice")
45
  submit_voice = gr.Button("Submit Voice")
46
  output_voice = gr.Textbox(label="Status")
47
  submit_voice.click(record_student_voice, inputs=[voice_input], outputs=output_voice)
48
 
49
  with gr.Tab("Write Comment"):
50
- comment_display = gr.Textbox(label="Question", interactive=False, value=lambda: submitted_question)
51
  comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
52
  submit_comment = gr.Button("Submit Comment")
53
  output_comment = gr.Textbox(label="Status")
54
  submit_comment.click(write_comment, inputs=[comment_input], outputs=output_comment)
55
 
 
 
 
 
 
56
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # μ „μ—­ μƒνƒœλ₯Ό μœ μ§€ν•˜λŠ” λ³€μˆ˜
4
+ state = {"question": "", "recordings": {}, "comments": {}}
 
 
5
 
6
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
7
  def teacher_question(question):
8
+ state["question"] = question
9
+ state["recordings"][question] = []
10
+ state["comments"][question] = []
 
11
  return question
12
 
13
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
14
  def record_student_voice(voice):
15
+ if state["question"]:
16
+ state["recordings"][state["question"]].append(voice)
17
+ return f"Voice recorded successfully for question: {state['question']}"
 
18
  else:
19
  return "Please submit a question first."
20
 
21
  # λŒ“κΈ€ μ €μž₯
22
  def write_comment(comment):
23
+ if state["question"]:
24
+ state["comments"][state["question"]].append(comment)
25
+ return f"Comment added successfully for question: {state['question']}"
 
26
  else:
27
  return "Please submit a question first."
28
 
 
35
  submit_question.click(teacher_question, inputs=question_input, outputs=output_question)
36
 
37
  with gr.Tab("Record Voice"):
38
+ question_display = gr.Textbox(label="Question", interactive=False)
39
  voice_input = gr.Audio(type="numpy", label="Record your voice")
40
  submit_voice = gr.Button("Submit Voice")
41
  output_voice = gr.Textbox(label="Status")
42
  submit_voice.click(record_student_voice, inputs=[voice_input], outputs=output_voice)
43
 
44
  with gr.Tab("Write Comment"):
45
+ comment_display = gr.Textbox(label="Question", interactive=False)
46
  comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
47
  submit_comment = gr.Button("Submit Comment")
48
  output_comment = gr.Textbox(label="Status")
49
  submit_comment.click(write_comment, inputs=[comment_input], outputs=output_comment)
50
 
51
+ def update_question_display():
52
+ return state["question"]
53
+
54
+ demo.load(fn=update_question_display, outputs=[question_display, comment_display])
55
+
56
  demo.launch()