felipekitamura commited on
Commit
303aac5
·
verified ·
1 Parent(s): 5ab917f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gensim.downloader
2
  import gradio as gr
 
3
  model = gensim.downloader.load("glove-wiki-gigaword-50")
4
 
5
 
@@ -18,11 +19,16 @@ 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
  output = model.similar_by_vector(model[word3] + model[word2] - model[word1])
24
- out_str = [x + ": " + str(y) for x,y in [item for item in output]]
25
- return """\n""".join(out_str)
 
 
 
 
26
 
27
  examples = [
28
  ["woman", "man", "aunt"],
@@ -33,7 +39,7 @@ examples = [
33
  iface = gr.Interface(
34
  fn=inference,
35
  inputs=[Word1, Word2, Word3],
36
- outputs=label,
37
  description=description,
38
  examples=examples
39
  )
 
1
  import gensim.downloader
2
  import gradio as gr
3
+ import pandas as pd
4
  model = gensim.downloader.load("glove-wiki-gigaword-50")
5
 
6
 
 
19
  Word2 = gr.Textbox()
20
  Word3 = gr.Textbox()
21
  label = gr.Label(show_label=True, label="Word4")
22
+ bp = gr.BarPlot()
23
 
24
  def inference(word1, word2, word3):
25
  output = model.similar_by_vector(model[word3] + model[word2] - model[word1])
26
+ #out_str = [x + ": " + str(y) for x,y in [item for item in output]]
27
+ #return """\n""".join(out_str)
28
+ df = pd.DataFrame({"x": [x for x,y in [item for item in output],
29
+ "y": [str(y) for x,y in [item for item in output]
30
+ })
31
+ return df
32
 
33
  examples = [
34
  ["woman", "man", "aunt"],
 
39
  iface = gr.Interface(
40
  fn=inference,
41
  inputs=[Word1, Word2, Word3],
42
+ outputs=bp,
43
  description=description,
44
  examples=examples
45
  )