MK-316 commited on
Commit
5fc9bc8
1 Parent(s): b07377c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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': '-', 'high': '-', 'voice': '-'},
7
+ 'b': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
8
+ 't': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
9
+ 'd': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
10
+ 'k': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '-'},
11
+ 'g': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'},
12
+ 'tʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'high': '-', 'voice': '-'},
13
+ 'dʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'high': '-', 'voice': '+'},
14
+ 'f': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
15
+ 'v': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
16
+ 'θ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
17
+ 'ð': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
18
+ 's': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
19
+ 'z': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
20
+ 'ʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
21
+ 'ʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
22
+ 'h': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'},
23
+ 'm': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
24
+ 'n': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'},
25
+ 'ŋ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'},
26
+ 'l': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '+', 'delayed release': '-', 'high': '-', 'voice': '+'},
27
+ 'r': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '+', 'high': '-', 'voice': '+'},
28
+ 'j': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '+', 'high': '+', 'voice': '+'},
29
+ 'w': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '+', 'high': '+', 'voice': '+'}
30
+ }
31
+
32
+ # Function to filter IPA symbols based on user selections with 'ALL' as an option
33
+ def filter_symbols(syllabic, consonantal, sonorant, coronal, anterior, continuant, nasal, strident, lateral, delayed_release, voice):
34
+ # Extract IPA symbols based on the user's selections
35
+ matching_symbols = [symbol for symbol, features in ipa_features.items()
36
+ if (syllabic == 'ALL' or features['syllabic'] == syllabic)
37
+ and (consonantal == 'ALL' or features['consonantal'] == consonantal)
38
+ and (sonorant == 'ALL' or features['sonorant'] == sonorant)
39
+ and (coronal == 'ALL' or features['coronal'] == coronal)
40
+ and (anterior == 'ALL' or features['anterior'] == anterior)
41
+ and (continuant == 'ALL' or features['continuant'] == continuant)
42
+ and (nasal == 'ALL' or features['nasal'] == nasal)
43
+ and (strident == 'ALL' or features['strident'] == strident)
44
+ and (lateral == 'ALL' or features['lateral'] == lateral)
45
+ and (delayed_release == 'ALL' or features['delayed release'] == delayed_release)
46
+ and (voice == 'ALL' or features['voice'] == voice)]
47
+
48
+ # Return the matching symbols in the format /p, b, m/
49
+ return f"/{', '.join(matching_symbols)}/" if matching_symbols else "No matching symbols."
50
+
51
+ # Define the Gradio interface using buttons
52
+ def interface():
53
+ with gr.Blocks() as app:
54
+ gr.Markdown("### IPA Symbol Finder Based on Distinctive Features")
55
+
56
+ # Button groups for user to click options for each feature
57
+ syllabic = gr.Radio(label="Syllabic", choices=['ALL', '+', '-'], value='ALL')
58
+ consonantal = gr.Radio(label="Consonantal", choices=['ALL', '+', '-'], value='ALL')
59
+ voice = gr.Radio(label="Voice", choices=['ALL', '+', '-'], value='ALL')
60
+ sonorant = gr.Radio(label="Sonorant", choices=['ALL', '+', '-'], value='ALL')
61
+ coronal = gr.Radio(label="Coronal", choices=['ALL', '+', '-'], value='ALL')
62
+ anterior = gr.Radio(label="Anterior", choices=['ALL', '+', '-'], value='ALL')
63
+ continuant = gr.Radio(label="Continuant", choices=['ALL', '+', '-'], value='ALL')
64
+ nasal = gr.Radio(label="Nasal", choices=['ALL', '+', '-'], value='ALL')
65
+ strident = gr.Radio(label="Strident", choices=['ALL', '+', '-'], value='ALL')
66
+ lateral = gr.Radio(label="Lateral", choices=['ALL', '+', '-'], value='ALL')
67
+ delayed_release = gr.Radio(label="Delayed Release", choices=['ALL', '+', '-'], value='ALL')
68
+
69
+ # Submit button
70
+ submit_button = gr.Button("Submit")
71
+
72
+ # Output area for filtered IPA symbols
73
+ output = gr.Textbox(label="Matching IPA Symbols", interactive=False)
74
+
75
+ # Connect the button to the filter function
76
+ submit_button.click(
77
+ fn=filter_symbols,
78
+ inputs=[syllabic, consonantal, sonorant, coronal, anterior, continuant, nasal, strident, lateral, delayed_release, voice],
79
+ outputs=output
80
+ )
81
+
82
+ return app
83
+
84
+ # Launch the app
85
+ app = interface()
86
+ app.launch()