jinggujiwoo7 commited on
Commit
cbfbd5b
β€’
1 Parent(s): 45b9570

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -34
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import gradio as gr
2
 
3
- # μ €μž₯된 μŒμ„± νŒŒμΌμ„ κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
4
- recordings = {}
5
- # μ €μž₯된 닡글을 κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
6
- comments = {}
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
@@ -12,22 +10,23 @@ def teacher_question(question):
12
  return "", question
13
 
14
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
15
- def record_student_voice(question, voice):
16
- global recordings
17
- if question in recordings:
18
- recordings[question].append(voice)
 
 
 
 
19
  else:
20
- recordings[question] = [voice]
21
- return "Voice recorded successfully!"
22
-
23
- # λ‹΅κΈ€ μž‘μ„±
24
- def write_comment(question, comment):
25
- global comments
26
- if question in comments:
27
- comments[question].append(comment)
28
  else:
29
- comments[question] = [comment]
30
- return "Comment added successfully!"
31
 
32
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
33
  with gr.Blocks() as demo:
@@ -38,26 +37,14 @@ with gr.Blocks() as demo:
38
  submit_question.click(teacher_question, inputs=question_input, outputs=[output_question])
39
 
40
  with gr.Tab("Record Voice"):
41
- question_select = gr.Dropdown(label="Select a question to record voice")
42
  voice_input = gr.Audio(type="numpy", label="Record your voice")
43
  submit_voice = gr.Button("Submit Voice")
44
  output_voice = gr.Textbox(label="Status")
45
- submit_voice.click(record_student_voice, inputs=[question_select, voice_input], outputs=output_voice)
46
-
47
- with gr.Tab("Write Comment"):
48
- comment_question_input = gr.Dropdown(label="Select a question to write comment")
49
- comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
50
- submit_comment = gr.Button("Submit Comment")
51
- output_comment = gr.Textbox(label="Status")
52
- submit_comment.click(write_comment, inputs=[comment_question_input, comment_input], outputs=output_comment)
53
-
54
- def update_question_select(question):
55
- question_select.choices = [question]
56
 
57
- def update_comment_select(question):
58
- comment_question_input.choices = [question]
59
 
60
- demo.load(update_question_select, inputs=output_question)
61
- demo.load(update_comment_select, inputs=output_question)
62
 
63
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ # μ„ μƒλ‹˜μ΄ μž…λ ₯ν•œ μ§ˆλ¬Έμ„ μ €μž₯ν•˜λŠ” λ³€μˆ˜
4
+ submitted_question = ""
 
 
5
 
6
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
7
  def teacher_question(question):
 
10
  return "", question
11
 
12
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
+ def record_student_voice(voice):
14
+ global submitted_question
15
+ if submitted_question:
16
+ if submitted_question in recordings:
17
+ recordings[submitted_question].append(voice)
18
+ else:
19
+ recordings[submitted_question] = [voice]
20
+ return "Voice recorded successfully for question: " + submitted_question
21
  else:
22
+ return "Please submit a question first."
23
+
24
+ # μ €μž₯된 μŒμ„± λͺ©λ‘ 제곡
25
+ def get_recorded_list(question):
26
+ if question in recordings:
27
+ return recordings[question]
 
 
28
  else:
29
+ return []
 
30
 
31
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
32
  with gr.Blocks() as demo:
 
37
  submit_question.click(teacher_question, inputs=question_input, outputs=[output_question])
38
 
39
  with gr.Tab("Record Voice"):
 
40
  voice_input = gr.Audio(type="numpy", label="Record your voice")
41
  submit_voice = gr.Button("Submit Voice")
42
  output_voice = gr.Textbox(label="Status")
43
+ submit_voice.click(record_student_voice, inputs=[voice_input], outputs=output_voice)
 
 
 
 
 
 
 
 
 
 
44
 
45
+ def update_question_display(question):
46
+ output_voice.value = "Recording for question: " + question
47
 
48
+ demo.load(update_question_display, inputs=output_question)
 
49
 
50
  demo.launch()