Spaces:
Runtime error
Runtime error
Update modules/advanced.py
Browse files- modules/advanced.py +50 -8
modules/advanced.py
CHANGED
@@ -1,13 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from utils.helpers import load_content, check_spelling, check_translation, get_random_exercise
|
4 |
|
5 |
def advanced_component():
|
6 |
content = load_content()
|
7 |
|
8 |
-
with gr.
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from utils.helpers import load_content, check_spelling, check_translation, get_random_exercise, check_reading_answer
|
|
|
3 |
|
4 |
def advanced_component():
|
5 |
content = load_content()
|
6 |
|
7 |
+
with gr.Column() as advanced:
|
8 |
+
# Vocabulary Section
|
9 |
+
with gr.Tab("Vocabulary"):
|
10 |
+
gr.Markdown("### Advanced Vocabulary")
|
11 |
+
word_display = gr.Textbox(label="Afrikaans Word")
|
12 |
+
translation_hidden = gr.Textbox(visible=False)
|
13 |
+
sentence_display = gr.Textbox(label="Example Sentence")
|
14 |
+
user_translation = gr.Textbox(label="Your Translation")
|
15 |
+
check_btn = gr.Button("Check")
|
16 |
+
result = gr.Textbox(label="Result")
|
17 |
+
next_btn = gr.Button("Next Word")
|
18 |
+
|
19 |
+
def get_vocab():
|
20 |
+
exercise = get_random_exercise("vocabulary", "advanced")
|
21 |
+
return exercise["word"], exercise["translation"], exercise["sentence"]
|
22 |
+
|
23 |
+
def check_vocab(user_input, correct):
|
24 |
+
return "Correct! β" if check_translation(user_input, correct) else "Try again"
|
25 |
+
|
26 |
+
next_btn.click(fn=get_vocab, outputs=[word_display, translation_hidden, sentence_display])
|
27 |
+
check_btn.click(fn=check_vocab, inputs=[user_translation, translation_hidden], outputs=[result])
|
28 |
+
|
29 |
+
# Grammar Section
|
30 |
+
with gr.Tab("Grammar"):
|
31 |
+
gr.Markdown("### Advanced Grammar")
|
32 |
+
for rule in content["grammar"]["advanced"]:
|
33 |
+
with gr.Accordion(rule["rule"], open=False):
|
34 |
+
gr.Markdown(rule["explanation"])
|
35 |
+
|
36 |
+
# Reading Section
|
37 |
+
with gr.Tab("Reading"):
|
38 |
+
gr.Markdown("### Advanced Reading")
|
39 |
+
for text in content["reading"]["advanced"]:
|
40 |
+
with gr.Accordion(text["title"], open=False):
|
41 |
+
gr.Markdown(text["text"])
|
42 |
+
for i, question in enumerate(text["questions"]):
|
43 |
+
gr.Markdown(f"**Question {i+1}:** {question}")
|
44 |
+
answer = gr.Textbox(label="Your Answer")
|
45 |
+
result = gr.Textbox(label="Result")
|
46 |
+
check_btn = gr.Button(f"Check Answer {i+1}")
|
47 |
+
|
48 |
+
check_btn.click(
|
49 |
+
fn=lambda ans, idx=i, txt=text: "Correct! β"
|
50 |
+
if check_reading_answer(ans, idx, txt) else "Try again",
|
51 |
+
inputs=[answer],
|
52 |
+
outputs=[result]
|
53 |
+
)
|
54 |
+
|
55 |
+
return advanced
|