Spaces:
Sleeping
Sleeping
File size: 1,013 Bytes
501414a 54d16dd 501414a 54d16dd 3bb05ba 501414a 4c121be 71e359d f304fac 501414a 71e359d 4c121be 71e359d dea2d5e 71e359d 54d16dd 71e359d 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-base-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()
|