jinggujiwoo7 commited on
Commit
17411ab
β€’
1 Parent(s): fc94876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -33
app.py CHANGED
@@ -7,7 +7,7 @@ comments = {}
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
10
- return question
11
 
12
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
  def record_student_voice(student_name, question, voice):
@@ -40,40 +40,42 @@ def write_comment(question, comment):
40
  return f"Comment '{comment}' added successfully for question '{question}'."
41
 
42
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
43
- question_interface = gr.Interface(
44
- fn=teacher_question,
45
- inputs=gr.Textbox(lines=2, placeholder="Enter your question here...", label="Teacher's Question"),
46
- outputs="text",
47
- title="Teacher's Question Input"
48
- )
49
 
50
- record_interface = gr.Interface(
51
- fn=record_student_voice,
52
- inputs=[gr.Textbox(placeholder="Your name"), gr.Textbox(placeholder="Question"), gr.Audio(type="filepath")],
53
- outputs="text",
54
- title="Record Your Voice"
55
- )
56
 
57
- list_interface = gr.Interface(
58
- fn=get_recorded_list,
59
- inputs=gr.Textbox(placeholder="Question"),
60
- outputs=gr.Dropdown(label="Select a recording to play"),
61
- title="List Recorded Voices"
62
- )
 
63
 
64
- play_interface = gr.Interface(
65
- fn=lambda file_path: file_path,
66
- inputs=gr.Dropdown(label="Select a recording to play"),
67
- outputs=gr.Audio(type="filepath"),
68
- title="Play Selected Voice"
69
- )
70
 
71
- comment_interface = gr.Interface(
72
- fn=write_comment,
73
- inputs=[gr.Textbox(placeholder="Question"), gr.Textbox(placeholder="Your comment")],
74
- outputs="text",
75
- title="Write Comment"
76
- )
77
 
78
- # Gradio μ•± μ‹€ν–‰
79
- gr.TabbedInterface([question_interface, record_interface, list_interface, play_interface, comment_interface], ["Teacher's Question", "Record Voice", "List Voices", "Play Voice", "Write Comment"]).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # μ„ μƒλ‹˜μ˜ 질문 μž…λ ₯ λ°›κΈ°
9
  def teacher_question(question):
10
+ return question, gr.update(value=question)
11
 
12
  # ν•™μƒλ“€μ˜ μŒμ„± λ…ΉμŒ 및 μ €μž₯
13
  def record_student_voice(student_name, question, voice):
 
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
 
60
+ gr.Textbox.update(question_display, value=state_question)
 
 
 
 
 
61
 
62
+ with gr.Tab("List Voices"):
63
+ question_list_input = gr.Textbox(placeholder="Question", label="Enter question to list recordings")
64
+ submit_list = gr.Button("Get Recordings")
65
+ recordings_list = gr.Dropdown(label="Select a recording to play")
66
+ submit_list.click(get_recorded_list, inputs=question_list_input, outputs=recordings_list)
 
67
 
68
+ with gr.Tab("Play Voice"):
69
+ recording_select = gr.Dropdown(label="Select a recording to play")
70
+ play_audio = gr.Audio(type="filepath", label="Recorded Voice")
71
+ recordings_list.change(lambda x: x, inputs=recordings_list, outputs=recording_select)
72
+ recording_select.change(lambda x: x, inputs=recording_select, outputs=play_audio)
73
+
74
+ with gr.Tab("Write Comment"):
75
+ comment_question_input = gr.Textbox(placeholder="Question", label="Question")
76
+ comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
77
+ submit_comment = gr.Button("Submit Comment")
78
+ output_comment = gr.Textbox(label="Status")
79
+ submit_comment.click(write_comment, inputs=[comment_question_input, comment_input], outputs=output_comment)
80
+
81
+ demo.launch()