import gradio as gr from corrector import GrammarCorrector import difflib corrector = GrammarCorrector() def highlight_diffs(original, corrected): diff = difflib.ndiff(original.split(), corrected.split()) result = [] for word in diff: if word.startswith("-"): result.append(f"~~{word[2:]}~~") elif word.startswith("+"): result.append(f"**{word[2:]}**") elif word.startswith(" "): result.append(word[2:]) return " ".join(result) def fix_sentence(text): corrected = corrector.correct(text) highlighted = highlight_diffs(text, corrected) return corrected, highlighted gr.Interface( fn=fix_sentence, inputs=gr.Textbox(lines=2, label="Input Sentence"), outputs=[ gr.Textbox(label="Corrected Sentence"), gr.Markdown(label="Changes Highlighted") ], title="Context-Aware Grammar & Spell Checker", description="Fixes grammar and spelling using a T5-based model.", examples=[ ["She go to school every day."], ["I can has cheeseburger?"], ["The cat sleeped on the mat."], ["We was going to the park yesterday."], ["This is teh best day of my life!"], ["He no went to office today."], ["Their coming too the party."], ["I hopes you gets better soon."], ["Where is you going now?"], ["He do not likes pizza."] ] ).launch()