SallySprick commited on
Commit
d535897
·
verified ·
1 Parent(s): f88a5f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,15 +1,20 @@
1
- from transformers import pipeline
 
2
  import gradio as grad
 
 
 
 
3
 
4
- zero_shot_classifier = pipeline("zero-shot-classification")
 
 
 
 
 
 
5
 
6
- def classify(text,labels):
7
- classifer_labels = labels.split(",")
8
- #["software", "politics", "love", "movies", "emergency", "advertisment","sports"]
9
- response = zero_shot_classifier(text,classifer_labels)
10
- return response
11
-
12
  txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
13
- labels=grad.Textbox(lines=1, label="Labels", placeholder="comma separated labels")
14
- out=grad.Textbox(lines=1, label="Classification")
15
  grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
 
1
+ from transformers import BartForSequenceClassification,
2
+ BartTokenizer
3
  import gradio as grad
4
+ Chapter 5 Tasks Using the Hugging Face Library
5
+ 94
6
+ bart_tkn = BartTokenizer.from_pretrained('facebook/bartlarge-mnli')
7
+ mdl = BartForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
8
 
9
+ def classify(text,label):
10
+ tkn_ids = bart_tkn.encode(text, label, return_tensors='pt')
11
+ tkn_lgts = mdl(tkn_ids)[0]
12
+ entail_contra_tkn_lgts = tkn_lgts[:,[0,2]]
13
+ probab = entail_contra_tkn_lgts.softmax(dim=1)
14
+ response = probab[:,1].item() * 100
15
+ return response
16
 
 
 
 
 
 
 
17
  txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
18
+ labels=grad.Textbox(lines=1, label="Label", placeholder="Input a Label")
19
+ out=grad.Textbox(lines=1, label="Probablity of label being true is")
20
  grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()