Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
|
| 4 |
-
# μ μ₯λ μμ±
|
| 5 |
recordings = {}
|
| 6 |
-
comments = {}
|
| 7 |
|
| 8 |
# μ μλμ μ§λ¬Έ μ
λ ₯ λ°κΈ°
|
| 9 |
def teacher_question(question):
|
|
@@ -12,35 +10,14 @@ def teacher_question(question):
|
|
| 12 |
return "", question
|
| 13 |
|
| 14 |
# νμλ€μ μμ± λ
Ήμ λ° μ μ₯
|
| 15 |
-
def record_student_voice(
|
| 16 |
-
|
| 17 |
-
os.makedirs("recordings", exist_ok=True)
|
| 18 |
-
with open(file_path, "wb") as f:
|
| 19 |
-
f.write(voice)
|
| 20 |
-
|
| 21 |
if question in recordings:
|
| 22 |
-
recordings[question].append(
|
| 23 |
else:
|
| 24 |
-
recordings[question] = [
|
| 25 |
-
|
| 26 |
return "Voice recorded successfully!"
|
| 27 |
|
| 28 |
-
# μ μ₯λ μμ± λͺ©λ‘ μ 곡
|
| 29 |
-
def get_recorded_list(question):
|
| 30 |
-
if question in recordings:
|
| 31 |
-
return recordings[question]
|
| 32 |
-
else:
|
| 33 |
-
return []
|
| 34 |
-
|
| 35 |
-
# μμ±μ λν μ½λ©νΈ μμ±
|
| 36 |
-
def write_comment(question, comment):
|
| 37 |
-
if question in comments:
|
| 38 |
-
comments[question].append(comment)
|
| 39 |
-
else:
|
| 40 |
-
comments[question] = [comment]
|
| 41 |
-
|
| 42 |
-
return f"Comment '{comment}' added successfully for question '{question}'."
|
| 43 |
-
|
| 44 |
# Gradio μΈν°νμ΄μ€ μ μ
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
with gr.Tab("Teacher's Question"):
|
|
@@ -51,29 +28,10 @@ with gr.Blocks() as demo:
|
|
| 51 |
|
| 52 |
with gr.Tab("Record Voice"):
|
| 53 |
question_display = gr.Textbox(label="Question", interactive=False)
|
| 54 |
-
|
| 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=[
|
| 59 |
-
|
| 60 |
-
with gr.Tab("List Voices"):
|
| 61 |
-
question_list_input = gr.Textbox(placeholder="Question", label="Enter question to list recordings")
|
| 62 |
-
submit_list = gr.Button("Get Recordings")
|
| 63 |
-
recordings_list = gr.Dropdown(label="Select a recording to play")
|
| 64 |
-
submit_list.click(get_recorded_list, inputs=question_list_input, outputs=recordings_list)
|
| 65 |
-
|
| 66 |
-
with gr.Tab("Play Voice"):
|
| 67 |
-
recording_select = gr.Dropdown(label="Select a recording to play")
|
| 68 |
-
play_audio = gr.Audio(type="filepath", label="Recorded Voice")
|
| 69 |
-
recording_select.change(lambda x: x, inputs=recording_select, outputs=play_audio)
|
| 70 |
-
|
| 71 |
-
with gr.Tab("Write Comment"):
|
| 72 |
-
comment_question_input = gr.Textbox(placeholder="Question", label="Question")
|
| 73 |
-
comment_input = gr.Textbox(placeholder="Your comment", label="Comment")
|
| 74 |
-
submit_comment = gr.Button("Submit Comment")
|
| 75 |
-
output_comment = gr.Textbox(label="Status")
|
| 76 |
-
submit_comment.click(write_comment, inputs=[comment_question_input, comment_input], outputs=output_comment)
|
| 77 |
|
| 78 |
def update_question_display(question):
|
| 79 |
question_display.value = question
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
+
# μ μ₯λ μμ± νμΌμ κ΄λ¦¬νλ λμ
λ리
|
| 4 |
recordings = {}
|
|
|
|
| 5 |
|
| 6 |
# μ μλμ μ§λ¬Έ μ
λ ₯ λ°κΈ°
|
| 7 |
def teacher_question(question):
|
|
|
|
| 10 |
return "", question
|
| 11 |
|
| 12 |
# νμλ€μ μμ± λ
Ήμ λ° μ μ₯
|
| 13 |
+
def record_student_voice(question, voice):
|
| 14 |
+
global recordings
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if question in recordings:
|
| 16 |
+
recordings[question].append(voice)
|
| 17 |
else:
|
| 18 |
+
recordings[question] = [voice]
|
|
|
|
| 19 |
return "Voice recorded successfully!"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Gradio μΈν°νμ΄μ€ μ μ
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
with gr.Tab("Teacher's Question"):
|
|
|
|
| 28 |
|
| 29 |
with gr.Tab("Record Voice"):
|
| 30 |
question_display = gr.Textbox(label="Question", interactive=False)
|
| 31 |
+
voice_input = gr.Audio(type="numpy", label="Record your voice")
|
|
|
|
| 32 |
submit_voice = gr.Button("Submit Voice")
|
| 33 |
output_voice = gr.Textbox(label="Status")
|
| 34 |
+
submit_voice.click(record_student_voice, inputs=[question_display, voice_input], outputs=output_voice)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
def update_question_display(question):
|
| 37 |
question_display.value = question
|