File size: 941 Bytes
501414a
 
54d16dd
501414a
54d16dd
 
501414a
4c121be
54d16dd
 
501414a
54d16dd
 
 
4c121be
54d16dd
 
 
 
 
dea2d5e
54d16dd
 
 
 
 
 
 
 
 
 
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
26
27
28
29
30
31
32
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=512)[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()