Spaces:
Running
Running
Create app.py
Browse files
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 |
+
# Function to select a random symbol
|
| 33 |
+
def start_quiz():
|
| 34 |
+
random_symbol = random.choice(list(ipa_features.keys()))
|
| 35 |
+
return random_symbol # Return only the IPA symbol, not the features
|
| 36 |
+
|
| 37 |
+
# Function to validate user's answers against the actual features
|
| 38 |
+
def validate_features(symbol, user_syllabic, user_consonantal, user_sonorant, user_coronal, user_anterior, user_continuant, user_nasal, user_strident, user_lateral, user_delayed_release, user_voice):
|
| 39 |
+
correct_features = ipa_features[symbol]
|
| 40 |
+
user_answers = {
|
| 41 |
+
'syllabic': user_syllabic,
|
| 42 |
+
'consonantal': user_consonantal,
|
| 43 |
+
'sonorant': user_sonorant,
|
| 44 |
+
'coronal': user_coronal,
|
| 45 |
+
'anterior': user_anterior,
|
| 46 |
+
'continuant': user_continuant,
|
| 47 |
+
'nasal': user_nasal,
|
| 48 |
+
'strident': user_strident,
|
| 49 |
+
'lateral': user_lateral,
|
| 50 |
+
'delayed release': user_delayed_release,
|
| 51 |
+
'voice': user_voice
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
# Compare user answers with correct answers and format the result
|
| 55 |
+
result = []
|
| 56 |
+
correctness = []
|
| 57 |
+
incorrect_count = 0
|
| 58 |
+
for feature, value in correct_features.items():
|
| 59 |
+
user_value = user_answers[feature]
|
| 60 |
+
if user_value == value:
|
| 61 |
+
correctness.append("Correct")
|
| 62 |
+
else:
|
| 63 |
+
correctness.append("Incorrect")
|
| 64 |
+
incorrect_count += 1
|
| 65 |
+
result.append(f"{value}{feature}")
|
| 66 |
+
|
| 67 |
+
# Format the result in the format /m/: [+syllabic, +consonantal, -sonorant...]
|
| 68 |
+
formatted_result = f"/{symbol}/: [{', '.join(result)}]"
|
| 69 |
+
formatted_correctness = f"{incorrect_count} Incorrect answers. {correctness}"
|
| 70 |
+
|
| 71 |
+
return formatted_result, formatted_correctness
|
| 72 |
+
|
| 73 |
+
# Gradio app
|
| 74 |
+
def interface():
|
| 75 |
+
with gr.Blocks() as app:
|
| 76 |
+
gr.Markdown("### IPA Feature Marking Quiz")
|
| 77 |
+
|
| 78 |
+
# Start button to display a new symbol
|
| 79 |
+
start_button = gr.Button("Start Quiz")
|
| 80 |
+
symbol_display = gr.Textbox(label="IPA Symbol", interactive=False)
|
| 81 |
+
|
| 82 |
+
# Feature selection buttons (user clicks either + or - for each feature)
|
| 83 |
+
user_syllabic = gr.Radio(label="Syllabic", choices=['+', '-'])
|
| 84 |
+
user_consonantal = gr.Radio(label="Consonantal", choices=['+', '-'])
|
| 85 |
+
user_sonorant = gr.Radio(label="Sonorant", choices=['+', '-'])
|
| 86 |
+
user_coronal = gr.Radio(label="Coronal", choices=['+', '-'])
|
| 87 |
+
user_anterior = gr.Radio(label="Anterior", choices=['+', '-'])
|
| 88 |
+
user_continuant = gr.Radio(label="Continuant", choices=['+', '-'])
|
| 89 |
+
user_nasal = gr.Radio(label="Nasal", choices=['+', '-'])
|
| 90 |
+
user_strident = gr.Radio(label="Strident", choices=['+', '-'])
|
| 91 |
+
user_lateral = gr.Radio(label="Lateral", choices=['+', '-'])
|
| 92 |
+
user_delayed_release = gr.Radio(label="Delayed Release", choices=['+', '-'])
|
| 93 |
+
user_voice = gr.Radio(label="Voice", choices=['+', '-'])
|
| 94 |
+
|
| 95 |
+
# Submit button to validate the answers
|
| 96 |
+
submit_button = gr.Button("Submit")
|
| 97 |
+
|
| 98 |
+
# Output area to display the result
|
| 99 |
+
output_result = gr.Textbox(label="Result (Features)", interactive=False)
|
| 100 |
+
output_correctness = gr.Textbox(label="Correctness", interactive=False)
|
| 101 |
+
|
| 102 |
+
# Event handlers
|
| 103 |
+
start_button.click(
|
| 104 |
+
fn=start_quiz,
|
| 105 |
+
inputs=[],
|
| 106 |
+
outputs=[symbol_display]
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
submit_button.click(
|
| 110 |
+
fn=validate_features,
|
| 111 |
+
inputs=[symbol_display, user_syllabic, user_consonantal, user_sonorant, user_coronal, user_anterior, user_continuant, user_nasal, user_strident, user_lateral, user_delayed_release, user_voice],
|
| 112 |
+
outputs=[output_result, output_correctness]
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
return app
|
| 116 |
+
|
| 117 |
+
# Launch the app
|
| 118 |
+
app = interface()
|
| 119 |
+
app.launch()
|