import gradio as gr from transformers import pipeline import difflib # Use a solid grammar correction + improvement model pipe = pipeline("text2text-generation", model="pszemraj/flan-t5-large-grammar-synthesis") def respond(prompt): # Generate revised essay revised = pipe(prompt, max_new_tokens=1024)[0]['generated_text'] # Generate a word-level diff diff = difflib.ndiff(prompt.split(), revised.split()) changes = [line for line in diff if line.startswith("- ") or line.startswith("+ ")] # Format explanation if changes: explanation = "\n".join(changes) else: explanation = "No significant changes were made. Minor improvements only." return f"šŸ“ Revised Essay:\n\n{revised}\n\nšŸ› ļø Explanation of Changes:\n\n{explanation}" # Set up Gradio interface gr.Interface( fn=respond, inputs="text", outputs="text", title="Free AI Essay Bot", description="Paste an essay below. The AI will revise it and explain the changes." ).launch()