eloi-goncalves commited on
Commit
07c7708
·
1 Parent(s): 21d73b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -42,17 +42,34 @@ def summarize(text):
42
  # out=grad.Textbox(lines=10, label="Summary")
43
  # grad.Interface(summarize, inputs=txt, outputs=out).launch()
44
 
45
-
46
- from transformers import pipeline
47
- import gradio as grad
48
- zero_shot_classifier = pipeline("zero-shot-classification")
49
  def classify(text,labels):
50
  classifer_labels = labels.split(",")
51
  #["software", "politics", "love", "movies", "emergency", "advertisment","sports"]
52
  response = zero_shot_classifier(text,classifer_labels)
53
  return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
55
- labels=grad.Textbox(lines=1, label="Labels", placeholder="comma separated labels")
56
- out=grad.Textbox(lines=1, label="Classification")
57
  grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
58
 
 
42
  # out=grad.Textbox(lines=10, label="Summary")
43
  # grad.Interface(summarize, inputs=txt, outputs=out).launch()
44
 
45
+ # ZeroShotClassification using pipeline
46
+ # from transformers import pipeline
47
+ # import gradio as grad
48
+ # zero_shot_classifier = pipeline("zero-shot-classification")
49
  def classify(text,labels):
50
  classifer_labels = labels.split(",")
51
  #["software", "politics", "love", "movies", "emergency", "advertisment","sports"]
52
  response = zero_shot_classifier(text,classifer_labels)
53
  return response
54
+ # txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
55
+ # labels=grad.Textbox(lines=1, label="Labels", placeholder="comma separated labels")
56
+ # out=grad.Textbox(lines=1, label="Classification")
57
+ # grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
58
+
59
+ # Text classification using BartForSequenceClassification
60
+ from transformers import BartForSequenceClassification, BartTokenizer
61
+ import gradio as grad
62
+ bart_tkn = BartTokenizer.from_pretrained('facebook/bart-large-mnli')
63
+ mdl = BartForSequenceClassification.from_pretrained('facebook/bart-large-mnli')
64
+ def classify(text,label):
65
+ tkn_ids = bart_tkn.encode(text, label, return_tensors='pt')
66
+ tkn_lgts = mdl(tkn_ids)[0]
67
+ entail_contra_tkn_lgts = tkn_lgts[:,[0,2]]
68
+ probab = entail_contra_tkn_lgts.softmax(dim=1)
69
+ response = probab[:,1].item() * 100
70
+ return response
71
  txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
72
+ labels=grad.Textbox(lines=1, label="Label", placeholder="Input a Label")
73
+ out=grad.Textbox(lines=1, label="Probablity of label being true is")
74
  grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
75