felipekitamura commited on
Commit
7b42f20
·
verified ·
1 Parent(s): 8088e46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gensim.downloader
2
+ import gradio as gr
3
+ model = gensim.downloader.load("glove-wiki-gigaword-50")
4
+
5
+
6
+ description = """
7
+ ### Word Embedding Demo App
8
+ Universidade Federal de São Paulo - Escola Paulista de Medicina
9
+
10
+ The output is Word3 + (Word2 - Word1)
11
+
12
+ Credits:
13
+ * Gensim
14
+ * Glove
15
+ """
16
+
17
+ Word1 = gr.Textbox()
18
+ Word2 = gr.Textbox()
19
+ Word3 = gr.Textbox()
20
+ label = gr.Label(show_label=True, label="Word4")
21
+
22
+ def inference(word1, word2, word3):
23
+ return model.similar_by_vector(model[word3] + model[word2] - model[word1])
24
+
25
+ examples = [
26
+ ["woman", "man", "aunt"],
27
+ ["woman", "man", "girl"],
28
+ ["woman", "man", "granddaughter"],
29
+ ]
30
+
31
+ iface = gr.Interface(
32
+ fn=inference,
33
+ inputs=[Word1, Word2, Word3],
34
+ outputs=label,
35
+ description=description,
36
+ examples=examples
37
+ )
38
+
39
+ iface.launch()