Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
|
5 |
-
text = st.text_area("enter some text")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
3 |
|
4 |
+
sentence = st.text_area("enter some text")
|
|
|
5 |
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained("Unbabel/gec-t5_small")
|
7 |
+
tokenizer = T5Tokenizer.from_pretrained('t5-small')
|
8 |
+
|
9 |
+
tokenized_sentence = tokenizer('gec: ' + sentence, max_length=128, truncation=True, padding='max_length', return_tensors='pt')
|
10 |
+
corrected_sentence = tokenizer.decode(
|
11 |
+
model.generate(
|
12 |
+
input_ids = tokenized_sentence.input_ids,
|
13 |
+
attention_mask = tokenized_sentence.attention_mask,
|
14 |
+
max_length=128,
|
15 |
+
num_beams=5,
|
16 |
+
early_stopping=True,
|
17 |
+
)[0],
|
18 |
+
skip_special_tokens=True,
|
19 |
+
clean_up_tokenization_spaces=True
|
20 |
+
)
|
21 |
+
print(corrected_sentence) # -> I like swimming.
|
22 |
+
|
23 |
+
|
24 |
+
#if text:
|
25 |
+
#st.json(corrected_sentence)
|
26 |
|
27 |
|
28 |
|