flichote commited on
Commit
bff58a8
·
1 Parent(s): 1042ce4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -76,19 +76,33 @@
76
  # out=grad.Textbox(lines=10, label="Summary")
77
  # grad.Interface(summarize, inputs=txt, outputs=out).launch()
78
 
79
- from transformers import PegasusForConditionalGeneration, PegasusTokenizer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  import gradio as grad
81
- mdl_name = "google/pegasus-xsum"
82
- pegasus_tkn = PegasusTokenizer.from_pretrained(mdl_name)
83
- mdl = PegasusForConditionalGeneration.from_pretrained(mdl_name)
84
-
85
- def summarize(text):
86
- tokens = pegasus_tkn(text, truncation=True, padding="longest", return_tensors="pt")
87
- translated_txt = mdl.generate(**tokens,num_return_sequences=5,max_length=200,temperature=1.5,num_beams=10)
88
- response = pegasus_tkn.batch_decode(translated_txt, skip_special_tokens=True)
89
- return response
90
- txt=grad.Textbox(lines=10, label="English", placeholder="English Text here")
91
- out=grad.Textbox(lines=10, label="Summary")
92
- grad.Interface(summarize, inputs=txt, outputs=out).launch()
93
 
94
 
 
 
 
 
 
 
 
 
 
 
 
76
  # out=grad.Textbox(lines=10, label="Summary")
77
  # grad.Interface(summarize, inputs=txt, outputs=out).launch()
78
 
79
+ # from transformers import PegasusForConditionalGeneration, PegasusTokenizer
80
+ # import gradio as grad
81
+ # mdl_name = "google/pegasus-xsum"
82
+ # pegasus_tkn = PegasusTokenizer.from_pretrained(mdl_name)
83
+ # mdl = PegasusForConditionalGeneration.from_pretrained(mdl_name)
84
+
85
+ # def summarize(text):
86
+ # tokens = pegasus_tkn(text, truncation=True, padding="longest", return_tensors="pt")
87
+ # translated_txt = mdl.generate(**tokens,num_return_sequences=5,max_length=200,temperature=1.5,num_beams=10)
88
+ # response = pegasus_tkn.batch_decode(translated_txt, skip_special_tokens=True)
89
+ # return response
90
+ # txt=grad.Textbox(lines=10, label="English", placeholder="English Text here")
91
+ # out=grad.Textbox(lines=10, label="Summary")
92
+ # grad.Interface(summarize, inputs=txt, outputs=out).launch()
93
+
94
+ from transformers import pipeline
95
  import gradio as grad
96
+ zero_shot_classifier = pipeline("zero-shot-classification")
 
 
 
 
 
 
 
 
 
 
 
97
 
98
 
99
+ def classify(text,labels):
100
+ classifer_labels = labels.split(",")
101
+ #["software", "politics", "love", "movies", "emergency", "advertisment","sports"]
102
+ response = zero_shot_classifier(text,classifer_labels)
103
+ return response
104
+ txt=grad.Textbox(lines=1, label="English", placeholder="text to be classified")
105
+ labels=grad.Textbox(lines=1, label="Labels", placeholder="comma separated labels")
106
+ out=grad.Textbox(lines=1, label="Classification")
107
+ grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
108
+