Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,15 @@ import torch, gradio as gr, re
|
|
| 4 |
# ------------------------
|
| 5 |
# Load Models
|
| 6 |
# ------------------------
|
| 7 |
-
# Stage 1: Paraphraser
|
| 8 |
paraphrase_model_name = "prithivida/parrot_paraphraser_on_T5"
|
| 9 |
paraphrase_tokenizer = AutoTokenizer.from_pretrained(paraphrase_model_name)
|
| 10 |
paraphrase_model = AutoModelForSeq2SeqLM.from_pretrained(paraphrase_model_name)
|
| 11 |
|
| 12 |
-
# Stage 2: Expander (
|
| 13 |
expander = pipeline(
|
| 14 |
"text2text-generation",
|
| 15 |
-
model="google/flan-t5-
|
| 16 |
device=0 if torch.cuda.is_available() else -1
|
| 17 |
)
|
| 18 |
|
|
@@ -46,13 +46,13 @@ def paraphrase_fn(text, num_return_sequences=1, temperature=1.2, top_p=0.92):
|
|
| 46 |
|
| 47 |
outputs = paraphrase_model.generate(
|
| 48 |
**inputs,
|
| 49 |
-
max_new_tokens=
|
| 50 |
num_return_sequences=int(num_return_sequences),
|
| 51 |
do_sample=True,
|
| 52 |
top_p=float(top_p),
|
| 53 |
temperature=float(temperature),
|
| 54 |
-
min_length=
|
| 55 |
-
length_penalty=1.
|
| 56 |
)
|
| 57 |
decoded = paraphrase_tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 58 |
|
|
@@ -69,16 +69,16 @@ def paraphrase_fn(text, num_return_sequences=1, temperature=1.2, top_p=0.92):
|
|
| 69 |
return " ".join(all_outputs).strip()
|
| 70 |
|
| 71 |
# ------------------------
|
| 72 |
-
# Stage 2: Expansion
|
| 73 |
# ------------------------
|
| 74 |
-
def expand_text(text, temperature=0.
|
| 75 |
expanded = expander(
|
| 76 |
-
f"
|
| 77 |
-
max_new_tokens=
|
| 78 |
temperature=float(temperature),
|
| 79 |
top_p=float(top_p)
|
| 80 |
)[0]['generated_text']
|
| 81 |
-
return expanded
|
| 82 |
|
| 83 |
# ------------------------
|
| 84 |
# Final Pipeline
|
|
@@ -90,7 +90,7 @@ def humanize_pipeline(text, variants=1, temperature=1.2, top_p=0.92):
|
|
| 90 |
# Stage 1: Paraphrase
|
| 91 |
base = paraphrase_fn(text, num_return_sequences=variants, temperature=temperature, top_p=top_p)
|
| 92 |
|
| 93 |
-
# Stage 2:
|
| 94 |
expanded = expand_text(base, temperature=temperature, top_p=top_p)
|
| 95 |
|
| 96 |
return expanded
|
|
@@ -107,8 +107,8 @@ iface = gr.Interface(
|
|
| 107 |
gr.Slider(0.6, 1.0, step=0.01, value=0.92, label="Top-p"),
|
| 108 |
],
|
| 109 |
outputs=gr.Textbox(label="Final Humanized Text"),
|
| 110 |
-
title="📝 Writenix Humanizer
|
| 111 |
-
description="Two-stage pipeline: Paraphrase +
|
| 112 |
)
|
| 113 |
|
| 114 |
iface.launch()
|
|
|
|
| 4 |
# ------------------------
|
| 5 |
# Load Models
|
| 6 |
# ------------------------
|
| 7 |
+
# Stage 1: Paraphraser (Parrot)
|
| 8 |
paraphrase_model_name = "prithivida/parrot_paraphraser_on_T5"
|
| 9 |
paraphrase_tokenizer = AutoTokenizer.from_pretrained(paraphrase_model_name)
|
| 10 |
paraphrase_model = AutoModelForSeq2SeqLM.from_pretrained(paraphrase_model_name)
|
| 11 |
|
| 12 |
+
# Stage 2: Lightweight Expander (flan-t5-small)
|
| 13 |
expander = pipeline(
|
| 14 |
"text2text-generation",
|
| 15 |
+
model="google/flan-t5-small",
|
| 16 |
device=0 if torch.cuda.is_available() else -1
|
| 17 |
)
|
| 18 |
|
|
|
|
| 46 |
|
| 47 |
outputs = paraphrase_model.generate(
|
| 48 |
**inputs,
|
| 49 |
+
max_new_tokens=64,
|
| 50 |
num_return_sequences=int(num_return_sequences),
|
| 51 |
do_sample=True,
|
| 52 |
top_p=float(top_p),
|
| 53 |
temperature=float(temperature),
|
| 54 |
+
min_length=10,
|
| 55 |
+
length_penalty=1.0
|
| 56 |
)
|
| 57 |
decoded = paraphrase_tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
| 58 |
|
|
|
|
| 69 |
return " ".join(all_outputs).strip()
|
| 70 |
|
| 71 |
# ------------------------
|
| 72 |
+
# Stage 2: Light Expansion
|
| 73 |
# ------------------------
|
| 74 |
+
def expand_text(text, temperature=0.7, top_p=0.9):
|
| 75 |
expanded = expander(
|
| 76 |
+
f"Lightly enhance this text by adding small natural words, transitions, or adjectives (like 'actually', 'quite', 'additionally', 'really'). Do NOT rewrite completely:\n{text}",
|
| 77 |
+
max_new_tokens=80,
|
| 78 |
temperature=float(temperature),
|
| 79 |
top_p=float(top_p)
|
| 80 |
)[0]['generated_text']
|
| 81 |
+
return expanded.strip()
|
| 82 |
|
| 83 |
# ------------------------
|
| 84 |
# Final Pipeline
|
|
|
|
| 90 |
# Stage 1: Paraphrase
|
| 91 |
base = paraphrase_fn(text, num_return_sequences=variants, temperature=temperature, top_p=top_p)
|
| 92 |
|
| 93 |
+
# Stage 2: Light Expansion
|
| 94 |
expanded = expand_text(base, temperature=temperature, top_p=top_p)
|
| 95 |
|
| 96 |
return expanded
|
|
|
|
| 107 |
gr.Slider(0.6, 1.0, step=0.01, value=0.92, label="Top-p"),
|
| 108 |
],
|
| 109 |
outputs=gr.Textbox(label="Final Humanized Text"),
|
| 110 |
+
title="📝 Writenix Humanizer v3 (Light Mode)",
|
| 111 |
+
description="Two-stage pipeline: Paraphrase + Subtle Expansion. Adds natural filler words, transitions, and adjectives instead of rewriting everything."
|
| 112 |
)
|
| 113 |
|
| 114 |
iface.launch()
|