jinggujiwoo7 commited on
Commit
f087849
β€’
1 Parent(s): 92ea409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,19 +1,19 @@
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."
@@ -21,7 +21,7 @@ def record_student_voice(voice):
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."
@@ -31,26 +31,28 @@ with gr.Blocks() as demo:
31
  with gr.Tab("Teacher's Question"):
32
  question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
33
  submit_question = gr.Button("Submit")
34
- output_question = gr.Textbox(label="Submitted Question")
35
- submit_question.click(teacher_question, inputs=question_input, outputs=output_question)
36
 
37
  with gr.Tab("Record Voice"):
38
  question_display = gr.Markdown(value="Question will appear here after submission")
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.Markdown(value="Question will appear here after submission")
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
  submit_question.click(fn=update_question_display, outputs=[question_display, comment_display])
56
 
 
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"] = []
10
+ state["comments"] = []
11
  return question
12
 
13
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
14
  def record_student_voice(voice):
15
  if state["question"]:
16
+ state["recordings"].append(voice)
17
  return f"Voice recorded successfully for question: {state['question']}"
18
  else:
19
  return "Please submit a question first."
 
21
  # λŒ“κΈ€ μ €μž₯
22
  def write_comment(comment):
23
  if state["question"]:
24
+ state["comments"].append(comment)
25
  return f"Comment added successfully for question: {state['question']}"
26
  else:
27
  return "Please submit a question first."
 
31
  with gr.Tab("Teacher's Question"):
32
  question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
33
  submit_question = gr.Button("Submit")
34
+ output_question = gr.Textbox(label="Submitted Question", interactive=False)
35
+ submit_question.click(fn=teacher_question, inputs=question_input, outputs=output_question)
36
 
37
  with gr.Tab("Record Voice"):
38
  question_display = gr.Markdown(value="Question will appear here after submission")
39
+ voice_input = gr.Audio(source="microphone", type="numpy", label="Record your voice")
40
  submit_voice = gr.Button("Submit Voice")
41
  output_voice = gr.Textbox(label="Status")
42
+ submit_voice.click(fn=record_student_voice, inputs=voice_input, outputs=output_voice)
43
 
44
  with gr.Tab("Write Comment"):
45
  comment_display = gr.Markdown(value="Question will appear here after submission")
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(fn=write_comment, inputs=comment_input, outputs=output_comment)
50
 
51
+ # μ—…λ°μ΄νŠΈ ν•¨μˆ˜ μ •μ˜
52
  def update_question_display():
53
  return state["question"]
54
 
55
+ # νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ 질문 μ—…λ°μ΄νŠΈ
56
  demo.load(fn=update_question_display, outputs=[question_display, comment_display])
57
  submit_question.click(fn=update_question_display, outputs=[question_display, comment_display])
58