Commit
·
dd76183
1
Parent(s):
3b04eac
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import PegasusForConditionalGeneration
|
3 |
+
from transformers import PegasusTokenizer
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
model_name = "google/pegasus-xsum"
|
7 |
+
pegasus_tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
8 |
+
def summarize(input_text):
|
9 |
+
nwords=len(input_text.split(" "))
|
10 |
+
# Define summarization pipeline
|
11 |
+
summarizer = pipeline("summarization", model=model_name, tokenizer=pegasus_tokenizer,min_length=int(nwords/10)+20, max_length=int(nwords/5+20), framework="pt")
|
12 |
+
summary=summarizer(input_text)[0]['summary_text']
|
13 |
+
return(summary)
|
14 |
+
gr.Interface(fn=summarize,inputs="textbox",outputs="textbox").launch(share="True");
|