Spaces:
Sleeping
Sleeping
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() |