vishnun commited on
Commit
5071fce
·
1 Parent(s): a527646

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import T5ForConditionalGeneration, AutoTokenizer
3
+
4
+ st.title("NeuralSpellChecker-Lite")
5
+ st.markdown('NeuralSpellChecker-Lite is a fine-tuned version of **pre-trained t5-small model** modelled on randomly selected 30000 sentences modified by imputing random noises and trained using transformers. It not only looks for _spelling errors but also looks for the semantics_ in the sentence and suggest other possible words for the incorrect word.')
6
+ ttokenizer = AutoTokenizer.from_pretrained("./")
7
+ tmodel = T5ForConditionalGeneration.from_pretrained('./')
8
+
9
+ form = st.form("NSC form")
10
+ input_text = form.text_input(label='Enter a random sentence')
11
+ submit = form.form_submit_button("Submit")
12
+
13
+ if submit:
14
+ input_ids = ttokenizer.encode('seq: '+ input_text, return_tensors='pt')
15
+
16
+ # generate text until the output length (which includes the context length) reaches 50
17
+ outputs = tmodel.generate(
18
+ input_ids,
19
+ do_sample=True,
20
+ max_length=50,
21
+ top_p=0.98,
22
+ num_return_sequences=3
23
+ )
24
+
25
+ st.subheader("Suggested sentences: ")
26
+
27
+ i = 0
28
+ for x in outputs:
29
+ out_text = ttokenizer.decode(x, skip_special_tokens=True)
30
+ i = i + 1
31
+ st.success(str(i) + '. ' + out_text)