Update app.py
Browse files
app.py
CHANGED
@@ -60,9 +60,73 @@ Je crois fermement en l'autodidaxie et considère la capacité à communiquer av
|
|
60 |
is_first_interaction = True
|
61 |
|
62 |
def determine_response_type(message):
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
message_lower = message.lower()
|
67 |
if any(keyword in message_lower for keyword in short_response_keywords):
|
68 |
return "short"
|
@@ -72,16 +136,30 @@ def determine_response_type(message):
|
|
72 |
return "medium"
|
73 |
|
74 |
def post_process_response(response, is_short_response):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
if is_short_response:
|
76 |
-
|
77 |
-
if len(sentences) > 2:
|
78 |
-
return ' '.join(sentences[:2]).strip()
|
79 |
return response.strip()
|
80 |
else:
|
81 |
-
|
82 |
-
|
83 |
-
return ' '.join(sentences[:-1]).strip()
|
84 |
-
return response.strip()
|
85 |
|
86 |
def check_coherence(response):
|
87 |
sentences = re.split(r'(?<=[.!?])\s+', response)
|
|
|
60 |
is_first_interaction = True
|
61 |
|
62 |
def determine_response_type(message):
|
63 |
+
# Liste améliorée de mots-clés pour les réponses courtes
|
64 |
+
short_response_keywords = [
|
65 |
+
"salut", "Salut", "SALUT",
|
66 |
+
"bonjour", "Bonjour", "BONJOUR",
|
67 |
+
"ça va", "ca va", "Ça va", "Ca va", "ÇA VA", "CA VA",
|
68 |
+
"comment tu vas", "Comment tu vas", "COMMENT TU VAS",
|
69 |
+
"comment vas tu", "Comment vas tu", "COMMENT VAS TU",
|
70 |
+
"comment vas-tu", "Comment vas-tu", "COMMENT VAS-TU",
|
71 |
+
"quoi de neuf", "Quoi de neuf", "QUOI DE NEUF",
|
72 |
+
"coucou", "Coucou", "COUCOU",
|
73 |
+
"hello", "Hello", "HELLO",
|
74 |
+
"hi", "Hi", "HI",
|
75 |
+
"tu fais quoi", "Tu fais quoi", "TU FAIS QUOI",
|
76 |
+
"?!", "?!?", "!?",
|
77 |
+
"bye", "Bye", "BYE",
|
78 |
+
"au revoir", "Au revoir", "AU REVOIR",
|
79 |
+
"à plus", "À plus", "A plus", "a plus", "À PLUS", "A PLUS",
|
80 |
+
"bonsoir", "Bonsoir", "BONSOIR",
|
81 |
+
"merci", "Merci", "MERCI",
|
82 |
+
"d'accord", "D'accord", "D'ACCORD",
|
83 |
+
"ok", "Ok", "OK",
|
84 |
+
"super", "Super", "SUPER",
|
85 |
+
"cool", "Cool", "COOL",
|
86 |
+
"génial", "Génial", "GENIAL",
|
87 |
+
"wow", "Wow", "WOW"
|
88 |
+
]
|
89 |
+
|
90 |
+
# Liste améliorée de mots-clés pour les réponses longues
|
91 |
+
long_response_keywords = [
|
92 |
+
"présente", "Présente", "PRÉSENTE", "presente", "Presente", "PRESENTE",
|
93 |
+
"parle moi de", "Parle moi de", "PARLE MOI DE",
|
94 |
+
"parle-moi de", "Parle-moi de", "PARLE-MOI DE",
|
95 |
+
"explique", "Explique", "EXPLIQUE",
|
96 |
+
"raconte", "Raconte", "RACONTE",
|
97 |
+
"décris", "Décris", "DÉCRIS", "decris", "Decris", "DECRIS",
|
98 |
+
"dis moi", "Dis moi", "DIS MOI",
|
99 |
+
"dis-moi", "Dis-moi", "DIS-MOI",
|
100 |
+
"détaille", "Détaille", "DÉTAILLE", "detaille", "Detaille", "DETAILLE",
|
101 |
+
"précise", "Précise", "PRÉCISE", "precise", "Precise", "PRECISE",
|
102 |
+
"vision", "Vision", "VISION",
|
103 |
+
"t'es qui", "T'es qui", "T'ES QUI",
|
104 |
+
"tu es qui", "Tu es qui", "TU ES QUI",
|
105 |
+
"t es qui", "T es qui", "T ES QUI",
|
106 |
+
"pourquoi", "Pourquoi", "POURQUOI",
|
107 |
+
"comment", "Comment", "COMMENT",
|
108 |
+
"quel est", "Quel est", "QUEL EST",
|
109 |
+
"quelle est", "Quelle est", "QUELLE EST",
|
110 |
+
"peux-tu développer", "Peux-tu développer", "PEUX-TU DÉVELOPPER",
|
111 |
+
"peux tu developper", "Peux tu developper", "PEUX TU DEVELOPPER",
|
112 |
+
"en quoi consiste", "En quoi consiste", "EN QUOI CONSISTE",
|
113 |
+
"qu'est-ce que", "Qu'est-ce que", "QU'EST-CE QUE",
|
114 |
+
"que penses-tu de", "Que penses-tu de", "QUE PENSES-TU DE",
|
115 |
+
"analyse", "Analyse", "ANALYSE",
|
116 |
+
"compare", "Compare", "COMPARE",
|
117 |
+
"élabore sur", "Élabore sur", "ÉLABORE SUR", "elabore sur", "Elabore sur", "ELABORE SUR",
|
118 |
+
"expérience", "Expérience", "EXPÉRIENCE", "experience", "Experience", "EXPERIENCE",
|
119 |
+
"expérience pro", "Expérience pro", "EXPÉRIENCE PRO",
|
120 |
+
"experience pro", "Experience pro", "EXPERIENCE PRO",
|
121 |
+
"expérience professionnelle", "Expérience professionnelle", "EXPÉRIENCE PROFESSIONNELLE",
|
122 |
+
"experience professionnelle", "Experience professionnelle", "EXPERIENCE PROFESSIONNELLE",
|
123 |
+
"parcours", "Parcours", "PARCOURS",
|
124 |
+
"formation", "Formation", "FORMATION",
|
125 |
+
"études", "Études", "ÉTUDES", "etudes", "Etudes", "ETUDES",
|
126 |
+
"compétences", "Compétences", "COMPÉTENCES", "competences", "Competences", "COMPETENCES",
|
127 |
+
"projets", "Projets", "PROJETS",
|
128 |
+
"réalisations", "Réalisations", "RÉALISATIONS", "realisations", "Realisations", "REALISATIONS"
|
129 |
+
]
|
130 |
message_lower = message.lower()
|
131 |
if any(keyword in message_lower for keyword in short_response_keywords):
|
132 |
return "short"
|
|
|
136 |
return "medium"
|
137 |
|
138 |
def post_process_response(response, is_short_response):
|
139 |
+
def count_questions(text):
|
140 |
+
return len(re.findall(r'\?', text))
|
141 |
+
|
142 |
+
def truncate_to_questions(text, max_questions):
|
143 |
+
sentences = re.split(r'(?<=[.!?])\s+', text)
|
144 |
+
question_count = 0
|
145 |
+
truncated_sentences = []
|
146 |
+
|
147 |
+
for sentence in sentences:
|
148 |
+
truncated_sentences.append(sentence)
|
149 |
+
|
150 |
+
if '?' in sentence:
|
151 |
+
question_count += 1
|
152 |
+
if question_count >= max_questions:
|
153 |
+
break
|
154 |
+
|
155 |
+
return ' '.join(truncated_sentences)
|
156 |
+
|
157 |
if is_short_response:
|
158 |
+
# Pour les réponses courtes, on ne limite pas le nombre de questions
|
|
|
|
|
159 |
return response.strip()
|
160 |
else:
|
161 |
+
# Pour les réponses moyennes et longues, on limite à 2 questions
|
162 |
+
return truncate_to_questions(response, 2).strip()
|
|
|
|
|
163 |
|
164 |
def check_coherence(response):
|
165 |
sentences = re.split(r'(?<=[.!?])\s+', response)
|