MK-316 commited on
Commit
321cc44
·
verified ·
1 Parent(s): 289f46c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +119 -0
app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+
4
+ # IPA features dictionary with full feature names
5
+ ipa_features = {
6
+ 'p': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
7
+ 'b': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
8
+ 't': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
9
+ 'd': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
10
+ 'k': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
11
+ 'g': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
12
+ 'tʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'voice': '-'},
13
+ 'dʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'voice': '+'},
14
+ 'f': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
15
+ 'v': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
16
+ 'θ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
17
+ 'ð': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
18
+ 's': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
19
+ 'z': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
20
+ 'ʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
21
+ 'ʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
22
+ 'h': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '-'},
23
+ 'm': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
24
+ 'n': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
25
+ 'ŋ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
26
+ 'l': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '+', 'delayed release': '-', 'voice': '+'},
27
+ 'r': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
28
+ 'j': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'},
29
+ 'w': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'voice': '+'}
30
+ }
31
+
32
+ # Variables to keep track of progress
33
+ score = 0
34
+ attempts = 0
35
+ completed_symbols = set()
36
+ current_symbol = None
37
+ remaining_features = []
38
+ current_feature = None
39
+
40
+ # Function to start or reset the quiz
41
+ def start_quiz():
42
+ global score, attempts, completed_symbols, current_symbol, remaining_features, current_feature
43
+ score = 0
44
+ attempts = 0
45
+ completed_symbols = set()
46
+ current_symbol, remaining_features = select_new_symbol()
47
+ current_feature = remaining_features.pop(0)
48
+ return (f"Practicing with /{current_symbol}/ sound. "
49
+ f"Does the '{current_feature}' feature of /{current_symbol}/ have a positive or negative value?"), "", f"Score: {score}", f"Attempts: {attempts}"
50
+
51
+ # Function to select a new symbol that hasn't been completed yet
52
+ def select_new_symbol():
53
+ available_symbols = [symbol for symbol in ipa_features if symbol not in completed_symbols]
54
+ if not available_symbols:
55
+ return None, [] # No symbols left to practice
56
+ symbol = random.choice(available_symbols)
57
+ features = list(ipa_features[symbol].keys())
58
+ return symbol, features
59
+
60
+ # Function to handle answer checking and feedback
61
+ def check_answer(user_choice):
62
+ global score, attempts, completed_symbols, current_symbol, remaining_features, current_feature
63
+ correct_value = ipa_features[current_symbol][current_feature]
64
+ attempts += 1
65
+ if user_choice == correct_value:
66
+ score += 1
67
+ feedback = "Correct!"
68
+ else:
69
+ feedback = "Incorrect!"
70
+
71
+ # Check if there are more features for the current symbol
72
+ if remaining_features:
73
+ next_feature_text = "Click 'Next Feature' to continue."
74
+ else:
75
+ completed_symbols.add(current_symbol)
76
+ next_feature_text = "Click 'Next Symbol' to continue." if select_new_symbol()[0] else "You've completed all symbols!"
77
+
78
+ return feedback, f"Score: {score}", f"Attempts: {attempts}", next_feature_text
79
+
80
+ # Function to load the next feature or symbol
81
+ def load_next():
82
+ global current_symbol, remaining_features, current_feature
83
+ if remaining_features:
84
+ current_feature = remaining_features.pop(0)
85
+ return (f"Practicing with /{current_symbol}/ sound. "
86
+ f"Does the '{current_feature}' feature of /{current_symbol}/ have a positive or negative value?"), ""
87
+ else:
88
+ current_symbol, remaining_features = select_new_symbol()
89
+ if current_symbol:
90
+ current_feature = remaining_features.pop(0)
91
+ return (f"Practicing with /{current_symbol}/ sound. "
92
+ f"Does the '{current_feature}' feature of /{current_symbol}/ have a positive or negative value?"), ""
93
+ else:
94
+ return "You've completed all symbols!", ""
95
+
96
+ # Gradio Interface
97
+ with gr.Blocks() as quiz_app:
98
+ # Start Button
99
+ start_button = gr.Button("Start/Reset Quiz")
100
+ question_text = gr.Markdown()
101
+ feedback_text = gr.Markdown()
102
+ score_text = gr.Markdown()
103
+ attempts_text = gr.Markdown()
104
+
105
+ # Answer Buttons
106
+ positive_button = gr.Button("+Feature")
107
+ negative_button = gr.Button("-Feature")
108
+
109
+ # Next Button
110
+ next_button = gr.Button("Next Feature/Symbol")
111
+
112
+ # Set up button actions
113
+ start_button.click(start_quiz, outputs=[question_text, feedback_text, score_text, attempts_text])
114
+ positive_button.click(lambda: check_answer('+'), outputs=[feedback_text, score_text, attempts_text, question_text])
115
+ negative_button.click(lambda: check_answer('-'), outputs=[feedback_text, score_text, attempts_text, question_text])
116
+ next_button.click(load_next, outputs=[question_text, feedback_text])
117
+
118
+ # Launch the app
119
+ quiz_app.launch()