Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gtts import gTTS
|
3 |
+
import tempfile
|
4 |
+
|
5 |
+
# ํด์ฆ ๋ฌธ์ ์ ์ ํ์ง๋ฅผ ์ค์
|
6 |
+
quiz = {
|
7 |
+
"text": "NUmber 1 : What did Tom buy from the peddler?",
|
8 |
+
"options": ["A toy", "Pots and pans", "A cloth", "A packet of magic seeds"],
|
9 |
+
"answer": 3
|
10 |
+
}
|
11 |
+
|
12 |
+
# ํ
์คํธ๋ฅผ ์์ฑ์ผ๋ก ๋ณํํ์ฌ ์์ ํ์ผ์ ์ ์ฅ
|
13 |
+
def text_to_speech(text):
|
14 |
+
tts = gTTS(text)
|
15 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
|
16 |
+
tts.save(temp_file.name)
|
17 |
+
return temp_file.name
|
18 |
+
|
19 |
+
# ํด์ฆ ํจ์๋ฅผ ์ ์ํฉ๋๋ค
|
20 |
+
def quiz_function(selected_option):
|
21 |
+
correct_index = quiz["answer"]
|
22 |
+
selected_index = quiz["options"].index(selected_option)
|
23 |
+
if selected_index == correct_index:
|
24 |
+
return "์ ๋ต์
๋๋ค!"
|
25 |
+
else:
|
26 |
+
return "์ค๋ต์
๋๋ค. ๋ค์ ์๋ํด๋ณด์ธ์."
|
27 |
+
|
28 |
+
# ์ค๋์ค ํ์ผ ์์ฑ
|
29 |
+
audio_path = text_to_speech(quiz["text"])
|
30 |
+
|
31 |
+
# Gradio ์ธํฐํ์ด์ค๋ฅผ ์ค์ ํฉ๋๋ค
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
gr.Markdown("### Listening Test")
|
34 |
+
audio = gr.Audio(value=audio_path, autoplay=False, label="์ค๋์ค๋ฅผ ๋ค์ด๋ณด์ธ์")
|
35 |
+
options = gr.Radio(choices=quiz["options"], label="")
|
36 |
+
submit = gr.Button("์ ์ถ")
|
37 |
+
result = gr.Textbox(label="๊ฒฐ๊ณผ")
|
38 |
+
|
39 |
+
submit.click(fn=quiz_function, inputs=options, outputs=result)
|
40 |
+
|
41 |
+
# ์ธํฐํ์ด์ค๋ฅผ ์คํํฉ๋๋ค
|
42 |
+
demo.launch()
|