belyakoff commited on
Commit
d50480b
·
verified ·
1 Parent(s): c172233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,25 +1,27 @@
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- classifier = pipeline("zero-shot-classification", model="MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7")
5
 
6
  def classify(text, labels):
7
  labels = labels.split(',')
8
  if not text or not labels:
9
  return []
10
  result = classifier(text, candidate_labels=labels)
11
- return list(zip(result['labels'], result['scores']))
12
 
13
  with gr.Blocks() as demo:
14
- gr.Markdown("## Zero-Shot Text Classification")
15
 
16
  with gr.Row():
17
- with gr.Column(scale=1):
18
- text_input = gr.Textbox(label="Text for classification", placeholder="Enter text here...")
19
- labels_input = gr.Textbox(label="Classes (comma separated)", placeholder="Enter classes separated by commas...")
20
- button = gr.Button("Classify")
21
  with gr.Column(scale=2):
22
- output = gr.Dataframe(headers=["Class", "Probability"], label="Classification Results")
 
 
 
 
23
 
24
  button.click(classify, inputs=[text_input, labels_input], outputs=output)
25
 
 
1
+ import os
2
+
3
  import gradio as gr
4
  from transformers import pipeline
5
 
6
+ classifier = pipeline("zero-shot-classification", model=os.getenv('MODEL'))
7
 
8
  def classify(text, labels):
9
  labels = labels.split(',')
10
  if not text or not labels:
11
  return []
12
  result = classifier(text, candidate_labels=labels)
13
+ return list(zip(result['labels'], map(lambda x: round(x, 4), result['scores'])))
14
 
15
  with gr.Blocks() as demo:
16
+ gr.Markdown("## Zero-Shot классификация")
17
 
18
  with gr.Row():
 
 
 
 
19
  with gr.Column(scale=2):
20
+ text_input = gr.Textbox(label="Текст для классификации", placeholder="Введите текст...")
21
+ labels_input = gr.Textbox(label="Классы (через запятую)", placeholder="Опишите классы через запятую...")
22
+ button = gr.Button("Classify")
23
+ with gr.Column(scale=1):
24
+ output = gr.Dataframe(headers=[" Класс ", "Вероятность"], label="Результаты классификации")
25
 
26
  button.click(classify, inputs=[text_input, labels_input], outputs=output)
27