Spaces:
Runtime error
Runtime error
File size: 897 Bytes
02a0fc5 b7b31e9 3aa3a41 b7b31e9 3aa3a41 b7b31e9 d0f63c1 b7b31e9 d0f63c1 02a0fc5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import gradio as gr
### Run Model
from transformers import T5ForConditionalGeneration, T5Tokenizer
import torch
torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'
tokenizer = T5Tokenizer.from_pretrained('deep-learning-analytics/GrammarCorrector')
model = T5ForConditionalGeneration.from_pretrained('deep-learning-analytics/GrammarCorrector').to(torch_device)
def correct_grammar(input_text,num_return_sequences=1):
batch = tokenizer([input_text],truncation=True,padding='max_length',max_length=64, return_tensors="pt").to(torch_device)
results = model.generate(**batch,max_length=64,num_beams=2, num_return_sequences=num_return_sequences, temperature=1.5)
answer = tokenizer.batch_decode(results[0], skip_special_tokens=True)
return answer
iface = gr.Interface(fn=correct_grammar, inputs=[gr.inputs.Textbox(lines=5)], outputs=["text"])
iface.launch(inline=False, share=True) |