File size: 1,014 Bytes
501414a
 
6426c2a
501414a
6426c2a
2e9ef82
501414a
6426c2a
 
 
501414a
6426c2a
 
 
4c121be
6426c2a
 
 
 
 
dea2d5e
6426c2a
54d16dd
6426c2a
 
 
 
 
 
 
 
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=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()