Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -144,7 +144,7 @@ class HumanLikeVariations:
|
|
| 144 |
]
|
| 145 |
|
| 146 |
def add_human_touch(self, text):
|
| 147 |
-
"""Add subtle human-like imperfections -
|
| 148 |
sentences = text.split('. ')
|
| 149 |
modified_sentences = []
|
| 150 |
|
|
@@ -152,115 +152,15 @@ class HumanLikeVariations:
|
|
| 152 |
if not sent.strip():
|
| 153 |
continue
|
| 154 |
|
| 155 |
-
#
|
| 156 |
-
|
| 157 |
-
if not words:
|
| 158 |
-
continue
|
| 159 |
-
|
| 160 |
-
# Occasionally start with casual transition (25% chance)
|
| 161 |
-
if i > 0 and random.random() < 0.25 and len(words) > 5:
|
| 162 |
-
# Choose transitions based on sentence type
|
| 163 |
-
if any(q in sent.lower() for q in ['why', 'how', 'what', 'when', 'where']):
|
| 164 |
-
# Question-appropriate transitions
|
| 165 |
-
transition = random.choice(["So, ", "Well, ", "Now, ", "Okay, ", "Right, "])
|
| 166 |
-
elif any(w in sent.lower() for w in ['however', 'but', 'although', 'despite']):
|
| 167 |
-
# Contrast-appropriate transitions
|
| 168 |
-
transition = random.choice(["Still, ", "Yet, ", "Even so, ", "That said, ", "Nonetheless, "])
|
| 169 |
-
else:
|
| 170 |
-
# General transitions
|
| 171 |
-
transition = random.choice(self.casual_transitions[:20]) # Use more common ones
|
| 172 |
-
|
| 173 |
-
sent = transition + sent[0].lower() + sent[1:] if len(sent) > 1 else sent
|
| 174 |
-
|
| 175 |
-
# Add filler words occasionally (20% chance) - SMARTER PLACEMENT
|
| 176 |
-
if random.random() < 0.2 and len(words) > 8:
|
| 177 |
-
# Find good positions for fillers (after verbs, before adjectives, etc.)
|
| 178 |
-
good_positions = []
|
| 179 |
-
|
| 180 |
-
for idx, word in enumerate(words):
|
| 181 |
-
if idx > 0 and idx < len(words) - 1:
|
| 182 |
-
# After "is/are/was/were" (good for "really", "actually", etc.)
|
| 183 |
-
if word.lower() in ['is', 'are', 'was', 'were', 'been', 'be']:
|
| 184 |
-
good_positions.append(idx + 1)
|
| 185 |
-
# Before adjectives (good for "quite", "rather", etc.)
|
| 186 |
-
elif words[idx-1].lower() in ['a', 'an', 'the', 'very', 'so']:
|
| 187 |
-
good_positions.append(idx)
|
| 188 |
-
# After "can/could/will/would" (good for "probably", "definitely", etc.)
|
| 189 |
-
elif word.lower() in ['can', 'could', 'will', 'would', 'should', 'might', 'may']:
|
| 190 |
-
good_positions.append(idx + 1)
|
| 191 |
-
|
| 192 |
-
if good_positions:
|
| 193 |
-
insert_pos = random.choice(good_positions)
|
| 194 |
-
# Choose appropriate filler based on context
|
| 195 |
-
if words[insert_pos-1].lower() in ['is', 'are', 'was', 'were']:
|
| 196 |
-
filler = random.choice(['really', 'actually', 'definitely', 'certainly', 'quite'])
|
| 197 |
-
elif words[insert_pos-1].lower() in ['can', 'could', 'will', 'would']:
|
| 198 |
-
filler = random.choice(['probably', 'definitely', 'certainly', 'likely', 'possibly'])
|
| 199 |
-
else:
|
| 200 |
-
filler = random.choice(['quite', 'rather', 'pretty', 'fairly', 'somewhat'])
|
| 201 |
-
|
| 202 |
-
words.insert(insert_pos, filler)
|
| 203 |
-
sent = ' '.join(words)
|
| 204 |
-
|
| 205 |
-
# Add varied sentence starters (15% chance) - MORE LOGICAL
|
| 206 |
-
if i > 0 and random.random() < 0.15 and len(words) > 10:
|
| 207 |
-
# Choose starters based on sentence content
|
| 208 |
-
if any(w in sent.lower() for w in ['research', 'study', 'data', 'evidence']):
|
| 209 |
-
starter = random.choice(["Research shows", "Studies indicate", "Evidence suggests", "Data reveals"])
|
| 210 |
-
elif any(w in sent.lower() for w in ['important', 'crucial', 'vital', 'essential']):
|
| 211 |
-
starter = random.choice(["It's worth noting that", "Keep in mind", "Bear in mind that", "The key here is"])
|
| 212 |
-
else:
|
| 213 |
-
starter = random.choice(["When it comes to", "As for", "Regarding", "In terms of"])
|
| 214 |
-
|
| 215 |
-
sent = starter + " " + sent[0].lower() + sent[1:] if len(sent) > 1 else sent
|
| 216 |
|
| 217 |
# Occasionally use contractions (35% chance)
|
| 218 |
if random.random() < 0.35:
|
| 219 |
sent = self.apply_contractions(sent)
|
| 220 |
|
| 221 |
-
#
|
| 222 |
-
|
| 223 |
-
# Only do this with independent clauses
|
| 224 |
-
parts = sent.split(', ')
|
| 225 |
-
if len(parts) == 2:
|
| 226 |
-
# Check if both parts could be sentences
|
| 227 |
-
if (len(parts[0].split()) > 4 and len(parts[1].split()) > 4 and
|
| 228 |
-
any(v in parts[1].lower().split()[:3] for v in ['it', 'this', 'that', 'they', 'we', 'i', 'you'])):
|
| 229 |
-
sent = parts[0] + ', ' + parts[1] # Keep the comma splice
|
| 230 |
-
|
| 231 |
-
# NEW: Add parenthetical thoughts (8% chance) - CONTEXT-AWARE
|
| 232 |
-
if random.random() < 0.08 and len(words) > 15:
|
| 233 |
-
# Find natural break points (after complete thoughts)
|
| 234 |
-
break_points = []
|
| 235 |
-
for idx, word in enumerate(words):
|
| 236 |
-
if idx > len(words)//3 and idx < 2*len(words)//3:
|
| 237 |
-
if word.endswith(',') or words[idx-1].lower() in ['is', 'are', 'was', 'were']:
|
| 238 |
-
break_points.append(idx)
|
| 239 |
-
|
| 240 |
-
if break_points:
|
| 241 |
-
insert_pos = random.choice(break_points)
|
| 242 |
-
# Choose relevant parenthetical
|
| 243 |
-
if any(w in sent.lower() for w in ['surprising', 'interesting', 'amazing']):
|
| 244 |
-
parenthetical = random.choice(["(and that's saying something)", "(believe it or not)", "(surprisingly enough)"])
|
| 245 |
-
elif any(w in sent.lower() for w in ['obvious', 'clear', 'evident']):
|
| 246 |
-
parenthetical = random.choice(["(obviously)", "(clearly)", "(of course)"])
|
| 247 |
-
else:
|
| 248 |
-
parenthetical = random.choice(["(which makes sense)", "(for good reason)", "(as you'd expect)"])
|
| 249 |
-
|
| 250 |
-
words.insert(insert_pos, parenthetical)
|
| 251 |
-
sent = ' '.join(words)
|
| 252 |
-
|
| 253 |
-
# NEW: Occasionally add rhetorical questions (5% chance) - ONLY AT PARAGRAPH ENDS
|
| 254 |
-
if random.random() < 0.05 and i == len(sentences) - 1:
|
| 255 |
-
# Choose question based on sentence content
|
| 256 |
-
if any(w in sent.lower() for w in ['amazing', 'incredible', 'fantastic']):
|
| 257 |
-
question = random.choice(["Pretty cool, right?", "Amazing, isn't it?", "Impressive, huh?"])
|
| 258 |
-
elif any(w in sent.lower() for w in ['important', 'crucial', 'essential']):
|
| 259 |
-
question = random.choice(["Makes sense, right?", "See what I mean?", "Important to remember, yeah?"])
|
| 260 |
-
else:
|
| 261 |
-
question = random.choice(["Interesting, right?", "Makes you think, doesn't it?", "Sound familiar?"])
|
| 262 |
-
|
| 263 |
-
sent = sent + " " + question
|
| 264 |
|
| 265 |
modified_sentences.append(sent)
|
| 266 |
|
|
|
|
| 144 |
]
|
| 145 |
|
| 146 |
def add_human_touch(self, text):
|
| 147 |
+
"""Add subtle human-like imperfections - WITHOUT RANDOM FILLERS"""
|
| 148 |
sentences = text.split('. ')
|
| 149 |
modified_sentences = []
|
| 150 |
|
|
|
|
| 152 |
if not sent.strip():
|
| 153 |
continue
|
| 154 |
|
| 155 |
+
# Skip adding random transitions and fillers
|
| 156 |
+
# Only keep natural, meaningful modifications
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
# Occasionally use contractions (35% chance)
|
| 159 |
if random.random() < 0.35:
|
| 160 |
sent = self.apply_contractions(sent)
|
| 161 |
|
| 162 |
+
# Skip parenthetical thoughts - they can be random
|
| 163 |
+
# Skip rhetorical questions - they can be random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
modified_sentences.append(sent)
|
| 166 |
|