CoolFace
Apppublic

Saeer/zero_shot_classifier

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py31 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4pipe = pipeline("zero-shot-classification",model='MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')5 6with gr.Blocks() as demo:7    txt = gr.Textbox('Input Text', label='Text to classify', interactive=True)8    with gr.Row():9        labels = gr.DataFrame(headers=['Labels'], row_count=(2, 'dynamic'), col_count=(1, 'fixed'),10                              datatype='str', interactive=True, scale=4)11        submit = gr.Button('Submit', scale=1)12    with gr.Group():13        with gr.Row():14            checkbox = gr.Checkbox(label='Multi-Label Classification', interactive=True, info='Showing the score for more than one label')15            dropdown = gr.Dropdown(label='Number of Labels to predict', multiselect=False, value=1, choices=list(range(1,6)),16                        interactive=False)17    result = gr.Label(label='Classification Result', visible=False)18 19    def activate_dropdown(ob):20        if not ob:21            return gr.Dropdown(interactive=ob, value=1)22        return gr.Dropdown(interactive=ob)23 24    def submit_btn(text, df, label_no):25        output = pipe(text, list(df['Labels']), multi_label=True)26        return gr.Label(visible=True, num_top_classes=int(label_no),27                        value={i: j for i, j in zip(output['labels'], output['scores'])})28 29    checkbox.change(activate_dropdown, inputs=[checkbox], outputs=[dropdown])30    submit.click(submit_btn, inputs=[txt, labels, dropdown], outputs=[result])31demo.launch()