| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- <!DOCTYPE html>
- <html lang="fr">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <title>Chatbot Intersel</title>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" />
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
- <style>
- body {
- margin: 0;
- font-family: 'Inter', sans-serif;
- background-color: #f4f6f8;
- height: 100vh;
- width: 100vw;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- }
- .chat-container {
- flex: 1;
- display: flex;
- flex-direction: column;
- height: 100vh;
- width: 100vw;
- }
- .chat-header {
- height: 64px;
- background: #07468f;
- color: white;
- padding: 1rem;
- font-size: 1.25rem;
- font-weight: bold;
- text-align: center;
- flex-shrink: 0;
- }
- .chat-body {
- display: flex;
- flex: 1;
- height: calc(100vh - 64px);
- overflow: hidden;
- }
- .chat-sidebar {
- width: 20%;
- background-color: #e9f5f2;
- border-right: 1px solid #ccc;
- padding: 1rem;
- overflow-y: auto;
- }
- .chat-title {
- font-weight: bold;
- margin-bottom: 1rem;
- }
- .chat-main {
- flex: 1;
- display: flex;
- flex-direction: column;
- background-color: #f7f9fa;
- }
- .chat-history {
- flex: 1;
- padding: 1rem;
- overflow-y: auto;
- display: flex;
- flex-direction: column;
- gap: 1rem;
- }
- .chat-input {
- padding: 1rem;
- background: white;
- border-top: 1px solid #ddd;
- flex-shrink: 0;
- }
- form {
- display: flex;
- flex-direction: column;
- gap: 1rem;
- }
- input[type="text"] {
- padding: 0.75rem;
- border-radius: 8px;
- border: 1px solid #ccc;
- font-size: 1rem;
- width: 100%;
- box-sizing: border-box;
- }
- button {
- background-color: #1e42e0;
- color: white;
- padding: 0.75rem;
- border: none;
- border-radius: 8px;
- cursor: pointer;
- font-weight: bold;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #214874;
- }
- .upload-label {
- display: inline-block;
- background-color: #e0f7f1;
- color: #070e49;
- padding: 0.5rem 1rem;
- border-radius: 8px;
- cursor: pointer;
- font-weight: bold;
- font-size: 0.95rem;
- width: fit-content;
- }
- input[type="file"] {
- display: none;
- }
- .file-preview {
- background-color: #f0f0f0;
- padding: 0.5rem;
- border-radius: 6px;
- font-size: 0.9rem;
- color: #555;
- max-width: 100%;
- word-break: break-word;
- }
- .message {
- display: flex;
- max-width: 70%;
- line-height: 1.4;
- position: relative;
- gap: 0.5rem;
- }
- .message.user {
- align-self: flex-end;
- flex-direction: row-reverse;
- }
- .message.bot {
- align-self: flex-start;
- flex-direction: row;
- }
- .message .avatar {
- font-size: 1.5rem;
- user-select: none;
- flex-shrink: 0;
- align-self: flex-end;
- margin: 0 0.5rem;
- }
- .message .bubble {
- padding: 0.8rem 1rem;
- border-radius: 16px;
- box-shadow: 0 1px 3px rgba(0,0,0,0.1);
- white-space: pre-wrap;
- word-wrap: break-word;
- font-size: 1rem;
- line-height: 1.4;
- position: relative;
- }
- .message.user .bubble {
- background-color: #d1e7dd;
- color: #00133d;
- border-bottom-right-radius: 0;
- }
- .message.user .bubble::after {
- content: "";
- position: absolute;
- bottom: 0;
- right: -8px;
- width: 0;
- height: 0;
- border-top: 12px solid #d1e7dd;
- border-left: 8px solid transparent;
- }
- .message.bot .bubble {
- background-color: #e2e3e5;
- color: #41464b;
- border-bottom-left-radius: 0;
- }
- .message.bot .bubble::after {
- content: "";
- position: absolute;
- bottom: 0;
- left: -8px;
- width: 0;
- height: 0;
- border-top: 12px solid #e2e3e5;
- border-right: 8px solid transparent;
- }
- body.dark {
- background-color: #1e1e1e;
- color: #f0f0f0;
- }
- body.dark .chat-header {
- background: #333;
- }
- body.dark .chat-sidebar {
- background-color: #2d2d2d;
- border-color: #444;
- }
- body.dark .chat-main {
- background-color: #1e1e1e;
- }
- body.dark .chat-history {
- background-color: #1e1e1e;
- }
- body.dark .chat-input {
- background-color: #2c2c2c;
- border-color: #444;
- }
- body.dark input[type="text"] {
- background-color: #3a3a3a;
- color: #f0f0f0;
- border-color: #555;
- }
- body.dark button {
- background-color: #96b4eb;
- color: white;
- }
- body.dark .upload-label {
- background-color: #37474f;
- color: #95a9e9;
- }
- body.dark .file-preview {
- background-color: #333;
- color: #ccc;
- }
- body.dark .message.user .bubble {
- background-color: #8d9ff0;
- color: #c8e6c9;
- }
- body.dark .message.user .bubble::after {
- border-top-color: #262f4d;
- }
- body.dark .message.bot .bubble {
- background-color: #444;
- color: #eee;
- }
- body.dark .message.bot .bubble::after {
- border-top-color: #444;
- }
- /* Header layout */
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 12px 24px;
- background-color: var(--header-bg, #f5f5f5);
- border-bottom: 1px solid #ccc;
- color: var(--text-color, #333);
- }
- .header h1 {
- font-size: 1.5em;
- margin: 0;
- }
- /* Right section layout */
- .header-right {
- display: flex;
- gap: 16px;
- }
- /* Shared button/icon style */
- .icon-button {
- background: none;
- border: none;
- font-size: 1.4em;
- color: var(--text-color, #333);
- cursor: pointer;
- transition: color 0.3s ease;
- text-decoration: none;
- }
- .icon-button:hover {
- color: #007bff;
- }
- /* Dark mode support */
- @media (prefers-color-scheme: dark) {
- .header {
- --header-bg: #1e1e1e;
- --text-color: #f0f0f0;
- }
- .icon-button {
- color: var(--text-color);
- }
- .icon-button:hover {
- color: #66b0ff;
- }
- }
- .header-buttons {
- position: absolute;
- right: 1rem;
- top: 1rem;
- display: flex;
- align-items: center;
- gap: 10px;
- z-index: 1000;
- }
- .theme-toggle,
- .signup-btn {
- background-color: rgba(255, 255, 255, 0.2);
- color: white;
- border: none;
- border-radius: 6px;
- width: 40px;
- height: 40px;
- font-size: 20px;
- line-height: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- cursor: pointer;
- }
- .theme-toggle:hover,
- .signup-btn:hover {
- background-color: rgba(255, 255, 255, 0.35);
- }
- .chat-sidebar {
- width: 200px;
- background-color: #202020;
- color: white;
- padding: 1rem;
- }
- .chat-title {
- font-weight: bold;
- margin-bottom: 1rem;
- }
- .chat-item {
- padding: 0.5rem;
- cursor: pointer;
- border-radius: 4px;
- }
- .chat-item:hover {
- background-color: #333;
- }
- </style>
- </head>
- <body>
- <div class="chat-container">
- <div class="chat-header">📎 Chatbot Documentaire</div>
- <div class="header-buttons">
- <a href="/developpeur" class="theme-toggle" title="Monitoring développeur" style="text-decoration:none;color:inherit;font-size:0.9rem;">🔧 Dev</a>
- <button class="theme-toggle" id="themeToggle" title="Changer de thème">🌙</button>
- <button class="fas fa-user-alt" id="signupBtn" title="Créer un compte" onclick="window.location.href='/register';"></button>
- </div>
- <div class="chat-body">
- <div class="chat-sidebar" id="chatSidebar">
- <div class="chat-title">💬 Vos Chats</div>
- <div id="chatList"></div>
- <button onclick="addNewChat()">➕ Nouveau Chat</button>
- <div class="chat-item">🗂️ Chat du 1 août</div>
- <div class="chat-item">🗂️ Chat du 2 août</div>
- </div>
- <div class="chat-main">
- <div class="chat-history" id="chatHistory"></div>
- <div class="chat-input">
- <form id="questionForm" enctype="multipart/form-data">
- <label class="upload-label" for="file">📁 Ajouter un fichier (PDF, TXT, Image)</label>
- <input type="file" id="file" name="file" accept=".pdf,.txt,image/*" />
- <div class="file-preview" id="filePreview" style="display: none;"></div>
- <input type="text" id="question" name="question" placeholder="Posez votre question…" autocomplete="off" required />
- <button type="submit">Envoyer</button>
- </form>
- </div>
- </div>
- </div>
- <div id="status" style="color: gray; margin-top: 0.5rem;"></div>
- </div>
- <script>
- const chatList = document.getElementById("chatList");
- let chatSessions = [];
- let currentChatIndex = -1;
- const chatHistoryDiv = document.getElementById("chatHistory");
- const questionForm = document.getElementById("questionForm");
- const questionInput = document.getElementById("question");
- const status = document.getElementById("status");
- const fileInput = document.getElementById("file");
- const filePreview = document.getElementById("filePreview");
- // Affiche nom fichier sélectionné
- fileInput.addEventListener('change', () => {
- if (fileInput.files.length > 0) {
- filePreview.style.display = 'block';
- filePreview.textContent = `Fichier sélectionné : ${fileInput.files[0].name}`;
- } else {
- filePreview.style.display = 'none';
- filePreview.textContent = '';
- }
- });
-
- // Fonction ajout message
- function appendMessage(sender, text) {
- const message = document.createElement("div");
- message.className = `message ${sender}`;
- const avatar = document.createElement("div");
- avatar.className = "avatar";
- avatar.textContent = sender === "user" ? "👤" : "🤖";
- const bubble = document.createElement("div");
- bubble.className = "bubble";
- bubble.textContent = text;
- message.appendChild(avatar);
- message.appendChild(bubble);
- chatHistoryDiv.appendChild(message);
- chatHistoryDiv.scrollTop = chatHistoryDiv.scrollHeight;
- // 🧠 Ajouter au tableau de sessions
- if (currentChatIndex >= 0) {
- chatSessions[currentChatIndex].messages.push({ sender, text });
- }
- }
- // pour afficher la liste de tous les chats dans la barre latérale
- function renderChatList() {
- chatList.innerHTML = "";
- chatSessions.forEach((session, index) => {
- const item = document.createElement("div");
- item.className = "chat-item";
- item.textContent = `${session.icon} ${session.label}`;
- item.addEventListener("click", () => {
- loadChat(index);
- });
- chatList.appendChild(item);
- });
- }
- // Fonction pour charger un ancien chat
- function loadChat(index) {
- currentChatIndex = index;
- chatHistoryDiv.innerHTML = "";
- chatSessions[index].messages.forEach(({ sender, text }) => {
- appendMessage(sender, text);
- });
- }
- // Charger historique si tu as cette route backend
- async function loadChatHistory() {
- try {
- const response = await fetch("/chat_history");
- if (response.ok) {
- const chatHistory = await response.json();
- chatHistoryDiv.innerHTML = "";
- chatHistory.forEach(({ question, answer }) => {
- appendMessage("user", question);
- appendMessage("bot", answer);
- });
- }
- } catch (error) {
- console.warn("Erreur chargement historique :", error);
- }
- }
- loadChatHistory();
- // Gestion submit formulaire unique
- questionForm.addEventListener("submit", async (e) => {
- e.preventDefault();
- const question = questionInput.value.trim();
- if (!question) return;
- appendMessage("user", question);
- status.textContent = "En attente de la réponse...";
- // Si fichier sélectionné, on envoie en multipart/form-data vers /upload_file
- if (fileInput.files.length > 0) {
- const formData = new FormData();
- formData.append("file", fileInput.files[0]);
- formData.append("question", question);
- try {
- const res = await fetch("/upload_file", {
- method: "POST",
- body: formData,
- });
- if (res.ok) {
- const data = await res.json();
- appendMessage("bot", data.answer || "Réponse reçue.");
- } else {
- appendMessage("bot", `Erreur serveur: ${res.status}`);
- }
- } catch (error) {
- appendMessage("bot", "Erreur réseau ou serveur.");
- console.error(error);
- }
- } else {
- // Pas de fichier, on envoie JSON vers /qa_chain
- try {
- const res = await fetch("/qa_chain", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ query: question }),
- });
- if (res.ok) {
- const data = await res.json();
- appendMessage("bot", data.answer || "Réponse reçue.");
- } else {
- appendMessage("bot", `Erreur serveur: ${res.status}`);
- }
- } catch (error) {
- appendMessage("bot", "Erreur réseau ou serveur.");
- console.error(error);
- }
- }
- status.textContent = "";
- questionInput.value = "";
- fileInput.value = "";
- filePreview.style.display = 'none';
- });
- const themeToggle = document.getElementById("themeToggle");
- function setTheme(mode) {
- document.body.classList.toggle("dark", mode === "dark");
- themeToggle.textContent = mode === "dark" ? "☀️" : "🌙";
- localStorage.setItem("theme", mode);
- }
- themeToggle.addEventListener("click", () => {
- const currentMode = document.body.classList.contains("dark") ? "dark" : "light";
- const newMode = currentMode === "dark" ? "light" : "dark";
- setTheme(newMode);
- });
- // Appliquer le thème sauvegardé
- const savedTheme = localStorage.getItem("theme") || "light";
- setTheme(savedTheme);
- function addNewChat() {
- const today = new Date().toLocaleDateString('fr-FR', {
- day: 'numeric',
- month: 'long',
- year: 'numeric'
- });
- const newChat = {
- label: `Chat du ${today}`,
- icon: "🗂️",
- messages: []
- };
- chatSessions.push(newChat);
- currentChatIndex = chatSessions.length - 1;
- // Vider l'historique affiché
- chatHistoryDiv.innerHTML = "";
- // Re-render la liste
- renderChatList();
- }
- </script>
- </body>
- </html>
|