Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,19 @@
|
|
1 |
-
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
model_name = "ailm/pegsus-text-summarization"
|
5 |
-
model = PegasusForConditionalGeneration.from_pretrained(model_name)
|
6 |
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
7 |
|
|
|
8 |
def summarize(text):
|
9 |
-
tokens = tokenizer(text, truncation=True, padding="longest", return_tensors="pt")
|
10 |
summary = model.generate(**tokens)
|
11 |
return tokenizer.decode(summary[0], skip_special_tokens=True)
|
12 |
|
13 |
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
14 |
-
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
+
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
|
4 |
+
import torch
|
5 |
+
|
6 |
+
device = 'cuda'
|
7 |
|
8 |
model_name = "ailm/pegsus-text-summarization"
|
9 |
+
model = PegasusForConditionalGeneration.from_pretrained(model_name).to(device)
|
10 |
tokenizer = PegasusTokenizer.from_pretrained(model_name)
|
11 |
|
12 |
+
@spaces.GPU
|
13 |
def summarize(text):
|
14 |
+
tokens = tokenizer(text, truncation=True, padding="longest", return_tensors="pt").to(device)
|
15 |
summary = model.generate(**tokens)
|
16 |
return tokenizer.decode(summary[0], skip_special_tokens=True)
|
17 |
|
18 |
iface = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
19 |
+
iface.launch()
|