Spaces:
Sleeping
Sleeping
File size: 971 Bytes
7a3385d 2fae333 7a3385d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
# Load your model and tokenizer
model_name = "akhmat-s/t5-base-grammar-corrector" # or "akhmat-s/t5-large-quant-grammar-corrector"
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
def correct_grammar(text):
inputs = tokenizer.encode("fix: " + text, return_tensors="pt", max_length=512, truncation=True)
outputs = model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return corrected_text
iface = gr.Interface(
fn=correct_grammar,
inputs=gr.Textbox(lines=5, label="Input Text"),
outputs=gr.Textbox(label="Corrected Text"),
title="Grammar Correction Chat",
description="Enter text with grammatical errors, and the model will provide corrections."
)
if __name__ == "__main__":
iface.launch()
|