Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
pipe = pipeline("zero-shot-classification",model='MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7')
|
5 |
+
|
6 |
+
with 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])
|
31 |
+
demo.launch()
|