Spaces:
Runtime error
Runtime error
Commit
·
b7b31e9
1
Parent(s):
569a47a
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
text = st.text_area('You is here')
|
3 |
+
### Run Model
|
4 |
+
from transformers import T5ForConditionalGeneration, T5Tokenizer, AutoTokenizer, AutoModelForSeq2SeqLM
|
5 |
+
import torch
|
6 |
+
torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained('deep-learning-analytics/GrammarCorrector')
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained('deep-learning-analytics/GrammarCorrector').to(torch_device)
|
9 |
+
|
10 |
+
def correct_grammar(input_text,num_return_sequences=1):
|
11 |
+
batch = tokenizer([input_text],truncation=True,padding='max_length',max_length=64, return_tensors="pt").to(torch_device)
|
12 |
+
translated = model.generate(**batch,max_length=64,num_beams=2, num_return_sequences=num_return_sequences, temperature=1.5)
|
13 |
+
tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
|
14 |
+
return tgt_text
|
15 |
+
|
16 |
+
if text:
|
17 |
+
result = correct_grammar(text)
|
18 |
+
st.json(result)
|