Spaces:
Runtime error
Runtime error
File size: 4,558 Bytes
e8aad19 |
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
import gradio as gr
import pandas as pd
from tool_info import TOOL_INFO
from modules.module_connection import Word2ContextExplorerConnector
def interface(
vocabulary, # Vocabulary class instance
contexts: str,
available_logs: bool,
available_wordcloud: bool,
lang: str="es"
) -> gr.Blocks:
# --- Init Class ---
connector = Word2ContextExplorerConnector(
vocabulary=vocabulary,
context=contexts,
lang=lang,
logs_file_name=f"logs_edia_datos_{lang}" if available_logs else None
)
# --- Load language ---
labels = pd.read_json(
f"language/{lang}.json"
)["DataExplorer_interface"]
# --- Interface ---
iface = gr.Blocks(
css=".container { max-width: 90%; margin: auto;}"
)
with iface:
with gr.Row():
with gr.Column():
with gr.Group():
gr.Markdown(
value=labels["step1"]
)
with gr.Row():
input_word = gr.Textbox(
label=labels["inputWord"]["title"],
show_label=False,
placeholder=labels["inputWord"]["placeholder"]
)
with gr.Row():
btn_get_w_info = gr.Button(
value=labels["wordInfoButton"]
)
with gr.Group():
gr.Markdown(
value=labels["step2"]
)
n_context = gr.Slider(
label="",
step=1, minimum=1, maximum=30, value=5,
visible=True,
interactive=True
)
with gr.Group():
gr.Markdown(
value=labels["step3"]
)
subsets_choice = gr.CheckboxGroup(
label="Conjuntos",
show_label=False,
interactive=True,
visible=True
)
with gr.Row():
btn_get_contexts = gr.Button(
value=labels["wordContextButton"],
visible=True
)
with gr.Row():
out_msj = gr.Markdown(
label="",
visible=True
)
with gr.Column():
with gr.Group():
gr.Markdown(
value=labels["wordDistributionTitle"]
)
dist_plot = gr.Plot(
label="",
show_label=False
)
wc_plot = gr.Plot(
label="",
show_label=False,
visible=available_wordcloud
)
with gr.Group():
gr.Markdown(
value=labels["frequencyPerSetTitle"]
)
subsets_freq = gr.HTML(
label=""
)
with gr.Row():
with gr.Group():
with gr.Row():
gr.Markdown(
value=labels["contextList"]
)
with gr.Row():
out_context = gr.Dataframe(
label="",
interactive=False,
value=pd.DataFrame([], columns=['']),
wrap=True,
datatype=['str','markdown','str','markdown']
)
with gr.Group():
gr.Markdown(
value=TOOL_INFO
)
btn_get_w_info.click(
fn=connector.get_word_info,
inputs=[input_word],
outputs=[out_msj,
out_context,
subsets_freq,
dist_plot,
wc_plot,
subsets_choice
]
)
btn_get_contexts.click(
fn=connector.get_word_context,
inputs=[input_word, n_context, subsets_choice],
outputs=[out_msj, out_context]
)
return iface |