Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,68 +159,33 @@ def paraphrase_text(text, replace_ratio=0.6):
|
|
| 159 |
import re
|
| 160 |
|
| 161 |
def humanize_text(AI_text):
|
| 162 |
-
"""
|
| 163 |
response = client.chat.completions.create(
|
| 164 |
-
model=finetuned_model,
|
| 165 |
-
temperature=1.
|
| 166 |
-
max_tokens=
|
| 167 |
-
top_p=0.
|
| 168 |
-
frequency_penalty=0.
|
| 169 |
-
presence_penalty=0.
|
| 170 |
messages=[
|
| 171 |
{"role": "system", "content": """
|
| 172 |
-
You are
|
| 173 |
-
- Use
|
| 174 |
-
-
|
| 175 |
-
-
|
| 176 |
-
-
|
| 177 |
-
- Use real-world examples when applicable.
|
| 178 |
"""},
|
| 179 |
-
{"role": "user", "content": f"Rewrite this text
|
| 180 |
]
|
| 181 |
)
|
| 182 |
|
| 183 |
gpt_output = response.choices[0].message.content.strip()
|
| 184 |
|
| 185 |
-
#
|
| 186 |
humanized_text = paraphrase_text(gpt_output)
|
| 187 |
-
|
| 188 |
-
# Introduce subtle "human-like" errors
|
| 189 |
-
humanized_text = introduce_human_errors(humanized_text)
|
| 190 |
|
| 191 |
return humanized_text
|
| 192 |
|
| 193 |
-
def introduce_human_errors(text):
|
| 194 |
-
"""Adds slight human-like errors to avoid AI detection."""
|
| 195 |
-
# Replace some words with informal/slang-like versions
|
| 196 |
-
replacements = {
|
| 197 |
-
"because": "cuz",
|
| 198 |
-
"going to": "gonna",
|
| 199 |
-
"cannot": "can't",
|
| 200 |
-
"do not": "don't",
|
| 201 |
-
"you are": "you're",
|
| 202 |
-
"about": "'bout",
|
| 203 |
-
"until": "til",
|
| 204 |
-
}
|
| 205 |
-
|
| 206 |
-
for word, replacement in replacements.items():
|
| 207 |
-
text = re.sub(rf"\b{word}\b", replacement, text, flags=re.IGNORECASE)
|
| 208 |
-
|
| 209 |
-
# Add minor typos (randomly swap letters)
|
| 210 |
-
if random.random() < 0.2:
|
| 211 |
-
words = text.split()
|
| 212 |
-
idx = random.randint(0, len(words) - 1)
|
| 213 |
-
if len(words[idx]) > 4:
|
| 214 |
-
typo_word = list(words[idx])
|
| 215 |
-
swap_idx = random.randint(0, len(typo_word) - 2)
|
| 216 |
-
typo_word[swap_idx], typo_word[swap_idx + 1] = typo_word[swap_idx + 1], typo_word[swap_idx]
|
| 217 |
-
words[idx] = "".join(typo_word)
|
| 218 |
-
text = " ".join(words)
|
| 219 |
-
|
| 220 |
-
return text
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
|
| 225 |
# Define the main function to process text
|
| 226 |
def main_function(AI_text):
|
|
|
|
| 159 |
import re
|
| 160 |
|
| 161 |
def humanize_text(AI_text):
|
| 162 |
+
"""Humanizes AI-generated text using GPT + Paraphrasing."""
|
| 163 |
response = client.chat.completions.create(
|
| 164 |
+
model=finetuned_model, # This remains the same (gpt-3.5-turbo)
|
| 165 |
+
temperature=1.1, # Increased for more variation
|
| 166 |
+
max_tokens=500,
|
| 167 |
+
top_p=0.95,
|
| 168 |
+
frequency_penalty=0.3,
|
| 169 |
+
presence_penalty=0.5,
|
| 170 |
messages=[
|
| 171 |
{"role": "system", "content": """
|
| 172 |
+
You are an advanced AI text rewriter that makes AI-generated text sound fully human-written.
|
| 173 |
+
- Use natural synonyms, contractions, and varied sentence structures.
|
| 174 |
+
- Restructure sentences to be complex and nuanced.
|
| 175 |
+
- Avoid robotic phrasing or overly formal structures.
|
| 176 |
+
- Ensure the text feels like it was written by a real person.
|
|
|
|
| 177 |
"""},
|
| 178 |
+
{"role": "user", "content": f"Rewrite this text to make it more human:\n\n{AI_text}"}
|
| 179 |
]
|
| 180 |
)
|
| 181 |
|
| 182 |
gpt_output = response.choices[0].message.content.strip()
|
| 183 |
|
| 184 |
+
# Apply additional paraphrasing to GPT output
|
| 185 |
humanized_text = paraphrase_text(gpt_output)
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
return humanized_text
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
# Define the main function to process text
|
| 191 |
def main_function(AI_text):
|