Spaces:
Runtime error
Runtime error
Commit
·
558653a
1
Parent(s):
42a66f5
updated app
Browse files
app.py
CHANGED
|
@@ -2,24 +2,33 @@ import streamlit as st
|
|
| 2 |
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
@st.cache(persist=True)
|
| 5 |
-
def load_model(input_complex_sentence,model):
|
| 6 |
-
|
| 7 |
-
base_path = "flax-community/"
|
| 8 |
-
model_path = base_path + model
|
| 9 |
-
print(model_path)
|
| 10 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 11 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
| 12 |
|
| 13 |
tokenized_sentence = tokenizer(input_complex_sentence,return_tensors="pt")
|
| 14 |
result = model.generate(tokenized_sentence['input_ids'],attention_mask = tokenized_sentence['attention_mask'],max_length=256,num_beams=5)
|
| 15 |
-
print(result)
|
| 16 |
generated_sentence = tokenizer.decode(result[0],skip_special_tokens=True)
|
| 17 |
|
| 18 |
return generated_sentence
|
| 19 |
|
| 20 |
def main():
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
st.write("Sentence Split is the task of dividing a long Sentence into multiple Sentences")
|
| 24 |
|
| 25 |
model = st.sidebar.selectbox(
|
|
@@ -31,8 +40,15 @@ def main():
|
|
| 31 |
input_complex_sentence = st.text_area("Please type a long Sentence to split",example)
|
| 32 |
|
| 33 |
if st.button('Simplify'):
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
st.write(generated_sentence)
|
| 37 |
|
| 38 |
|
|
|
|
| 2 |
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
@st.cache(persist=True)
|
| 5 |
+
def load_model(input_complex_sentence,model, tokenizer):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
tokenized_sentence = tokenizer(input_complex_sentence,return_tensors="pt")
|
| 8 |
result = model.generate(tokenized_sentence['input_ids'],attention_mask = tokenized_sentence['attention_mask'],max_length=256,num_beams=5)
|
|
|
|
| 9 |
generated_sentence = tokenizer.decode(result[0],skip_special_tokens=True)
|
| 10 |
|
| 11 |
return generated_sentence
|
| 12 |
|
| 13 |
def main():
|
| 14 |
|
| 15 |
+
t5_base_path = "flax-community/t5-base-wikisplit"
|
| 16 |
+
t5_base_tokenizer = AutoTokenizer.from_pretrained(t5_base_path)
|
| 17 |
+
t5_base_model = AutoModelForSeq2SeqLM.from_pretrained(t5_base_path)
|
| 18 |
+
|
| 19 |
+
t5_v1_1_base_path = "flax-community/t5-v1_1-base-wikisplit"
|
| 20 |
+
t5_v1_1_base_tokenizer = AutoTokenizer.from_pretrained(t5_v1_1_base_path)
|
| 21 |
+
t5_v1_1_base_model = AutoModelForSeq2SeqLM.from_pretrained(t5_v1_1_base_path)
|
| 22 |
+
|
| 23 |
+
byt5_base_path = "flax-community/byt5-base-wikisplit"
|
| 24 |
+
byt5_base_tokenizer = AutoTokenizer.from_pretrained(byt5_base_path)
|
| 25 |
+
byt5_base_model = AutoModelForSeq2SeqLM.from_pretrained(byt5_base_path)
|
| 26 |
+
|
| 27 |
+
t5_large_path = "flax-community/t5-large-wikisplit"
|
| 28 |
+
t5_large_tokenizer = AutoTokenizer.from_pretrained(t5_large_path)
|
| 29 |
+
t5_large_model = AutoModelForSeq2SeqLM.from_pretrained(t5_large_path)
|
| 30 |
+
|
| 31 |
+
st.title("✂️ Sentence Split in English using T5 variants")
|
| 32 |
st.write("Sentence Split is the task of dividing a long Sentence into multiple Sentences")
|
| 33 |
|
| 34 |
model = st.sidebar.selectbox(
|
|
|
|
| 40 |
input_complex_sentence = st.text_area("Please type a long Sentence to split",example)
|
| 41 |
|
| 42 |
if st.button('Simplify'):
|
| 43 |
+
|
| 44 |
+
if model=="t5-base-wikisplit":
|
| 45 |
+
generated_sentence = load_model(input_complex_sentence, t5_base_model, t5_base_tokenizer)
|
| 46 |
+
elif model=="t5-v1_1-base-wikisplit":
|
| 47 |
+
generated_sentence = load_model(input_complex_sentence, t5_v1_1_base_model, t5_v1_1_base_tokenizer)
|
| 48 |
+
elif model=="byt5-base-wikisplit":
|
| 49 |
+
generated_sentence = load_model(input_complex_sentence, byt5_base_model, byt5_base_tokenizer)
|
| 50 |
+
else:
|
| 51 |
+
generated_sentence = load_model(input_complex_sentence, t5_large_model, t5_large_tokenizer)
|
| 52 |
st.write(generated_sentence)
|
| 53 |
|
| 54 |
|