flow3rdown commited on
Commit
260dd9d
·
1 Parent(s): 8a8ed77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,7 +1,20 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from gensim.models import KeyedVectors
3
 
4
+ def isNoneWords(word):
5
+ if word is None or len(word)==0 or word not in model.vocab:
6
+ return True
7
+ else:
8
+ return False
9
 
10
+ def top_similarity_route(word):
11
+ if isNoneWords(word):
12
+ return "word is null or not in model!"
13
+ else:
14
+ return {'word':word,'top_similar_words':model.similar_by_word(word, topn=20, restrict_vocab=None)}
15
+
16
+
17
+ if __name__ == '__main__':
18
+ model = KeyedVectors.load_word2vec_format('tencent-ailab-embedding-zh-d100-v0.2.0-s.txt', binary=False)
19
+ iface = gr.Interface(fn=top_similarity_route, inputs="text", outputs="text")
20
+ iface.launch()