word_sim / app.py
flow3rdown's picture
Update app.py
32dc508
raw
history blame
664 Bytes
import gradio as gr
from gensim.models import KeyedVectors
def isNoneWords(word):
if word is None or len(word)==0 or word not in model.key_to_index:
return True
else:
return False
def top_similarity_route(word):
if isNoneWords(word):
return "word is null or not in model!"
else:
return {'word':word,'top_similar_words':model.similar_by_word(word, topn=20, restrict_vocab=None)}
if __name__ == '__main__':
model = KeyedVectors.load_word2vec_format('tencent-ailab-embedding-zh-d100-v0.2.0-s.txt', binary=False)
iface = gr.Interface(fn=top_similarity_route, inputs="text", outputs="text")
iface.launch()