Spaces:
Runtime error
Runtime error
Commit
·
78f4796
1
Parent(s):
626b394
updated app
Browse files
app.py
CHANGED
|
@@ -3,45 +3,45 @@ from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
|
|
| 3 |
|
| 4 |
@st.cache(show_spinner=False, persist=True)
|
| 5 |
def load_model(input_complex_sentence,model):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
def main():
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
|
|
|
|
| 3 |
|
| 4 |
@st.cache(show_spinner=False, persist=True)
|
| 5 |
def load_model(input_complex_sentence,model):
|
| 6 |
+
|
| 7 |
+
base_path = "flax-community/"
|
| 8 |
+
model_path = base_path + model
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
|
| 11 |
+
|
| 12 |
+
tokenized_sentence = tokenizer(input_complex_sentence,return_tensors="pt")
|
| 13 |
+
result = model.generate(tokenized_sentence['input_ids'],attention_mask = tokenized_sentence['attention_mask'],max_length=256,num_beams=5)
|
| 14 |
+
generated_sentence = tokenizer.decode(result[0],skip_special_tokens=True)
|
| 15 |
+
|
| 16 |
+
return generated_sentence
|
| 17 |
|
| 18 |
def main():
|
| 19 |
|
| 20 |
+
st.sidebar.title("🧠Sentence Simplifier")
|
| 21 |
+
st.title("Sentence Split in English using T5 Variants")
|
| 22 |
+
st.write("Sentence Split is the task of **dividing a long Complex Sentence into Simple Sentences**")
|
| 23 |
+
|
| 24 |
+
model = st.sidebar.selectbox(
|
| 25 |
+
"Please Choose the Model",
|
| 26 |
+
("t5-base-wikisplit","t5-v1_1-base-wikisplit", "byt5-base-wikisplit","t5-large-wikisplit"))
|
| 27 |
|
| 28 |
+
st.sidebar.write('''
|
| 29 |
+
## Applications:
|
| 30 |
+
* Sentence Simplification
|
| 31 |
+
* Data Augmentation
|
| 32 |
+
* Sentence Rephrase
|
| 33 |
+
''')
|
| 34 |
|
| 35 |
+
st.sidebar.write("[More Exploration](https://github.com/bhadreshpsavani/t5-sentence-split)")
|
| 36 |
+
|
| 37 |
+
example = "Mary likes to play football in her freetime whenever she meets with her friends that are very nice people."
|
| 38 |
+
input_complex_sentence = st.text_area("Please type a Complex Sentence to split",example)
|
| 39 |
|
| 40 |
+
if st.button('Split'):
|
| 41 |
+
with st.spinner("Spliting Sentence...🧠"):
|
| 42 |
+
generated_sentence = load_model(input_complex_sentence, model)
|
| 43 |
+
st.write(generated_sentence)
|
| 44 |
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
+
main()
|