Spaces:
Sleeping
Sleeping
File size: 1,139 Bytes
7b42f20 303aac5 7b42f20 f840320 7b42f20 66642ba 303aac5 e3a05a1 303aac5 7b42f20 303aac5 7b42f20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gensim.downloader
import gradio as gr
import pandas as pd
model = gensim.downloader.load("glove-wiki-gigaword-50")
description = """
### Word Embedding Demo App
Universidade Federal de São Paulo - Escola Paulista de Medicina
The output is Word3 + (Word2 - Word1)
Credits:
* Gensim
* Glove
"""
Word1 = gr.Textbox()
Word2 = gr.Textbox()
Word3 = gr.Textbox()
label = gr.Label(show_label=True, label="Word4")
bp = gr.BarPlot(x="x", y="y")
def inference(word1, word2, word3):
output = model.similar_by_vector(model[word3] + model[word2] - model[word1])
#out_str = [x + ": " + str(y) for x,y in [item for item in output]]
#return """\n""".join(out_str)
df = pd.DataFrame({"x": [x for x,y in [item for item in output]],
"y": [str(y) for x,y in [item for item in output]]
})
return df
examples = [
["woman", "man", "aunt"],
["woman", "man", "girl"],
["woman", "man", "granddaughter"],
]
iface = gr.Interface(
fn=inference,
inputs=[Word1, Word2, Word3],
outputs=bp,
description=description,
examples=examples
)
iface.launch() |