Spaces:
Running
Running
# app.py | |
import gradio as gr | |
import spacy | |
import language_tool_python | |
from transformers import pipeline | |
# --- load lightweight models once --- | |
nlp = spacy.load("en_core_web_sm") | |
tool = language_tool_python.LanguageTool('en-US') | |
para = pipeline("text2text-generation", model="Vamsi/T5_Paraphrase_Paws") | |
def humanize(text, tone, strength, freeze): | |
# detect entities to lock | |
locked = [(ent.text, ent.label_) for ent in nlp(text).ents] if freeze else [] | |
# paraphrase | |
paraphrased = para(text, max_length=512, do_sample=True, temperature=0.7 * strength / 10)[0]['generated_text'] | |
# grammar fix | |
paraphrased = tool.correct(paraphrased) | |
# restore locked entities | |
for ent, label in locked: | |
paraphrased = re.sub(re.escape(ent), ent, paraphrased, flags=re.IGNORECASE) | |
return paraphrased | |
# --- Gradio interface --- | |
import re | |
iface = gr.Interface( | |
fn=humanize, | |
inputs=[ | |
gr.Textbox(label="Paste or type your text here", lines=10, placeholder="Type or paste your AI text…"), | |
gr.Dropdown(["Casual", "Academic", "Marketing", "Legal", "Creative"], value="Casual", label="Tone"), | |
gr.Slider(1, 10, value=5, label="Humanize Strength (1 = subtle, 10 = aggressive)"), | |
gr.Checkbox(label="Lock facts / dates / names") | |
], | |
outputs=gr.Textbox(label="Humanized text", lines=10), | |
title="AI Humanizer – 100 % Free & Unlimited", | |
description="Zero sign-up, zero cost. Paste, choose options, click “Submit”." | |
) | |
iface.launch() |