eloi-goncalves commited on
Commit
220d18f
·
1 Parent(s): 07c7708

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -57,10 +57,10 @@ def classify(text,labels):
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]
@@ -68,8 +68,21 @@ def classify(text,label):
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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]
 
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
 
76
+ # GPT2
77
+ from transformers import GPT2LMHeadModel,GPT2Tokenizer
78
+ import gradio as grad
79
+ mdl = GPT2LMHeadModel.from_pretrained('gpt2')
80
+ gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
81
+ def generate(starting_text):
82
+ tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
83
+ gpt2_tensors = mdl.generate(tkn_ids)
84
+ response = gpt2_tensors
85
+ return response
86
+ txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
87
+ out=grad.Textbox(lines=1, label="Generated Tensors")
88
+ grad.Interface(generate, inputs=txt, outputs=out).launch()