Update app.py
Browse files
app.py
CHANGED
@@ -188,12 +188,12 @@ def interact_with_lucas(prompt, messages):
|
|
188 |
messages[-1] = ChatMessage(role="assistant", content=response)
|
189 |
yield messages
|
190 |
|
191 |
-
def vote(
|
192 |
-
|
193 |
"timestamp": datetime.now().isoformat(),
|
194 |
-
"user_input":
|
195 |
-
"bot_response":
|
196 |
-
"liked":
|
197 |
}
|
198 |
|
199 |
api = HfApi()
|
@@ -211,7 +211,7 @@ def vote(data: gr.LikeData):
|
|
211 |
print(f"Erreur lors du téléchargement du fichier : {str(e)}")
|
212 |
current_feedback = []
|
213 |
|
214 |
-
current_feedback.append(
|
215 |
updated_content = json.dumps(current_feedback, ensure_ascii=False, indent=2)
|
216 |
|
217 |
temp_file_path = "/tmp/feedback.json"
|
@@ -228,6 +228,8 @@ def vote(data: gr.LikeData):
|
|
228 |
print(f"Feedback enregistré dans {repo_id}/{file_name}")
|
229 |
except Exception as e:
|
230 |
print(f"Erreur lors de l'enregistrement du feedback : {str(e)}")
|
|
|
|
|
231 |
|
232 |
def load_feedback_data():
|
233 |
try:
|
@@ -282,6 +284,22 @@ with gr.Blocks() as demo:
|
|
282 |
)
|
283 |
text_input = gr.Textbox(lines=1, label="Votre message")
|
284 |
text_input.submit(interact_with_lucas, [text_input, chatbot], [chatbot])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
with gr.Tab("Statistiques"):
|
287 |
gr.Markdown("# Statistiques d'utilisation 📊")
|
@@ -295,9 +313,8 @@ with gr.Blocks() as demo:
|
|
295 |
with gr.Tab("À propos"):
|
296 |
gr.Markdown(Path(current_dir / "about.md").read_text())
|
297 |
|
298 |
-
chatbot.like(vote, None, None)
|
299 |
-
|
300 |
demo.queue(max_size=20, default_concurrency_limit=2).launch(max_threads=10)
|
301 |
|
302 |
|
303 |
|
|
|
|
188 |
messages[-1] = ChatMessage(role="assistant", content=response)
|
189 |
yield messages
|
190 |
|
191 |
+
def vote(feedback: str, message: str, response: str):
|
192 |
+
feedback_data = {
|
193 |
"timestamp": datetime.now().isoformat(),
|
194 |
+
"user_input": message,
|
195 |
+
"bot_response": response,
|
196 |
+
"liked": feedback == "👍"
|
197 |
}
|
198 |
|
199 |
api = HfApi()
|
|
|
211 |
print(f"Erreur lors du téléchargement du fichier : {str(e)}")
|
212 |
current_feedback = []
|
213 |
|
214 |
+
current_feedback.append(feedback_data)
|
215 |
updated_content = json.dumps(current_feedback, ensure_ascii=False, indent=2)
|
216 |
|
217 |
temp_file_path = "/tmp/feedback.json"
|
|
|
228 |
print(f"Feedback enregistré dans {repo_id}/{file_name}")
|
229 |
except Exception as e:
|
230 |
print(f"Erreur lors de l'enregistrement du feedback : {str(e)}")
|
231 |
+
|
232 |
+
return "Merci pour votre feedback !"
|
233 |
|
234 |
def load_feedback_data():
|
235 |
try:
|
|
|
284 |
)
|
285 |
text_input = gr.Textbox(lines=1, label="Votre message")
|
286 |
text_input.submit(interact_with_lucas, [text_input, chatbot], [chatbot])
|
287 |
+
|
288 |
+
with gr.Row():
|
289 |
+
like_btn = gr.Button("👍")
|
290 |
+
dislike_btn = gr.Button("👎")
|
291 |
+
|
292 |
+
feedback_text = gr.Textbox(label="Feedback")
|
293 |
+
|
294 |
+
def vote_callback(feedback, history):
|
295 |
+
if history:
|
296 |
+
last_user_message = history[-1][0]
|
297 |
+
last_bot_response = history[-1][1]
|
298 |
+
return vote(feedback, last_user_message, last_bot_response)
|
299 |
+
return "Aucun message à évaluer."
|
300 |
+
|
301 |
+
like_btn.click(lambda: vote_callback("👍", chatbot.value), outputs=feedback_text)
|
302 |
+
dislike_btn.click(lambda: vote_callback("👎", chatbot.value), outputs=feedback_text)
|
303 |
|
304 |
with gr.Tab("Statistiques"):
|
305 |
gr.Markdown("# Statistiques d'utilisation 📊")
|
|
|
313 |
with gr.Tab("À propos"):
|
314 |
gr.Markdown(Path(current_dir / "about.md").read_text())
|
315 |
|
|
|
|
|
316 |
demo.queue(max_size=20, default_concurrency_limit=2).launch(max_threads=10)
|
317 |
|
318 |
|
319 |
|
320 |
+
|