File size: 899 Bytes
4fb1be0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()