File size: 879 Bytes
35fdc6e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import streamlit as st
import torch
import pandas as pd
st.write("""# Summerize your text""")
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("tokenizer")
model = AutoModelForSeq2SeqLM.from_pretrained("pegasus_summery_model")
text_input = st.text_area("text to summerize")
if text_input:
tokenized_text = tokenizer.encode_plus(
str(text_input),
return_attention_mask= True,
return_tensors='pt'
)
generated_token = model.generate(
input_ids = tokenized_text['input_ids'],
attention_mask = tokenized_text["attention_mask"],
use_cache=True,)
pred = [tokenizer.decode(token_ids=ids, skip_special_tokens=True)for ids in generated_token]
st.write("## Summerized Text")
st.write(" ".join(pred)) |