bhadresh-savani's picture
Update app.py
626b394
raw
history blame
1.74 kB
import streamlit as st
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
@st.cache(show_spinner=False, persist=True)
def load_model(input_complex_sentence,model):
\t
\tbase_path = "flax-community/"
\tmodel_path = base_path + model
\ttokenizer = AutoTokenizer.from_pretrained(model_path)
\tmodel = AutoModelForSeq2SeqLM.from_pretrained(model_path)
\t
\ttokenized_sentence = tokenizer(input_complex_sentence,return_tensors="pt")
\tresult = model.generate(tokenized_sentence['input_ids'],attention_mask = tokenized_sentence['attention_mask'],max_length=256,num_beams=5)
\tgenerated_sentence = tokenizer.decode(result[0],skip_special_tokens=True)
\t
\treturn generated_sentence
def main():
\tst.sidebar.title("🧠 Sentence Simplifier")
\tst.title("Sentence Split in English using T5 Variants")
\tst.write("Sentence Split is the task of **dividing a long Complex Sentence into Simple Sentences**")
\t
\tmodel = st.sidebar.selectbox(
\t\t\t\t "Please Choose the Model",
\t\t\t\t ("t5-base-wikisplit","t5-v1_1-base-wikisplit", "byt5-base-wikisplit","t5-large-wikisplit"))
\tst.sidebar.write('''
\t\t## Applications:
\t\t* Sentence Simplification
\t\t* Data Augmentation
\t\t* Sentence Rephrase
\t''')
\tst.sidebar.write("[More Exploration](https://github.com/bhadreshpsavani/t5-sentence-split)")
\t
\texample = "Mary likes to play football in her freetime whenever she meets with her friends that are very nice people."
\tinput_complex_sentence = st.text_area("Please type a Complex Sentence to split",example)
\tif st.button('Split'):
\t\twith st.spinner("Spliting Sentence...🧠"):
\t\t\tgenerated_sentence = load_model(input_complex_sentence, model)
\t\tst.write(generated_sentence)
if __name__ == "__main__":
\tmain()