Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
|
4 |
def check_grammar(sentence):
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
10 |
|
11 |
demo = gr.Interface(check_grammar, inputs=['text'],
|
12 |
outputs="text",
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
4 |
def check_grammar(sentence):
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("leslyarun/grammatical-error-correction")
|
6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("leslyarun/grammatical-error-correction")
|
7 |
+
|
8 |
+
inputs = tokenizer("grammar: " + sentence, truncation=True, return_tensors='pt')
|
9 |
+
|
10 |
+
output = model.generate(inputs['input_ids'], num_beams=5, max_length=512, early_stopping=True)
|
11 |
+
correction = tokenizer.batch_decode(output, skip_special_tokens=True)
|
12 |
+
return "".join(correction)
|
13 |
+
|
14 |
|
15 |
demo = gr.Interface(check_grammar, inputs=['text'],
|
16 |
outputs="text",
|