marcelcastrobr commited on
Commit
3702ace
1 Parent(s): b0b0ba6

Add application file

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1,4 +1,20 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
@@ -6,5 +22,12 @@ def greet(name):
6
  iface = gr.Interface(
7
  title = "Zero-shot Classification of Norwegian Text",
8
  description = "Demo of zero-shot classification using NB-Bert base model (Norwegian).",
9
- fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
10
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoFeatureExtractor, AutoTokenizer, SpeechEncoderDecoderModel
3
+ import torch
4
+
5
+ from transformers import pipeline
6
+ classifier = pipeline("zero-shot-classification", model="NbAiLab/nb-bert-base-mnli")
7
+
8
+
9
+ def sequence_to_classify(sequence, labels):
10
+ #sequence_to_classify = 'Folkehelseinstituttets mest optimistiske anslag er at alle voksne er ferdigvaksinert innen midten av september.'
11
+ #candidate_labels = ['politikk', 'helse', 'sport', 'religion']
12
+ hypothesis_template = 'Dette eksempelet er {}.'
13
+ #classifier(sequence_to_classify, candidate_labels, hypothesis_template=hypothesis_template, multi_class=True)
14
+ return classifier(sequence, labels, hypothesis_template=hypothesis_template, multi_class=True)
15
+
16
+
17
+
18
 
19
  def greet(name):
20
  return "Hello " + name + "!!"
 
22
  iface = gr.Interface(
23
  title = "Zero-shot Classification of Norwegian Text",
24
  description = "Demo of zero-shot classification using NB-Bert base model (Norwegian).",
25
+ fn=sequence_to_classify,
26
+ inputs=[gr.inputs.Textbox(lines=2,
27
+ label="Write a norwegian text you would like to classify...",
28
+ placeholder="Text here..."),
29
+ gr.inputs.Textbox(lines=2,
30
+ label="Possible candidate labels",
31
+ placeholder="labels here...")],
32
+ outputs="text")
33
  iface.launch()