Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from huggingface_hub import InferenceClient | |
| def classify_words(input_text): | |
| """ | |
| Classify words in the input text into those that start with vowels | |
| and those that start with consonants. | |
| """ | |
| if not input_text.strip(): | |
| return "Please enter some text.", "", "" | |
| vowels = {'a', 'e', 'i', 'o', 'u'} | |
| words = input_text.split() | |
| # Separate words into vowels and consonants | |
| words_starting_with_vowels = [word for word in words if word[0].lower() in vowels] | |
| words_starting_with_consonants = [word for word in words if word[0].lower() not in vowels] | |
| return ( | |
| f"Words starting with vowels ({len(words_starting_with_vowels)}): " + ", ".join(words_starting_with_vowels), | |
| f"Words starting with consonants ({len(words_starting_with_consonants)}): " + ", ".join(words_starting_with_consonants), | |
| ) | |
| # Define Gradio Interface | |
| with gr.Blocks() as app: | |
| gr.Markdown("# 🗣️ Vowel-Consonant Classifier Chatbot") | |
| gr.Markdown("Enter text below, and I will classify the words based on whether they start with vowels or consonants!") | |
| with gr.Row(): | |
| input_text = gr.Textbox(label="Enter your text here and I can tell you how many words start with vowel and how many with consonant", placeholder="Type something...") | |
| with gr.Row(): | |
| vowel_output = gr.Textbox(label="Words Starting with Vowels", interactive=False) | |
| consonant_output = gr.Textbox(label="Words Starting with Consonants", interactive=False) | |
| classify_button = gr.Button("Classify Words") | |
| classify_button.click(classify_words, inputs=[input_text], outputs=[vowel_output, consonant_output]) | |
| # Launch the app | |
| app.launch() | |