import gensim import gensim.models from gensim.models import KeyedVectors import gensim.downloader as api import fasttext import gradio as gr model = fasttext.load_model("fasttext_model_ina.bin") # Test Model Locally #print(model.get_nearest_neighbors("ndalama")) # Example Chichewa word # Define function for Gradio def find_similar_words(wordz, top_n=10): words=model.get_nearest_neighbors(wordz) try: text='' for word in words: text= text +"\n" +str(word[1]) + " Similarity score : "+ str(word[0]) return text except KeyError: return f"'{word}' not found in the vocabulary!" # Gradio UI demo = gr.Interface( fn=find_similar_words, inputs=gr.Textbox(label="Enter a Word"), outputs="text", title="Chichewa Word Embeddings Explorer", description="Find similar words using a pre-trained word embedding model.", ) # Launch for local testing demo.launch()