belyakoff commited on
Commit
8a99a39
·
verified ·
1 Parent(s): 772ea61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('Введите текст', label='Текст для классификации', interactive=True)
8
+ with gr.Row():
9
+ labels = gr.DataFrame(
10
+ headers=['Labels'],
11
+ row_count=(2, 'static'),
12
+ col_count=(1, 'fixed'),
13
+ datatype='str',
14
+ interactive=True,
15
+ scale=4,
16
+ )
17
+ submit = gr.Button('Обработать', scale=1)
18
+ with gr.Group():
19
+ with gr.Row():
20
+ checkbox = gr.Checkbox(
21
+ label='Множественная положительная классификация',
22
+ interactive=True,
23
+ info='',
24
+ )
25
+ dropdown = gr.Dropdown(
26
+ label='Number of Labels to predict',
27
+ multiselect=False,
28
+ value=1,
29
+ choices=list(range(1,6),),
30
+ interactive=False,
31
+ )
32
+ result = gr.Label(
33
+ label='Результат классификации',
34
+ visible=False,
35
+ )
36
+
37
+ def activate_dropdown(ob):
38
+ if not ob:
39
+ return gr.Dropdown(
40
+ interactive=ob,
41
+ value=1,
42
+ )
43
+ return gr.Dropdown(interactive=ob)
44
+
45
+ def submit_btn(text, df, label_no):
46
+ output = pipe(
47
+ text,
48
+ list(df['Labels']),
49
+ multi_label=True,
50
+ )
51
+ return gr.Label(
52
+ visible=True,
53
+ num_top_classes=int(label_no),
54
+ value={i: j for i, j in zip(output['labels'], output['scores'])}
55
+ )
56
+
57
+ checkbox.change(activate_dropdown, inputs=[checkbox], outputs=[dropdown])
58
+ submit.click(submit_btn, inputs=[txt, labels, dropdown], outputs=[result])
59
+ demo.launch()