johvir commited on
Commit
96c098d
1 Parent(s): 805d0ae

Update app.py

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