jinggujiwoo7
commited on
Commit
β’
f087849
1
Parent(s):
92ea409
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
# μ μ μνλ₯Ό μ μ§νλ λ³μ
|
4 |
-
state = {"question": "", "recordings":
|
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"]
|
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"]
|
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=
|
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=
|
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 |
|