import gradio as gr import random # IPA features dictionary with full feature names ipa_features = { 'p': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'b': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 't': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'd': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'k': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '-'}, 'g': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'}, 'tʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'high': '-', 'voice': '-'}, 'dʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '-', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '+', 'high': '-', 'voice': '+'}, 'f': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'v': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'θ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'ð': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 's': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'z': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'ʃ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'ʒ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '+', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '+', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'h': {'syllabic': '-', 'consonantal': '+', 'sonorant': '-', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '-'}, 'm': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'n': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'ŋ': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '-', 'nasal': '+', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'}, 'l': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '-', 'nasal': '-', 'strident': '-', 'lateral': '+', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'r': {'syllabic': '-', 'consonantal': '+', 'sonorant': '+', 'coronal': '+', 'anterior': '+', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '-', 'voice': '+'}, 'j': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'}, 'w': {'syllabic': '-', 'consonantal': '-', 'sonorant': '+', 'coronal': '-', 'anterior': '-', 'continuant': '+', 'nasal': '-', 'strident': '-', 'lateral': '-', 'delayed release': '-', 'high': '+', 'voice': '+'} } # Function to filter IPA symbols based on user selections with 'ALL' as an option def filter_symbols(syllabic, consonantal, sonorant, coronal, anterior, continuant, nasal, strident, lateral, delayed_release, voice): # Extract IPA symbols based on the user's selections matching_symbols = [symbol for symbol, features in ipa_features.items() if (syllabic == 'ALL' or features['syllabic'] == syllabic) and (consonantal == 'ALL' or features['consonantal'] == consonantal) and (sonorant == 'ALL' or features['sonorant'] == sonorant) and (coronal == 'ALL' or features['coronal'] == coronal) and (anterior == 'ALL' or features['anterior'] == anterior) and (continuant == 'ALL' or features['continuant'] == continuant) and (nasal == 'ALL' or features['nasal'] == nasal) and (strident == 'ALL' or features['strident'] == strident) and (lateral == 'ALL' or features['lateral'] == lateral) and (delayed_release == 'ALL' or features['delayed release'] == delayed_release) and (voice == 'ALL' or features['voice'] == voice)] # Return the matching symbols in the format /p, b, m/ return f"/{', '.join(matching_symbols)}/" if matching_symbols else "No matching symbols." # Define the Gradio interface using buttons def interface(): with gr.Blocks() as app: gr.Markdown("### IPA Symbol Finder Based on Distinctive Features") # Button groups for user to click options for each feature syllabic = gr.Radio(label="Syllabic", choices=['ALL', '+', '-'], value='ALL') consonantal = gr.Radio(label="Consonantal", choices=['ALL', '+', '-'], value='ALL') voice = gr.Radio(label="Voice", choices=['ALL', '+', '-'], value='ALL') sonorant = gr.Radio(label="Sonorant", choices=['ALL', '+', '-'], value='ALL') coronal = gr.Radio(label="Coronal", choices=['ALL', '+', '-'], value='ALL') anterior = gr.Radio(label="Anterior", choices=['ALL', '+', '-'], value='ALL') continuant = gr.Radio(label="Continuant", choices=['ALL', '+', '-'], value='ALL') nasal = gr.Radio(label="Nasal", choices=['ALL', '+', '-'], value='ALL') strident = gr.Radio(label="Strident", choices=['ALL', '+', '-'], value='ALL') lateral = gr.Radio(label="Lateral", choices=['ALL', '+', '-'], value='ALL') delayed_release = gr.Radio(label="Delayed Release", choices=['ALL', '+', '-'], value='ALL') # Submit button submit_button = gr.Button("Submit") # Output area for filtered IPA symbols output = gr.Textbox(label="Matching IPA Symbols", interactive=False) # Connect the button to the filter function submit_button.click( fn=filter_symbols, inputs=[syllabic, consonantal, sonorant, coronal, anterior, continuant, nasal, strident, lateral, delayed_release, voice], outputs=output ) return app # Launch the app app = interface() app.launch()