VictorM-Coder commited on
Commit
aef9a98
·
verified ·
1 Parent(s): c63aa57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
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 (Flan-T5-Large)
13
  expander = pipeline(
14
  "text2text-generation",
15
- model="google/flan-t5-large",
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=128,
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=20,
55
- length_penalty=1.2
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.9, top_p=0.95):
75
  expanded = expander(
76
- f"Expand and make this text more detailed, natural, and human-like:\n{text}",
77
- max_new_tokens=250,
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: Expand & Smooth
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 v2",
111
- description="Two-stage pipeline: Paraphrase + Expand. Produces longer, more natural, human-like rewrites that are harder to detect."
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()