eval / app.py
johvir's picture
Update app.py
96c098d
raw
history blame
864 Bytes
import streamlit as st
from transformers import T5ForConditionalGeneration, T5Tokenizer
sentence = st.text_area("enter some text")
if sentence:
model = T5ForConditionalGeneration.from_pretrained("t5-small")
tokenizer = T5Tokenizer.from_pretrained('t5-small')
tokenized_sentence = tokenizer('gec: ' + sentence, max_length=128, truncation=True, padding='max_length', return_tensors='pt')
corrected_sentence = tokenizer.decode(
model.generate(
input_ids = tokenized_sentence.input_ids,
attention_mask = tokenized_sentence.attention_mask,
max_length=128,
num_beams=5,
early_stopping=True,
)[0],
skip_special_tokens=True,
clean_up_tokenization_spaces=True
)
#print(corrected_sentence) # -> I like swimming.
st.json(corrected_sentence)