Spaces:
Build error
Build error
File size: 4,012 Bytes
7dda7b9 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
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() |