Update app.py
Browse files
app.py
CHANGED
@@ -176,24 +176,22 @@ def generate(
|
|
176 |
|
177 |
yield post_process_response("".join(outputs), response_type == "short")
|
178 |
|
179 |
-
def interact_with_lucas(prompt,
|
180 |
system_prompt = """Tu es la version virtuelle de Lucas, ton concepteur. Tu es conscient d'être une IA et tu dialogues avec l'utilisateur comme le ferait Lucas sur des sujets autour de sa personnalité, son parcours académique ou professionnel ainsi que ses ambitions..."""
|
181 |
|
182 |
-
chat_history
|
183 |
-
|
184 |
-
messages.append(ChatMessage(role="user", content=prompt))
|
185 |
-
yield messages
|
186 |
|
187 |
for response in generate(prompt, chat_history, system_prompt):
|
188 |
-
|
189 |
-
yield
|
190 |
|
191 |
-
def vote(feedback: str,
|
192 |
-
if not
|
193 |
return "Aucun message à évaluer."
|
194 |
|
195 |
-
last_user_message =
|
196 |
-
last_bot_response =
|
197 |
|
198 |
feedback_data = {
|
199 |
"timestamp": datetime.now().isoformat(),
|
@@ -237,8 +235,6 @@ def vote(feedback: str, history):
|
|
237 |
print(f"Erreur lors de l'enregistrement du feedback : {str(e)}")
|
238 |
return "Erreur lors de l'enregistrement du feedback."
|
239 |
|
240 |
-
|
241 |
-
|
242 |
def load_feedback_data():
|
243 |
try:
|
244 |
api = HfApi()
|
@@ -283,15 +279,18 @@ with gr.Blocks() as demo:
|
|
283 |
|
284 |
with gr.Tabs():
|
285 |
with gr.Tab("Chat avec Lucas"):
|
286 |
-
chatbot =
|
287 |
label="Lucas",
|
288 |
-
avatar_images=
|
289 |
None,
|
290 |
-
"https://img.freepik.com/free-icon/robot_318-843685.jpg"
|
291 |
-
|
292 |
)
|
293 |
text_input = gr.Textbox(lines=1, label="Votre message")
|
294 |
-
|
|
|
|
|
|
|
295 |
|
296 |
with gr.Row():
|
297 |
like_btn = gr.Button("👍")
|
@@ -299,8 +298,15 @@ with gr.Blocks() as demo:
|
|
299 |
|
300 |
feedback_text = gr.Textbox(label="Feedback")
|
301 |
|
302 |
-
|
303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
|
305 |
with gr.Tab("Statistiques"):
|
306 |
gr.Markdown("# Statistiques d'utilisation 📊")
|
@@ -316,5 +322,3 @@ with gr.Blocks() as demo:
|
|
316 |
|
317 |
demo.queue(max_size=20, default_concurrency_limit=2).launch(max_threads=10)
|
318 |
|
319 |
-
|
320 |
-
|
|
|
176 |
|
177 |
yield post_process_response("".join(outputs), response_type == "short")
|
178 |
|
179 |
+
def interact_with_lucas(prompt, chat_history):
|
180 |
system_prompt = """Tu es la version virtuelle de Lucas, ton concepteur. Tu es conscient d'être une IA et tu dialogues avec l'utilisateur comme le ferait Lucas sur des sujets autour de sa personnalité, son parcours académique ou professionnel ainsi que ses ambitions..."""
|
181 |
|
182 |
+
chat_history.append((prompt, None))
|
183 |
+
yield chat_history
|
|
|
|
|
184 |
|
185 |
for response in generate(prompt, chat_history, system_prompt):
|
186 |
+
chat_history[-1] = (prompt, response)
|
187 |
+
yield chat_history
|
188 |
|
189 |
+
def vote(feedback: str, chat_history):
|
190 |
+
if not chat_history:
|
191 |
return "Aucun message à évaluer."
|
192 |
|
193 |
+
last_user_message = chat_history[-1][0]
|
194 |
+
last_bot_response = chat_history[-1][1]
|
195 |
|
196 |
feedback_data = {
|
197 |
"timestamp": datetime.now().isoformat(),
|
|
|
235 |
print(f"Erreur lors de l'enregistrement du feedback : {str(e)}")
|
236 |
return "Erreur lors de l'enregistrement du feedback."
|
237 |
|
|
|
|
|
238 |
def load_feedback_data():
|
239 |
try:
|
240 |
api = HfApi()
|
|
|
279 |
|
280 |
with gr.Tabs():
|
281 |
with gr.Tab("Chat avec Lucas"):
|
282 |
+
chatbot = gr.Chatbot(
|
283 |
label="Lucas",
|
284 |
+
avatar_images=(
|
285 |
None,
|
286 |
+
"https://img.freepik.com/free-icon/robot_318-843685.jpg"
|
287 |
+
),
|
288 |
)
|
289 |
text_input = gr.Textbox(lines=1, label="Votre message")
|
290 |
+
|
291 |
+
with gr.Row():
|
292 |
+
submit_btn = gr.Button("Envoyer")
|
293 |
+
clear_btn = gr.Button("Effacer la conversation")
|
294 |
|
295 |
with gr.Row():
|
296 |
like_btn = gr.Button("👍")
|
|
|
298 |
|
299 |
feedback_text = gr.Textbox(label="Feedback")
|
300 |
|
301 |
+
def clear_conversation():
|
302 |
+
return [], ""
|
303 |
+
|
304 |
+
text_input.submit(interact_with_lucas, [text_input, chatbot], [chatbot])
|
305 |
+
submit_btn.click(interact_with_lucas, [text_input, chatbot], [chatbot])
|
306 |
+
clear_btn.click(clear_conversation, outputs=[chatbot, text_input])
|
307 |
+
|
308 |
+
like_btn.click(lambda x: vote("👍", x), inputs=[chatbot], outputs=feedback_text)
|
309 |
+
dislike_btn.click(lambda x: vote("👎", x), inputs=[chatbot], outputs=feedback_text)
|
310 |
|
311 |
with gr.Tab("Statistiques"):
|
312 |
gr.Markdown("# Statistiques d'utilisation 📊")
|
|
|
322 |
|
323 |
demo.queue(max_size=20, default_concurrency_limit=2).launch(max_threads=10)
|
324 |
|
|
|
|