Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -12,16 +12,25 @@ from heapq import nlargest
|
|
12 |
import warnings
|
13 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
14 |
import numpy as np
|
|
|
15 |
|
16 |
warnings.filterwarnings("ignore")
|
17 |
|
18 |
-
pegasus = gr.Interface.load("huggingface/google/pegasus-xsum")
|
19 |
-
|
20 |
def get_wiki_original_text(inp):
|
21 |
text = wikipedia.summary(inp)
|
22 |
return text
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def get_wiki_summary_by_lem(inp):
|
26 |
text = wikipedia.summary(inp)
|
27 |
|
@@ -111,7 +120,7 @@ sample = [['Europe'],['Great Depression'],['Crocodile Dundee']]
|
|
111 |
iface = Parallel(gr.Interface(fn=get_wiki_original_text, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Original Text'),
|
112 |
gr.Interface(fn=get_wiki_summary_by_lem, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Summary 1'),
|
113 |
gr.Interface(fn=get_wiki_summary_by_tfidf, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Summary 2'),
|
114 |
-
|
115 |
title= 'Text Summarizer',
|
116 |
description = desc,
|
117 |
examples=sample,
|
|
|
12 |
import warnings
|
13 |
from sklearn.feature_extraction.text import TfidfVectorizer
|
14 |
import numpy as np
|
15 |
+
from transformers import PegasusForConditionalGeneration
|
16 |
|
17 |
warnings.filterwarnings("ignore")
|
18 |
|
|
|
|
|
19 |
def get_wiki_original_text(inp):
|
20 |
text = wikipedia.summary(inp)
|
21 |
return text
|
22 |
|
23 |
|
24 |
+
def get_wiki_summary_by_pegasus(inp):
|
25 |
+
text = wikipedia.summary(inp)
|
26 |
+
tokenizer = gr.Interface.load("huggingface/google/pegasus-xsum")
|
27 |
+
tokens = tokenizer(text, truncation=True, padding="longest", return_tensors="pt")
|
28 |
+
model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
|
29 |
+
summary = model.generate(**tokens)
|
30 |
+
return tokenizer.decode(summary)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
def get_wiki_summary_by_lem(inp):
|
35 |
text = wikipedia.summary(inp)
|
36 |
|
|
|
120 |
iface = Parallel(gr.Interface(fn=get_wiki_original_text, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Original Text'),
|
121 |
gr.Interface(fn=get_wiki_summary_by_lem, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Summary 1'),
|
122 |
gr.Interface(fn=get_wiki_summary_by_tfidf, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Summary 2'),
|
123 |
+
gr.Interface(fn=get_wiki_summary_by_pegasus, inputs=gr.inputs.Textbox(label="Text"), outputs="text", description='Summary 3'),
|
124 |
title= 'Text Summarizer',
|
125 |
description = desc,
|
126 |
examples=sample,
|