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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def normalize(self, text: str) -> str:
|
| 7 |
return re.sub(r"\s+", " ", (text or "").strip())
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
# =========================
|
| 12 |
|
| 13 |
def detect_intent(self, prompt: str) -> str:
|
| 14 |
-
p = (prompt
|
| 15 |
|
| 16 |
-
if
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
return "latest_info"
|
| 21 |
|
| 22 |
-
if
|
| 23 |
-
"tiktok", "hook", "cta", "short", "réel", "reel",
|
| 24 |
-
"vidéo courte", "contenu viral"
|
| 25 |
-
]):
|
| 26 |
return "tiktok"
|
| 27 |
|
| 28 |
-
if
|
| 29 |
-
"anime", "manga", "dragon ball", "naruto", "one piece",
|
| 30 |
-
"combat", "transformation"
|
| 31 |
-
]):
|
| 32 |
return "anime"
|
| 33 |
|
| 34 |
-
if
|
| 35 |
-
"histoire", "conte", "récit", "cinématique",
|
| 36 |
-
"immersif", "scene"
|
| 37 |
-
]):
|
| 38 |
return "story"
|
| 39 |
|
| 40 |
-
if
|
| 41 |
-
"explique", "définis", "c'est quoi",
|
| 42 |
-
"comment ça marche"
|
| 43 |
-
]):
|
| 44 |
return "explanation"
|
| 45 |
|
| 46 |
-
if
|
| 47 |
-
"business", "marketing", "client",
|
| 48 |
-
"vente", "produit"
|
| 49 |
-
]):
|
| 50 |
return "business"
|
| 51 |
|
| 52 |
-
if
|
| 53 |
-
"émotion", "triste", "amour", "motivant",
|
| 54 |
-
"espoir", "touchant"
|
| 55 |
-
]):
|
| 56 |
return "emotional"
|
| 57 |
|
| 58 |
return "general"
|
| 59 |
|
| 60 |
-
# =========================
|
| 61 |
-
# OPTIONAL BOOST
|
| 62 |
-
# =========================
|
| 63 |
-
|
| 64 |
def enhance_prompt(self, prompt: str, intent: str) -> str:
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
if intent == "anime":
|
| 68 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
if intent == "tiktok":
|
| 71 |
-
return
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
if intent == "emotional":
|
| 74 |
-
return
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
if intent == "story":
|
| 77 |
-
return
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
return
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
class PromptIntelligenceEngine:
|
| 5 |
+
def __init__(self):
|
| 6 |
+
self.story_keywords = [
|
| 7 |
+
"histoire",
|
| 8 |
+
"conte",
|
| 9 |
+
"récit",
|
| 10 |
+
"recit",
|
| 11 |
+
"cinématique",
|
| 12 |
+
"cinematique",
|
| 13 |
+
"immersif",
|
| 14 |
+
"immersion",
|
| 15 |
+
"scène",
|
| 16 |
+
"scene",
|
| 17 |
+
"suite logique",
|
| 18 |
+
"ville futuriste",
|
| 19 |
+
"ville abandonnée",
|
| 20 |
+
"ville abandonnee",
|
| 21 |
+
"se réveille",
|
| 22 |
+
"se reveille",
|
| 23 |
+
"seul être vivant",
|
| 24 |
+
"seul etre vivant",
|
| 25 |
+
"monde vide",
|
| 26 |
+
"survie",
|
| 27 |
+
"survit",
|
| 28 |
+
"découvre progressivement",
|
| 29 |
+
"decouvre progressivement",
|
| 30 |
+
"un homme se réveille",
|
| 31 |
+
"une femme se réveille",
|
| 32 |
+
"se réveille dans",
|
| 33 |
+
"se reveille dans",
|
| 34 |
+
"découvre qu'il est seul",
|
| 35 |
+
"decouvre qu'il est seul",
|
| 36 |
+
"se retrouve seul",
|
| 37 |
+
"réveil dans une ville",
|
| 38 |
+
"reveil dans une ville",
|
| 39 |
+
"ville vide",
|
| 40 |
+
"ville désertée",
|
| 41 |
+
"ville desertee"
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
self.anime_keywords = [
|
| 45 |
+
"anime",
|
| 46 |
+
"manga",
|
| 47 |
+
"dragon ball",
|
| 48 |
+
"dragon ball z",
|
| 49 |
+
"dragon ball super",
|
| 50 |
+
"naruto",
|
| 51 |
+
"one piece",
|
| 52 |
+
"bleach",
|
| 53 |
+
"snk",
|
| 54 |
+
"attaque des titans",
|
| 55 |
+
"combat",
|
| 56 |
+
"transformation",
|
| 57 |
+
"saïyen",
|
| 58 |
+
"saiyen",
|
| 59 |
+
"goku",
|
| 60 |
+
"vegeta",
|
| 61 |
+
"luffy",
|
| 62 |
+
"zoro",
|
| 63 |
+
"guerrier",
|
| 64 |
+
"ennemi invisible",
|
| 65 |
+
"nouvelle forme de puissance"
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
self.tiktok_keywords = [
|
| 69 |
+
"tiktok",
|
| 70 |
+
"hook",
|
| 71 |
+
"cta",
|
| 72 |
+
"short",
|
| 73 |
+
"shorts",
|
| 74 |
+
"réel",
|
| 75 |
+
"reel",
|
| 76 |
+
"réels",
|
| 77 |
+
"reels",
|
| 78 |
+
"script vidéo",
|
| 79 |
+
"script video",
|
| 80 |
+
"vidéo courte",
|
| 81 |
+
"video courte",
|
| 82 |
+
"contenu viral",
|
| 83 |
+
"fait surprenant",
|
| 84 |
+
"secret",
|
| 85 |
+
"presque personne ne connaît",
|
| 86 |
+
"presque personne ne connait",
|
| 87 |
+
"tu savais",
|
| 88 |
+
"incroyable",
|
| 89 |
+
"le cerveau influence",
|
| 90 |
+
"psychologie",
|
| 91 |
+
"smartphone",
|
| 92 |
+
"smartphones",
|
| 93 |
+
"presque personne ne le sait",
|
| 94 |
+
"personne ne connaît",
|
| 95 |
+
"personne ne connait",
|
| 96 |
+
"personne ne sait",
|
| 97 |
+
"le cerveau",
|
| 98 |
+
"influence nos décisions",
|
| 99 |
+
"influence nos decisions"
|
| 100 |
+
]
|
| 101 |
+
|
| 102 |
+
self.explanation_keywords = [
|
| 103 |
+
"explique",
|
| 104 |
+
"définis",
|
| 105 |
+
"definis",
|
| 106 |
+
"c'est quoi",
|
| 107 |
+
"c est quoi",
|
| 108 |
+
"qu'est-ce que",
|
| 109 |
+
"qu est ce que",
|
| 110 |
+
"comment ça marche",
|
| 111 |
+
"comment ca marche",
|
| 112 |
+
"en quelques lignes",
|
| 113 |
+
"simplement"
|
| 114 |
+
]
|
| 115 |
+
|
| 116 |
+
self.business_keywords = [
|
| 117 |
+
"business",
|
| 118 |
+
"vente",
|
| 119 |
+
"marketing",
|
| 120 |
+
"offre",
|
| 121 |
+
"client",
|
| 122 |
+
"clients",
|
| 123 |
+
"stratégie",
|
| 124 |
+
"strategie",
|
| 125 |
+
"commercial",
|
| 126 |
+
"produit",
|
| 127 |
+
"marque",
|
| 128 |
+
"branding",
|
| 129 |
+
"rentable",
|
| 130 |
+
"attirer plus de clients",
|
| 131 |
+
"attirer des clients",
|
| 132 |
+
"magasin",
|
| 133 |
+
"réparation téléphone",
|
| 134 |
+
"reparation telephone"
|
| 135 |
+
]
|
| 136 |
+
|
| 137 |
+
self.emotional_keywords = [
|
| 138 |
+
"triste",
|
| 139 |
+
"émotion",
|
| 140 |
+
"emotion",
|
| 141 |
+
"amour",
|
| 142 |
+
"rupture",
|
| 143 |
+
"touchant",
|
| 144 |
+
"inspirant",
|
| 145 |
+
"motivant",
|
| 146 |
+
"poétique",
|
| 147 |
+
"poetique",
|
| 148 |
+
"reprend espoir",
|
| 149 |
+
"espoir",
|
| 150 |
+
"période difficile",
|
| 151 |
+
"periode difficile",
|
| 152 |
+
"texte touchant",
|
| 153 |
+
"retrouve progressivement espoir",
|
| 154 |
+
"petits moments du quotidien",
|
| 155 |
+
"retrouve l'espoir",
|
| 156 |
+
"retrouve espoir",
|
| 157 |
+
"une femme traverse une période difficile",
|
| 158 |
+
"une femme traverse une periode difficile"
|
| 159 |
+
]
|
| 160 |
+
|
| 161 |
+
self.latest_info_keywords = [
|
| 162 |
+
"dernière sortie",
|
| 163 |
+
"derniere sortie",
|
| 164 |
+
"dernières sorties",
|
| 165 |
+
"dernieres sorties",
|
| 166 |
+
"à jour",
|
| 167 |
+
"a jour",
|
| 168 |
+
"actuel",
|
| 169 |
+
"actualité",
|
| 170 |
+
"actualite",
|
| 171 |
+
"en ce moment",
|
| 172 |
+
"latest",
|
| 173 |
+
"news",
|
| 174 |
+
"nouveauté",
|
| 175 |
+
"nouveaute",
|
| 176 |
+
"date précise",
|
| 177 |
+
"date precise",
|
| 178 |
+
"sortie ps5",
|
| 179 |
+
"jeux ps5"
|
| 180 |
+
]
|
| 181 |
|
| 182 |
def normalize(self, text: str) -> str:
|
| 183 |
return re.sub(r"\s+", " ", (text or "").strip())
|
| 184 |
|
| 185 |
+
def _contains_any(self, text: str, keywords) -> bool:
|
| 186 |
+
return any(keyword in text for keyword in keywords)
|
|
|
|
| 187 |
|
| 188 |
def detect_intent(self, prompt: str) -> str:
|
| 189 |
+
p = self.normalize(prompt).lower()
|
| 190 |
|
| 191 |
+
if not p:
|
| 192 |
+
return "general"
|
| 193 |
+
|
| 194 |
+
if self._contains_any(p, self.latest_info_keywords):
|
| 195 |
return "latest_info"
|
| 196 |
|
| 197 |
+
if self._contains_any(p, self.tiktok_keywords):
|
|
|
|
|
|
|
|
|
|
| 198 |
return "tiktok"
|
| 199 |
|
| 200 |
+
if self._contains_any(p, self.anime_keywords):
|
|
|
|
|
|
|
|
|
|
| 201 |
return "anime"
|
| 202 |
|
| 203 |
+
if self._contains_any(p, self.story_keywords):
|
|
|
|
|
|
|
|
|
|
| 204 |
return "story"
|
| 205 |
|
| 206 |
+
if self._contains_any(p, self.explanation_keywords):
|
|
|
|
|
|
|
|
|
|
| 207 |
return "explanation"
|
| 208 |
|
| 209 |
+
if self._contains_any(p, self.business_keywords):
|
|
|
|
|
|
|
|
|
|
| 210 |
return "business"
|
| 211 |
|
| 212 |
+
if self._contains_any(p, self.emotional_keywords):
|
|
|
|
|
|
|
|
|
|
| 213 |
return "emotional"
|
| 214 |
|
| 215 |
return "general"
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
def enhance_prompt(self, prompt: str, intent: str) -> str:
|
| 218 |
+
clean = self.normalize(prompt)
|
| 219 |
+
|
| 220 |
+
if not clean:
|
| 221 |
+
return clean
|
| 222 |
|
| 223 |
if intent == "anime":
|
| 224 |
+
return (
|
| 225 |
+
f"{clean}. "
|
| 226 |
+
"Même personnage principal du début à la fin, progression nette du combat, "
|
| 227 |
+
"mise en scène dynamique, vraie montée en puissance, scènes visuellement différentes."
|
| 228 |
+
)
|
| 229 |
|
| 230 |
if intent == "tiktok":
|
| 231 |
+
return (
|
| 232 |
+
f"{clean}. "
|
| 233 |
+
"Structure courte, claire, percutante, avec hook fort, montée d'intérêt et fin marquante."
|
| 234 |
+
)
|
| 235 |
|
| 236 |
if intent == "emotional":
|
| 237 |
+
return (
|
| 238 |
+
f"{clean}. "
|
| 239 |
+
"Même personne du début à la fin, émotion sincère, progression douce, visuels humains et réalistes."
|
| 240 |
+
)
|
| 241 |
|
| 242 |
if intent == "story":
|
| 243 |
+
return (
|
| 244 |
+
f"{clean}. "
|
| 245 |
+
"Même sujet principal du début à la fin, continuité narrative claire, scènes distinctes et immersives."
|
| 246 |
+
)
|
| 247 |
|
| 248 |
+
return clean
|