Check / app.py
Vivek12345323's picture
Update app.py
2e9ef82 verified
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()