Upload folder using huggingface_hub
Browse files- static/script.js +22 -52
- static/script1.js +129 -0
static/script.js
CHANGED
|
@@ -8,24 +8,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 8 |
const matchedLbl = document.getElementById('matched');
|
| 9 |
const confFill = document.getElementById('conf-fill');
|
| 10 |
const stars = document.querySelectorAll('.star');
|
|
|
|
| 11 |
|
| 12 |
-
let currentInteraction = null;
|
| 13 |
let isLoading = false;
|
| 14 |
|
| 15 |
-
// Fonction principale pour envoyer une question
|
| 16 |
async function sendQuestion(q) {
|
| 17 |
const question = q.trim();
|
| 18 |
if (!question || isLoading) return;
|
| 19 |
|
| 20 |
-
// Affichage de la question utilisateur
|
| 21 |
chat.innerHTML += `<div class="user-msg"><b>Vous :</b> ${question}</div>`;
|
| 22 |
input.value = '';
|
| 23 |
input.focus();
|
| 24 |
|
| 25 |
-
|
| 26 |
-
stars.forEach(s => { s.textContent="☆"; s.style.pointerEvents='auto'; });
|
| 27 |
|
| 28 |
-
// Afficher loader
|
| 29 |
const loaderDiv = document.createElement('div');
|
| 30 |
loaderDiv.className = 'bot-msg';
|
| 31 |
loaderDiv.innerHTML = '<i>💭 Bot réfléchit…</i>';
|
|
@@ -36,66 +32,39 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 36 |
|
| 37 |
try {
|
| 38 |
const res = await fetch('/ask', {
|
| 39 |
-
method:'POST',
|
| 40 |
-
headers:{'Content-Type':'application/json'},
|
| 41 |
-
body:JSON.stringify({question
|
| 42 |
});
|
| 43 |
-
const data = await res.json();
|
| 44 |
-
currentInteraction = data;
|
| 45 |
|
| 46 |
-
|
| 47 |
loaderDiv.remove();
|
| 48 |
|
| 49 |
-
// Affichage réponse bot
|
| 50 |
chat.innerHTML += `<div class="bot-msg"><b>Bot :</b> ${data.response}</div>`;
|
| 51 |
|
| 52 |
-
|
| 53 |
-
if(data.recs && data.recs.length>0){
|
| 54 |
const suggDiv = document.createElement('div');
|
| 55 |
suggDiv.className = 'recs';
|
| 56 |
-
suggDiv.style.display = "grid";
|
| 57 |
-
suggDiv.style.gridTemplateRows = "repeat(5, auto)";
|
| 58 |
-
suggDiv.style.gridAutoFlow = "column";
|
| 59 |
-
suggDiv.style.gap = "6px 12px";
|
| 60 |
-
suggDiv.style.marginTop = "4px";
|
| 61 |
-
|
| 62 |
-
data.recs.forEach((r) => {
|
| 63 |
-
const itemDiv = document.createElement('div');
|
| 64 |
-
itemDiv.style.display = "inline-flex";
|
| 65 |
-
itemDiv.style.alignItems = "center";
|
| 66 |
-
|
| 67 |
-
const circle = document.createElement('span');
|
| 68 |
-
circle.style.display = "inline-block";
|
| 69 |
-
circle.style.width = "8px";
|
| 70 |
-
circle.style.height = "8px";
|
| 71 |
-
circle.style.backgroundColor = "black";
|
| 72 |
-
circle.style.borderRadius = "50%";
|
| 73 |
-
circle.style.marginRight = "6px";
|
| 74 |
-
itemDiv.appendChild(circle);
|
| 75 |
|
|
|
|
| 76 |
const a = document.createElement('a');
|
| 77 |
a.textContent = r;
|
| 78 |
-
|
| 79 |
-
itemDiv.appendChild(a);
|
| 80 |
-
|
| 81 |
-
suggDiv.appendChild(itemDiv);
|
| 82 |
});
|
| 83 |
|
| 84 |
chat.appendChild(suggDiv);
|
| 85 |
}
|
| 86 |
|
| 87 |
-
// Mise à jour des informations
|
| 88 |
intentLbl.textContent = data.intent;
|
| 89 |
matchedLbl.textContent = data.matched;
|
| 90 |
confFill.style.width = data.confidence + "%";
|
| 91 |
confFill.textContent = data.confidence + "%";
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
confFill.style.background = color;
|
| 97 |
|
| 98 |
-
} catch(err){
|
| 99 |
loaderDiv.remove();
|
| 100 |
chat.innerHTML += '<div class="bot-msg"><b>Erreur :</b> Impossible de contacter le serveur.</div>';
|
| 101 |
console.error(err);
|
|
@@ -105,24 +74,25 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 105 |
isLoading = false;
|
| 106 |
}
|
| 107 |
|
| 108 |
-
// Click sur le bouton Envoyer
|
| 109 |
btn.addEventListener('click', () => sendQuestion(input.value));
|
|
|
|
| 110 |
|
| 111 |
-
//
|
| 112 |
-
input.addEventListener('keypress', e => { if(e.key==='Enter') sendQuestion(input.value); });
|
| 113 |
-
|
| 114 |
-
// Gestion étoiles de satisfaction
|
| 115 |
stars.forEach(s => {
|
| 116 |
s.addEventListener('click', () => {
|
| 117 |
const val = parseInt(s.dataset.value);
|
| 118 |
-
stars.forEach((st, i) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
chat.innerHTML += `<div><i>⭐ Merci pour votre évaluation : ${val} / 5</i></div>`;
|
|
|
|
| 120 |
});
|
| 121 |
});
|
| 122 |
|
| 123 |
-
// Event delegation pour les recommandations
|
| 124 |
chat.addEventListener('click', (e) => {
|
| 125 |
-
if(e.target.tagName === 'A' && e.target.parentElement.
|
| 126 |
sendQuestion(e.target.textContent);
|
| 127 |
}
|
| 128 |
});
|
|
|
|
| 8 |
const matchedLbl = document.getElementById('matched');
|
| 9 |
const confFill = document.getElementById('conf-fill');
|
| 10 |
const stars = document.querySelectorAll('.star');
|
| 11 |
+
const surveyLink = document.getElementById('survey-link');
|
| 12 |
|
|
|
|
| 13 |
let isLoading = false;
|
| 14 |
|
|
|
|
| 15 |
async function sendQuestion(q) {
|
| 16 |
const question = q.trim();
|
| 17 |
if (!question || isLoading) return;
|
| 18 |
|
|
|
|
| 19 |
chat.innerHTML += `<div class="user-msg"><b>Vous :</b> ${question}</div>`;
|
| 20 |
input.value = '';
|
| 21 |
input.focus();
|
| 22 |
|
| 23 |
+
stars.forEach(s => { s.textContent = "☆"; s.style.pointerEvents = 'auto'; });
|
|
|
|
| 24 |
|
|
|
|
| 25 |
const loaderDiv = document.createElement('div');
|
| 26 |
loaderDiv.className = 'bot-msg';
|
| 27 |
loaderDiv.innerHTML = '<i>💭 Bot réfléchit…</i>';
|
|
|
|
| 32 |
|
| 33 |
try {
|
| 34 |
const res = await fetch('/ask', {
|
| 35 |
+
method: 'POST',
|
| 36 |
+
headers: { 'Content-Type': 'application/json' },
|
| 37 |
+
body: JSON.stringify({ question })
|
| 38 |
});
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
const data = await res.json();
|
| 41 |
loaderDiv.remove();
|
| 42 |
|
|
|
|
| 43 |
chat.innerHTML += `<div class="bot-msg"><b>Bot :</b> ${data.response}</div>`;
|
| 44 |
|
| 45 |
+
if (data.recs && data.recs.length > 0) {
|
|
|
|
| 46 |
const suggDiv = document.createElement('div');
|
| 47 |
suggDiv.className = 'recs';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
data.recs.forEach(r => {
|
| 50 |
const a = document.createElement('a');
|
| 51 |
a.textContent = r;
|
| 52 |
+
suggDiv.appendChild(a);
|
|
|
|
|
|
|
|
|
|
| 53 |
});
|
| 54 |
|
| 55 |
chat.appendChild(suggDiv);
|
| 56 |
}
|
| 57 |
|
|
|
|
| 58 |
intentLbl.textContent = data.intent;
|
| 59 |
matchedLbl.textContent = data.matched;
|
| 60 |
confFill.style.width = data.confidence + "%";
|
| 61 |
confFill.textContent = data.confidence + "%";
|
| 62 |
|
| 63 |
+
confFill.style.background =
|
| 64 |
+
data.confidence < 40 ? "#E53935" :
|
| 65 |
+
data.confidence < 80 ? "#FB8C00" : "#43A047";
|
|
|
|
| 66 |
|
| 67 |
+
} catch (err) {
|
| 68 |
loaderDiv.remove();
|
| 69 |
chat.innerHTML += '<div class="bot-msg"><b>Erreur :</b> Impossible de contacter le serveur.</div>';
|
| 70 |
console.error(err);
|
|
|
|
| 74 |
isLoading = false;
|
| 75 |
}
|
| 76 |
|
|
|
|
| 77 |
btn.addEventListener('click', () => sendQuestion(input.value));
|
| 78 |
+
input.addEventListener('keypress', e => { if (e.key === 'Enter') sendQuestion(input.value); });
|
| 79 |
|
| 80 |
+
// Étoiles de satisfaction + affichage questionnaire
|
|
|
|
|
|
|
|
|
|
| 81 |
stars.forEach(s => {
|
| 82 |
s.addEventListener('click', () => {
|
| 83 |
const val = parseInt(s.dataset.value);
|
| 84 |
+
stars.forEach((st, i) => {
|
| 85 |
+
st.textContent = i < val ? "★" : "☆";
|
| 86 |
+
st.style.pointerEvents = 'none';
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
chat.innerHTML += `<div><i>⭐ Merci pour votre évaluation : ${val} / 5</i></div>`;
|
| 90 |
+
surveyLink.style.display = 'block';
|
| 91 |
});
|
| 92 |
});
|
| 93 |
|
|
|
|
| 94 |
chat.addEventListener('click', (e) => {
|
| 95 |
+
if (e.target.tagName === 'A' && e.target.parentElement.classList.contains('recs')) {
|
| 96 |
sendQuestion(e.target.textContent);
|
| 97 |
}
|
| 98 |
});
|
static/script1.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
console.log('✅ script.js chargé');
|
| 2 |
+
|
| 3 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 4 |
+
const btn = document.getElementById('sendBtn');
|
| 5 |
+
const input = document.getElementById('question');
|
| 6 |
+
const chat = document.getElementById('chat');
|
| 7 |
+
const intentLbl = document.getElementById('intent');
|
| 8 |
+
const matchedLbl = document.getElementById('matched');
|
| 9 |
+
const confFill = document.getElementById('conf-fill');
|
| 10 |
+
const stars = document.querySelectorAll('.star');
|
| 11 |
+
|
| 12 |
+
let currentInteraction = null;
|
| 13 |
+
let isLoading = false;
|
| 14 |
+
|
| 15 |
+
// Fonction principale pour envoyer une question
|
| 16 |
+
async function sendQuestion(q) {
|
| 17 |
+
const question = q.trim();
|
| 18 |
+
if (!question || isLoading) return;
|
| 19 |
+
|
| 20 |
+
// Affichage de la question utilisateur
|
| 21 |
+
chat.innerHTML += `<div class="user-msg"><b>Vous :</b> ${question}</div>`;
|
| 22 |
+
input.value = '';
|
| 23 |
+
input.focus();
|
| 24 |
+
|
| 25 |
+
// Réinitialiser les étoiles
|
| 26 |
+
stars.forEach(s => { s.textContent="☆"; s.style.pointerEvents='auto'; });
|
| 27 |
+
|
| 28 |
+
// Afficher loader
|
| 29 |
+
const loaderDiv = document.createElement('div');
|
| 30 |
+
loaderDiv.className = 'bot-msg';
|
| 31 |
+
loaderDiv.innerHTML = '<i>💭 Bot réfléchit…</i>';
|
| 32 |
+
chat.appendChild(loaderDiv);
|
| 33 |
+
chat.scrollTop = chat.scrollHeight;
|
| 34 |
+
|
| 35 |
+
isLoading = true;
|
| 36 |
+
|
| 37 |
+
try {
|
| 38 |
+
const res = await fetch('/ask', {
|
| 39 |
+
method:'POST',
|
| 40 |
+
headers:{'Content-Type':'application/json'},
|
| 41 |
+
body:JSON.stringify({question:question})
|
| 42 |
+
});
|
| 43 |
+
const data = await res.json();
|
| 44 |
+
currentInteraction = data;
|
| 45 |
+
|
| 46 |
+
// Retirer loader
|
| 47 |
+
loaderDiv.remove();
|
| 48 |
+
|
| 49 |
+
// Affichage réponse bot
|
| 50 |
+
chat.innerHTML += `<div class="bot-msg"><b>Bot :</b> ${data.response}</div>`;
|
| 51 |
+
|
| 52 |
+
// Suggestions
|
| 53 |
+
if(data.recs && data.recs.length>0){
|
| 54 |
+
const suggDiv = document.createElement('div');
|
| 55 |
+
suggDiv.className = 'recs';
|
| 56 |
+
suggDiv.style.display = "grid";
|
| 57 |
+
suggDiv.style.gridTemplateRows = "repeat(5, auto)";
|
| 58 |
+
suggDiv.style.gridAutoFlow = "column";
|
| 59 |
+
suggDiv.style.gap = "6px 12px";
|
| 60 |
+
suggDiv.style.marginTop = "4px";
|
| 61 |
+
|
| 62 |
+
data.recs.forEach((r) => {
|
| 63 |
+
const itemDiv = document.createElement('div');
|
| 64 |
+
itemDiv.style.display = "inline-flex";
|
| 65 |
+
itemDiv.style.alignItems = "center";
|
| 66 |
+
|
| 67 |
+
const circle = document.createElement('span');
|
| 68 |
+
circle.style.display = "inline-block";
|
| 69 |
+
circle.style.width = "8px";
|
| 70 |
+
circle.style.height = "8px";
|
| 71 |
+
circle.style.backgroundColor = "black";
|
| 72 |
+
circle.style.borderRadius = "50%";
|
| 73 |
+
circle.style.marginRight = "6px";
|
| 74 |
+
itemDiv.appendChild(circle);
|
| 75 |
+
|
| 76 |
+
const a = document.createElement('a');
|
| 77 |
+
a.textContent = r;
|
| 78 |
+
a.style.cursor = "pointer";
|
| 79 |
+
itemDiv.appendChild(a);
|
| 80 |
+
|
| 81 |
+
suggDiv.appendChild(itemDiv);
|
| 82 |
+
});
|
| 83 |
+
|
| 84 |
+
chat.appendChild(suggDiv);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
// Mise à jour des informations
|
| 88 |
+
intentLbl.textContent = data.intent;
|
| 89 |
+
matchedLbl.textContent = data.matched;
|
| 90 |
+
confFill.style.width = data.confidence + "%";
|
| 91 |
+
confFill.textContent = data.confidence + "%";
|
| 92 |
+
|
| 93 |
+
let color = "#43A047";
|
| 94 |
+
if(data.confidence < 40) color = "#E53935";
|
| 95 |
+
else if(data.confidence < 80) color = "#FB8C00";
|
| 96 |
+
confFill.style.background = color;
|
| 97 |
+
|
| 98 |
+
} catch(err){
|
| 99 |
+
loaderDiv.remove();
|
| 100 |
+
chat.innerHTML += '<div class="bot-msg"><b>Erreur :</b> Impossible de contacter le serveur.</div>';
|
| 101 |
+
console.error(err);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
chat.scrollTop = chat.scrollHeight;
|
| 105 |
+
isLoading = false;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// Click sur le bouton Envoyer
|
| 109 |
+
btn.addEventListener('click', () => sendQuestion(input.value));
|
| 110 |
+
|
| 111 |
+
// Envoi avec Enter
|
| 112 |
+
input.addEventListener('keypress', e => { if(e.key==='Enter') sendQuestion(input.value); });
|
| 113 |
+
|
| 114 |
+
// Gestion étoiles de satisfaction
|
| 115 |
+
stars.forEach(s => {
|
| 116 |
+
s.addEventListener('click', () => {
|
| 117 |
+
const val = parseInt(s.dataset.value);
|
| 118 |
+
stars.forEach((st, i) => { st.textContent = i<val?"★":"☆"; st.style.pointerEvents='none'; });
|
| 119 |
+
chat.innerHTML += `<div><i>⭐ Merci pour votre évaluation : ${val} / 5</i></div>`;
|
| 120 |
+
});
|
| 121 |
+
});
|
| 122 |
+
|
| 123 |
+
// Event delegation pour les recommandations
|
| 124 |
+
chat.addEventListener('click', (e) => {
|
| 125 |
+
if(e.target.tagName === 'A' && e.target.parentElement.parentElement.classList.contains('recs')){
|
| 126 |
+
sendQuestion(e.target.textContent);
|
| 127 |
+
}
|
| 128 |
+
});
|
| 129 |
+
});
|