Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
# IPA Data from your original dictionary
|
5 |
+
ipa_data = {
|
6 |
+
'p': {'Voicing': 'voiceless', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
7 |
+
'b': {'Voicing': 'voiced', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
8 |
+
't': {'Voicing': 'voiceless', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
9 |
+
'd': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
10 |
+
'k': {'Voicing': 'voiceless', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
11 |
+
'g': {'Voicing': 'voiced', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'},
|
12 |
+
'f': {'Voicing': 'voiceless', 'Place': 'labio-dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
13 |
+
'v': {'Voicing': 'voiced', 'Place': 'labio-dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
14 |
+
'θ': {'Voicing': 'voiceless', 'Place': 'dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
15 |
+
'ð': {'Voicing': 'voiced', 'Place': 'dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
16 |
+
's': {'Voicing': 'voiceless', 'Place': 'alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
17 |
+
'z': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
18 |
+
'ʃ': {'Voicing': 'voiceless', 'Place': 'palato-alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
19 |
+
'ʒ': {'Voicing': 'voiced', 'Place': 'palato-alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
20 |
+
'tʃ': {'Voicing': 'voiceless', 'Place': 'palato-alveolar', 'Manner': 'affricate','Oro-nasal': '(oral)','Centrality':'(central)'},
|
21 |
+
'dʒ': {'Voicing': 'voiced', 'Place': 'palato-alveolar', 'Manner': 'affricate','Oro-nasal': '(oral)','Centrality':'(central)'},
|
22 |
+
'h': {'Voicing': 'voiceless', 'Place': 'glottal', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'},
|
23 |
+
'm': {'Voicing': 'voiced', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'},
|
24 |
+
'n': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'},
|
25 |
+
'ŋ': {'Voicing': 'voiced', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'},
|
26 |
+
'ɹ': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'},
|
27 |
+
'l': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'lateral'},
|
28 |
+
'j': {'Voicing': 'voiced', 'Place': 'palatal', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'},
|
29 |
+
'w': {'Voicing': 'voiced', 'Place': 'labio-velar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'}
|
30 |
+
}
|
31 |
+
|
32 |
+
# Function to filter IPA symbols based on user selections with 'ALL' as an option
|
33 |
+
def filter_symbols(voicing, place, manner, oronasal, centrality):
|
34 |
+
# Extract IPA symbols based on the user's selections
|
35 |
+
matching_symbols = [symbol for symbol, attributes in ipa_data.items()
|
36 |
+
if (voicing == 'ALL' or attributes['Voicing'] == voicing)
|
37 |
+
and (place == 'ALL' or attributes['Place'] == place)
|
38 |
+
and (manner == 'ALL' or attributes['Manner'] == manner)
|
39 |
+
and (oronasal == 'ALL' or attributes['Oro-nasal'] == oronasal)
|
40 |
+
and (centrality == 'ALL' or attributes['Centrality'] == centrality)]
|
41 |
+
|
42 |
+
# Return the matching symbols in the format /p, b, m/
|
43 |
+
return f"/{', '.join(matching_symbols)}/" if matching_symbols else "No matching symbols."
|
44 |
+
|
45 |
+
# Define the Gradio interface using buttons
|
46 |
+
def interface():
|
47 |
+
with gr.Blocks() as app:
|
48 |
+
gr.Markdown("### IPA Symbol Finder with Buttons and 'ALL' Option")
|
49 |
+
|
50 |
+
# Button groups for user to click options
|
51 |
+
voicing = gr.Radio(label="Voicing", choices=['ALL', 'voiceless', 'voiced'], value='ALL')
|
52 |
+
place = gr.Radio(label="Place", choices=['ALL', 'bilabial', 'labio-dental', 'labio-velar', 'dental', 'alveolar', 'palato-alveolar', 'palatal', 'velar', 'glottal'], value='ALL')
|
53 |
+
manner = gr.Radio(label="Manner", choices=['ALL', 'stop', 'fricative', 'affricate', 'approximant'], value='ALL')
|
54 |
+
oronasal = gr.Radio(label="Oro-nasal", choices=['ALL', '(oral)', 'nasal'], value='ALL')
|
55 |
+
centrality = gr.Radio(label="Centrality", choices=['ALL', '(central)', 'lateral', '(not applicable)'], value='ALL')
|
56 |
+
|
57 |
+
# Submit button
|
58 |
+
submit_button = gr.Button("Submit")
|
59 |
+
|
60 |
+
# Output area for filtered IPA symbols
|
61 |
+
output = gr.Textbox(label="Matching IPA Symbols", interactive=False)
|
62 |
+
|
63 |
+
# Connect the button to the filter function
|
64 |
+
submit_button.click(
|
65 |
+
fn=filter_symbols,
|
66 |
+
inputs=[voicing, place, manner, oronasal, centrality],
|
67 |
+
outputs=output
|
68 |
+
)
|
69 |
+
|
70 |
+
return app
|
71 |
+
|
72 |
+
# Launch the app
|
73 |
+
app = interface()
|
74 |
+
app.launch()
|