import gradio as gr import random # IPA Data from your original dictionary ipa_data = { 'p': {'Voicing': 'voiceless', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 'b': {'Voicing': 'voiced', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 't': {'Voicing': 'voiceless', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 'd': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 'k': {'Voicing': 'voiceless', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 'g': {'Voicing': 'voiced', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': '(oral)','Centrality':'(central)'}, 'f': {'Voicing': 'voiceless', 'Place': 'labio-dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'v': {'Voicing': 'voiced', 'Place': 'labio-dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'θ': {'Voicing': 'voiceless', 'Place': 'dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'ð': {'Voicing': 'voiced', 'Place': 'dental', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 's': {'Voicing': 'voiceless', 'Place': 'alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'z': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'ʃ': {'Voicing': 'voiceless', 'Place': 'palato-alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'ʒ': {'Voicing': 'voiced', 'Place': 'palato-alveolar', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'tʃ': {'Voicing': 'voiceless', 'Place': 'palato-alveolar', 'Manner': 'affricate','Oro-nasal': '(oral)','Centrality':'(central)'}, 'dʒ': {'Voicing': 'voiced', 'Place': 'palato-alveolar', 'Manner': 'affricate','Oro-nasal': '(oral)','Centrality':'(central)'}, 'h': {'Voicing': 'voiceless', 'Place': 'glottal', 'Manner': 'fricative','Oro-nasal': '(oral)','Centrality':'(central)'}, 'm': {'Voicing': 'voiced', 'Place': 'bilabial', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'}, 'n': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'}, 'ŋ': {'Voicing': 'voiced', 'Place': 'velar', 'Manner': 'stop','Oro-nasal': 'nasal','Centrality':'(not applicable)'}, 'ɹ': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'}, 'l': {'Voicing': 'voiced', 'Place': 'alveolar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'lateral'}, 'j': {'Voicing': 'voiced', 'Place': 'palatal', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'}, 'w': {'Voicing': 'voiced', 'Place': 'labio-velar', 'Manner': 'approximant','Oro-nasal': '(oral)','Centrality':'(central)'} } # Function to filter IPA symbols based on user selections with 'ALL' as an option def filter_symbols(voicing, place, manner, oronasal, centrality): # Extract IPA symbols based on the user's selections matching_symbols = [symbol for symbol, attributes in ipa_data.items() if (voicing == 'ALL' or attributes['Voicing'] == voicing) and (place == 'ALL' or attributes['Place'] == place) and (manner == 'ALL' or attributes['Manner'] == manner) and (oronasal == 'ALL' or attributes['Oro-nasal'] == oronasal) and (centrality == 'ALL' or attributes['Centrality'] == centrality)] # 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 with Buttons and 'ALL' Option") # Button groups for user to click options voicing = gr.Radio(label="Voicing", choices=['ALL', 'voiceless', 'voiced'], value='ALL') place = gr.Radio(label="Place", choices=['ALL', 'bilabial', 'labio-dental', 'labio-velar', 'dental', 'alveolar', 'palato-alveolar', 'palatal', 'velar', 'glottal'], value='ALL') manner = gr.Radio(label="Manner", choices=['ALL', 'stop', 'fricative', 'affricate', 'approximant'], value='ALL') oronasal = gr.Radio(label="Oro-nasal", choices=['ALL', '(oral)', 'nasal'], value='ALL') centrality = gr.Radio(label="Centrality", choices=['ALL', '(central)', 'lateral', '(not applicable)'], 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=[voicing, place, manner, oronasal, centrality], outputs=output ) return app # Launch the app app = interface() app.launch()