jinggujiwoo7 commited on
Commit
a8345a1
β€’
1 Parent(s): e46bb7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -62
app.py CHANGED
@@ -1,79 +1,29 @@
1
  import gradio as gr
2
- import os
3
 
4
- # μ €μž₯된 μŒμ„± 파일과 μ½”λ©˜νŠΈλ₯Ό κ΄€λ¦¬ν•˜λŠ” λ”•μ…”λ„ˆλ¦¬
5
- recordings = {}
6
- comments = {}
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
 
 
10
  return "", question
11
 
12
- # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
- def record_student_voice(student_name, question, voice):
14
- file_path = f"recordings/{student_name}_{question}.wav"
15
- os.makedirs("recordings", exist_ok=True)
16
- with open(file_path, "wb") as f:
17
- f.write(voice)
18
-
19
- if question in recordings:
20
- recordings[question].append(file_path)
21
- else:
22
- recordings[question] = [file_path]
23
-
24
- return "Voice recorded successfully!"
25
-
26
- # μ €μž₯된 μŒμ„± λͺ©λ‘ 제곡
27
- def get_recorded_list(question):
28
- if question in recordings:
29
- return recordings[question]
30
- else:
31
- return []
32
-
33
- # μŒμ„±μ— λŒ€ν•œ μ½”λ©˜νŠΈ μž‘μ„±
34
- def write_comment(question, comment):
35
- if question in comments:
36
- comments[question].append(comment)
37
- else:
38
- comments[question] = [comment]
39
-
40
- return f"Comment '{comment}' added successfully for question '{question}'."
41
 
42
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
43
  with gr.Blocks() as demo:
44
- state_question = gr.State("")
45
-
46
  with gr.Tab("Teacher's Question"):
47
  question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
48
  submit_question = gr.Button("Submit")
49
  output_question = gr.Textbox(label="Submitted Question")
50
- submit_question.click(teacher_question, inputs=question_input, outputs=[output_question, state_question])
51
-
52
- with gr.Tab("Record Voice"):
53
- student_name_input = gr.Textbox(placeholder="Your name", label="Your name")
54
- question_display = gr.Textbox(label="Question", interactive=False)
55
- voice_input = gr.Audio(type="filepath", label="Record your voice")
56
- submit_voice = gr.Button("Submit Voice")
57
- output_voice = gr.Textbox(label="Status")
58
- submit_voice.click(record_student_voice, inputs=[student_name_input, state_question, voice_input], outputs=output_voice)
59
- demo.load(lambda question: gr.update(value=question), inputs=state_question, outputs=question_display)
60
-
61
- with gr.Tab("List Voices"):
62
- question_list_input = gr.Textbox(placeholder="Question", label="Enter question to list recordings")
63
- submit_list = gr.Button("Get Recordings")
64
- recordings_list = gr.Dropdown(label="Select a recording to play")
65
- submit_list.click(get_recorded_list, inputs=question_list_input, outputs=recordings_list)
66
-
67
- with gr.Tab("Play Voice"):
68
- recording_select = gr.Dropdown(label="Select a recording to play")
69
- play_audio = gr.Audio(type="filepath", label="Recorded Voice")
70
- recording_select.change(lambda x: x, inputs=recording_select, outputs=play_audio)
71
 
72
- with gr.Tab("Write Comment"):
73
- comment_question_input = gr.Textbox(placeholder="Question", label="Question")
74
- comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
75
- submit_comment = gr.Button("Submit Comment")
76
- output_comment = gr.Textbox(label="Status")
77
- submit_comment.click(write_comment, inputs=[comment_question_input, comment_input], outputs=output_comment)
78
 
79
  demo.launch()
 
1
  import gradio as gr
 
2
 
3
+ # μ§ˆλ¬Έμ„ μ €μž₯ν•  λ³€μˆ˜
4
+ submitted_question = ""
 
5
 
6
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
7
  def teacher_question(question):
8
+ global submitted_question
9
+ submitted_question = question
10
  return "", question
11
 
12
+ # 질문이 μ œμΆœλ˜μ—ˆμŒμ„ ν™•μΈν•˜λŠ” ν•¨μˆ˜
13
+ def check_submission():
14
+ return submitted_question
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
17
  with gr.Blocks() as demo:
 
 
18
  with gr.Tab("Teacher's Question"):
19
  question_input = gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question")
20
  submit_question = gr.Button("Submit")
21
  output_question = gr.Textbox(label="Submitted Question")
22
+ submit_question.click(teacher_question, inputs=question_input, outputs=[output_question])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ with gr.Tab("Check Submission"):
25
+ check_button = gr.Button("Check Submission")
26
+ submitted_text = gr.Textbox(label="Submitted Question")
27
+ check_button.click(check_submission, outputs=submitted_text)
 
 
28
 
29
  demo.launch()