Spaces:
Build error
Build error
import matplotlib as mpl | |
mpl.use('Agg') | |
from audioop import bias | |
import gradio as gr | |
from modules_sesgo_en_palabras import WEBiasExplorer2d, Embedding | |
from examples import examples_explorar_relaciones_entre_palabras | |
import matplotlib.pyplot as plt | |
from tool_info import TOOL_INFO | |
plt.rcParams.update({'font.size': 14}) | |
LABEL_WORD_LIST_1 = 'Lista de palabras 1' | |
LABEL_WORD_LIST_2 = 'Lista de palabras 2' | |
LABEL_WORD_LIST_3 = 'Lista de palabras 3' | |
LABEL_WORD_LIST_4 = 'Lista de palabras 4' | |
LABEL_WORD_LIST_DIAGNOSE = 'Lista de palabras a diagnosticar' | |
word_vectors_path = 'fasttext-sbwc.100k.vec' | |
we = Embedding(word_vectors_path) | |
we.load_we_as_keyed_vectors(word_vectors_path) | |
we_bias_2d = WEBiasExplorer2d(we.wv) | |
explorar_relaciones_entre_palabras_interface = gr.Blocks() | |
with explorar_relaciones_entre_palabras_interface: | |
gr.Markdown("Escribi algunas palabras para visualizar sus palabras relacionadas") | |
with gr.Row(): | |
with gr.Column(scale=3): | |
with gr.Row(equal_height=True): | |
with gr.Column(scale=5): | |
diagnose_list = gr.Textbox(lines=2, label=LABEL_WORD_LIST_DIAGNOSE) | |
with gr.Column(scale=1,min_width=10): | |
color_wordlist = gr.ColorPicker(label="",value='#000000',) | |
with gr.Row(): | |
with gr.Column(scale=5): | |
wordlist_1 = gr.Textbox(lines=2, label=LABEL_WORD_LIST_1) | |
with gr.Column(scale=1,min_width=10): | |
color_wordlist_1 = gr.ColorPicker(label="",value='#1f78b4') | |
with gr.Row(): | |
with gr.Column(scale=5): | |
wordlist_2 = gr.Textbox(lines=2, label=LABEL_WORD_LIST_2) | |
with gr.Column(scale=1,min_width=10): | |
color_wordlist_2 = gr.ColorPicker(label="",value='#33a02c') | |
with gr.Row(): | |
with gr.Column(scale=5): | |
wordlist_3 = gr.Textbox(lines=2, label=LABEL_WORD_LIST_3) | |
with gr.Column(scale=1,min_width=10): | |
color_wordlist_3 = gr.ColorPicker(label="",value='#e31a1c') | |
with gr.Row(): | |
with gr.Column(scale=5): | |
wordlist_4 = gr.Textbox(lines=2, label=LABEL_WORD_LIST_4) | |
with gr.Column(scale=1,min_width=10): | |
color_wordlist_4 = gr.ColorPicker(label="",value='#6a3d9a') | |
with gr.Column(scale=4): | |
with gr.Row(): | |
with gr.Row(): | |
plot_neighbors = gr.Checkbox(label='Graficar palabras relacionadas') | |
with gr.Row(): | |
alpha = gr.Slider(minimum=0.1,maximum=0.9, value=0.3, step=0.1,label='Transparencia') | |
with gr.Row(): | |
fontsize=gr.Number(value=18, label='Tamaño de fuente') | |
with gr.Row(): | |
btn_plot = gr.Button('¡Graficar en el espacio!') | |
with gr.Row(): | |
err_msg = gr.Markdown(label="", visible=True) | |
with gr.Row(): | |
word_proyections = gr.Image(shape=(10, 10)) | |
with gr.Row(): | |
examples = gr.Examples( | |
fn=we_bias_2d.plot_projections_2d, | |
inputs=[diagnose_list,wordlist_1,wordlist_2,wordlist_3,wordlist_4], | |
outputs=[word_proyections,err_msg], | |
examples=examples_explorar_relaciones_entre_palabras | |
) | |
with gr.Row(): | |
gr.Markdown(TOOL_INFO) | |
btn_plot.click( | |
fn=we_bias_2d.plot_projections_2d, | |
inputs=[ | |
diagnose_list, | |
wordlist_1, | |
wordlist_2, | |
wordlist_3, | |
wordlist_4, | |
color_wordlist, | |
color_wordlist_1, | |
color_wordlist_2, | |
color_wordlist_3, | |
color_wordlist_4, | |
plot_neighbors, | |
alpha, | |
fontsize | |
], | |
outputs=[word_proyections,err_msg] | |
) | |
explorar_relaciones_entre_palabras_interface.queue(concurrency_count=10) | |
explorar_relaciones_entre_palabras_interface.launch() |