Spaces:
Sleeping
Sleeping
Commit
·
0c4b135
1
Parent(s):
345d0f3
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from transformers import AutoModelForQuestionAnswering, AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
2 |
import gradio as grad
|
3 |
import ast
|
4 |
|
@@ -25,5 +25,20 @@ def translate(text):
|
|
25 |
#response = translate_pipeline(text)
|
26 |
return response
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
#grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
|
29 |
-
grad.Interface(translate, inputs=['text',], outputs='text').launch()
|
|
|
1 |
+
from transformers import AutoModelForQuestionAnswering, AutoModelForSeq2SeqLM, AutoTokenizer, PegasusForConditionalGeneration, PegasusTokenizer, pipeline
|
2 |
import gradio as grad
|
3 |
import ast
|
4 |
|
|
|
25 |
#response = translate_pipeline(text)
|
26 |
return response
|
27 |
|
28 |
+
|
29 |
+
|
30 |
+
mdl_name = "google/pegasus-xsum"
|
31 |
+
pegasus_tkn = PegasusTokenizer.from_pretrained(mdl_name)
|
32 |
+
mdl = PegasusForConditionalGeneration.from_pretrained(mdl_name)
|
33 |
+
|
34 |
+
def summarize(text):
|
35 |
+
tokens = pegasus_tkn(text, truncation=True, padding="longest", return_tensors="pt")
|
36 |
+
txt_summary = mdl.generate(**tokens)
|
37 |
+
response = pegasus_tkn.batch_decode(txt_summary, skip_special_tokens=True)
|
38 |
+
return response
|
39 |
+
txt=grad.Textbox(lines=10, label="English", placeholder="English Text here")
|
40 |
+
out=grad.Textbox(lines=10, label="Summary")
|
41 |
+
grad.Interface(summarize, inputs=txt, outputs=out).launch()
|
42 |
+
|
43 |
#grad.Interface(answer_question, inputs=["text","text"], outputs="text").launch()
|
44 |
+
# grad.Interface(translate, inputs=['text',], outputs='text').launch()
|