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('Input Text', label='Text to classify', interactive=True) with gr.Row(): labels = gr.DataFrame(headers=['Labels'], row_count=(2, 'dynamic'), col_count=(1, 'fixed'), datatype='str', interactive=True, scale=4) submit = gr.Button('Submit', scale=1) with gr.Group(): with gr.Row(): checkbox = gr.Checkbox(label='Multi-Label Classification', interactive=True, info='Showing the score for more than one label') dropdown = gr.Dropdown(label='Number of Labels to predict', multiselect=False, value=1, choices=list(range(1,6)), interactive=False) result = gr.Label(label='Classification Result', 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()