shamim237 commited on
Commit
1467bd0
1 Parent(s): 1091aaf

Update summary.py

Browse files
Files changed (1) hide show
  1. summary.py +8 -4
summary.py CHANGED
@@ -1,12 +1,16 @@
1
  import torch
 
2
  from transformers import PegasusForConditionalGeneration, AutoTokenizer
3
 
 
 
 
 
 
 
 
4
  def summarize(passage):
5
  txt = " ".join(passage)
6
- model_name = 'google/pegasus-cnn_dailymail'
7
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
- model = PegasusForConditionalGeneration.from_pretrained(model_name).to(device)
10
  batch = tokenizer(txt, truncation=True, padding='longest', return_tensors="pt").to(device)
11
  translated = model.generate(**batch)
12
  summy = tokenizer.batch_decode(translated, skip_special_tokens=True)
 
1
  import torch
2
+ import streamlit as st
3
  from transformers import PegasusForConditionalGeneration, AutoTokenizer
4
 
5
+ @st.cache(allow_output_mutation=True)
6
+
7
+ model_name = 'google/pegasus-cnn_dailymail'
8
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = PegasusForConditionalGeneration.from_pretrained(model_name).to(device)
11
+
12
  def summarize(passage):
13
  txt = " ".join(passage)
 
 
 
 
14
  batch = tokenizer(txt, truncation=True, padding='longest', return_tensors="pt").to(device)
15
  translated = model.generate(**batch)
16
  summy = tokenizer.batch_decode(translated, skip_special_tokens=True)