Spaces:
Sleeping
Sleeping
Chithekitale
commited on
Commit
·
4fb1be0
1
Parent(s):
39e2311
koyamba4
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gensim
|
| 2 |
+
import gensim.models
|
| 3 |
+
from gensim.models import KeyedVectors
|
| 4 |
+
import gensim.downloader as api
|
| 5 |
+
import fasttext
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
model = fasttext.load_model("fasttext_model_ina.bin")
|
| 10 |
+
|
| 11 |
+
# Test Model Locally
|
| 12 |
+
|
| 13 |
+
#print(model.get_nearest_neighbors("ndalama")) # Example Chichewa word
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Define function for Gradio
|
| 17 |
+
def find_similar_words(wordz, top_n=10):
|
| 18 |
+
words=model.get_nearest_neighbors(wordz)
|
| 19 |
+
try:
|
| 20 |
+
text=''
|
| 21 |
+
for word in words:
|
| 22 |
+
text= text +"\n" +str(word[1]) + " Similarity score : "+ str(word[0])
|
| 23 |
+
|
| 24 |
+
return text
|
| 25 |
+
except KeyError:
|
| 26 |
+
return f"'{word}' not found in the vocabulary!"
|
| 27 |
+
|
| 28 |
+
# Gradio UI
|
| 29 |
+
demo = gr.Interface(
|
| 30 |
+
fn=find_similar_words,
|
| 31 |
+
inputs=gr.Textbox(label="Enter a Word"),
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="Chichewa Word Embeddings Explorer",
|
| 34 |
+
description="Find similar words using a pre-trained word embedding model.",
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Launch for local testing
|
| 38 |
+
demo.launch()
|