SmokeyBandit commited on
Commit
307cb7f
Β·
verified Β·
1 Parent(s): b5ac841

Update modules/intermediate.py

Browse files
Files changed (1) hide show
  1. modules/intermediate.py +50 -8
modules/intermediate.py CHANGED
@@ -1,13 +1,55 @@
1
  import gradio as gr
2
- import json
3
- from utils.helpers import load_content, check_spelling, check_translation, get_random_exercise
4
 
5
  def intermediate_component():
6
  content = load_content()
7
 
8
- with gr.Tabs() as tabs:
9
- # Move all intermediate-level components here (Grade 5-9)
10
- # Include vocabulary, grammar, reading, and exercises for intermediate level
11
- pass
12
-
13
- return tabs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 intermediate_component():
5
  content = load_content()
6
 
7
+ with gr.Column() as intermediate:
8
+ # Vocabulary Section
9
+ with gr.Tab("Vocabulary"):
10
+ gr.Markdown("### Intermediate 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", "intermediate")
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("### Intermediate Grammar")
32
+ for rule in content["grammar"]["intermediate"]:
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("### Intermediate Reading")
39
+ for text in content["reading"]["intermediate"]:
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 intermediate