PuzzleZeroShot / app.py
belyakoff's picture
Create app.py
8a99a39 verified
raw
history blame
1.95 kB
import gradio as gr
from transformers import pipeline
pipe = pipeline("zero-shot-classification",model='MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')
with gr.Blocks() as demo:
txt = gr.Textbox('Введите текст', label='Текст для классификации', interactive=True)
with gr.Row():
labels = gr.DataFrame(
headers=['Labels'],
row_count=(2, 'static'),
col_count=(1, 'fixed'),
datatype='str',
interactive=True,
scale=4,
)
submit = gr.Button('Обработать', scale=1)
with gr.Group():
with gr.Row():
checkbox = gr.Checkbox(
label='Множественная положительная классификация',
interactive=True,
info='',
)
dropdown = gr.Dropdown(
label='Number of Labels to predict',
multiselect=False,
value=1,
choices=list(range(1,6),),
interactive=False,
)
result = gr.Label(
label='Результат классификации',
visible=False,
)
def activate_dropdown(ob):
if not ob:
return gr.Dropdown(
interactive=ob,
value=1,
)
return gr.Dropdown(interactive=ob)
def submit_btn(text, df, label_no):
output = pipe(
text,
list(df['Labels']),
multi_label=True,
)
return gr.Label(
visible=True,
num_top_classes=int(label_no),
value={i: j for i, j in zip(output['labels'], output['scores'])}
)
checkbox.change(activate_dropdown, inputs=[checkbox], outputs=[dropdown])
submit.click(submit_btn, inputs=[txt, labels, dropdown], outputs=[result])
demo.launch()