Update templates/index.html
Browse files- templates/index.html +120 -50
templates/index.html
CHANGED
|
@@ -4,77 +4,147 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Mariam AI!</title>
|
|
|
|
|
|
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
</style>
|
|
|
|
|
|
|
| 25 |
</head>
|
| 26 |
-
<body>
|
| 27 |
|
| 28 |
-
<div class="chat-container">
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
</div>
|
| 32 |
|
| 33 |
-
|
|
|
|
| 34 |
{% for message in chat_history %}
|
| 35 |
-
<div class="message {
|
| 36 |
-
<
|
| 37 |
-
|
|
|
|
| 38 |
</div>
|
| 39 |
{% endfor %}
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
</div>
|
| 49 |
|
|
|
|
| 50 |
{% if error %}
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
{% endif %}
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
Activer la recherche web
|
| 60 |
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</div>
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
</div>
|
| 66 |
-
</
|
| 67 |
-
|
| 68 |
-
<input type="text" name="prompt" placeholder="Posez votre question..." required autofocus>
|
| 69 |
-
<button type="submit">Envoyer</button>
|
| 70 |
-
</div>
|
| 71 |
-
</form>
|
| 72 |
</div>
|
| 73 |
|
| 74 |
<script>
|
| 75 |
-
//
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
</script>
|
| 79 |
|
| 80 |
</body>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Mariam AI!</title>
|
| 7 |
+
<!-- Tailwind CSS via CDN -->
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
<style>
|
| 10 |
+
/* Style personnalisé pour la barre de défilement (optionnel) */
|
| 11 |
+
::-webkit-scrollbar {
|
| 12 |
+
width: 8px;
|
| 13 |
+
}
|
| 14 |
+
::-webkit-scrollbar-track {
|
| 15 |
+
background: #f1f1f1;
|
| 16 |
+
border-radius: 10px;
|
| 17 |
+
}
|
| 18 |
+
::-webkit-scrollbar-thumb {
|
| 19 |
+
background: #888;
|
| 20 |
+
border-radius: 10px;
|
| 21 |
+
}
|
| 22 |
+
::-webkit-scrollbar-thumb:hover {
|
| 23 |
+
background: #555;
|
| 24 |
+
}
|
| 25 |
+
/* Empêche le FOUC (Flash of Unstyled Content) */
|
| 26 |
+
[x-cloak] { display: none !important; }
|
| 27 |
</style>
|
| 28 |
+
<!-- Alpine.js pour une interactivité simple (optionnel mais utile) -->
|
| 29 |
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
| 30 |
</head>
|
| 31 |
+
<body class="bg-gray-100 flex items-center justify-center min-h-screen" x-data="{ processing: {{ 'true' if processing_message else 'false' }} }">
|
| 32 |
|
| 33 |
+
<div class="chat-container bg-white rounded-lg shadow-xl w-full max-w-3xl h-[90vh] flex flex-col" x-cloak>
|
| 34 |
+
<!-- En-tête -->
|
| 35 |
+
<div class="chat-header bg-gradient-to-r from-emerald-500 to-teal-600 text-white p-4 rounded-t-lg flex justify-between items-center">
|
| 36 |
+
<h1 class="text-xl font-semibold">Mariam AI!</h1>
|
| 37 |
+
<!-- Bouton pour effacer (optionnel mais utile) -->
|
| 38 |
+
<form action="{{ url_for('clear_chat') }}" method="post" onsubmit="return confirm('Voulez-vous vraiment effacer la conversation ?');">
|
| 39 |
+
<button type="submit" title="Effacer la conversation" class="text-white hover:text-red-300 transition duration-150">
|
| 40 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
|
| 41 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12.576 0a48.108 48.108 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
|
| 42 |
+
</svg>
|
| 43 |
+
</button>
|
| 44 |
+
</form>
|
| 45 |
</div>
|
| 46 |
|
| 47 |
+
<!-- Zone des messages -->
|
| 48 |
+
<div class="chat-messages flex-grow overflow-y-auto p-4 md:p-6 space-y-4" id="chat-messages">
|
| 49 |
{% for message in chat_history %}
|
| 50 |
+
<div class="message flex {% if message.role == 'user' %}justify-end{% else %}justify-start{% endif %}">
|
| 51 |
+
<div class="max-w-xs md:max-w-md lg:max-w-lg px-4 py-2 rounded-lg shadow {% if message.role == 'user' %}bg-emerald-500 text-white rounded-br-none{% else %}bg-gray-200 text-gray-800 rounded-bl-none{% endif %}">
|
| 52 |
+
<p class="text-sm break-words whitespace-pre-wrap">{{ message.text }}</p>
|
| 53 |
+
</div>
|
| 54 |
</div>
|
| 55 |
{% endfor %}
|
| 56 |
+
|
| 57 |
+
<!-- Indicateur de chargement -->
|
| 58 |
+
<div x-show="processing" class="flex justify-center items-center py-4">
|
| 59 |
+
<div class="animate-spin rounded-full h-6 w-6 border-b-2 border-emerald-500"></div>
|
| 60 |
+
<span class="ml-2 text-gray-500 italic">
|
| 61 |
+
{% if session.get('processing_web_search') %}
|
| 62 |
+
Recherche web et génération en cours...
|
| 63 |
+
{% else %}
|
| 64 |
+
Génération de la réponse...
|
| 65 |
+
{% endif %}
|
| 66 |
+
</span>
|
| 67 |
+
</div>
|
| 68 |
</div>
|
| 69 |
|
| 70 |
+
<!-- Affichage des erreurs -->
|
| 71 |
{% if error %}
|
| 72 |
+
<div class="error-message bg-red-100 border border-red-400 text-red-700 px-4 py-2 rounded-md mx-4 mb-2 text-sm">
|
| 73 |
+
<strong>Erreur :</strong> {{ error }}
|
| 74 |
+
</div>
|
| 75 |
{% endif %}
|
| 76 |
|
| 77 |
+
<!-- Zone de saisie et options -->
|
| 78 |
+
<div class="chat-input-area border-t border-gray-200 p-4 bg-gray-50 rounded-b-lg">
|
| 79 |
+
<form method="POST" action="{{ url_for('chat') }}" enctype="multipart/form-data" id="chat-form" @submit="processing = true">
|
| 80 |
+
<!-- Options : Recherche Web & Upload -->
|
| 81 |
+
<div class="options flex flex-col sm:flex-row justify-between items-center mb-3 gap-3 text-sm text-gray-600">
|
| 82 |
+
<label for="web_search_toggle" class="flex items-center cursor-pointer">
|
| 83 |
+
<input type="checkbox" id="web_search_toggle" name="web_search" value="true" {% if web_search_active %}checked{% endif %} class="mr-2 h-4 w-4 rounded border-gray-300 text-emerald-600 focus:ring-emerald-500">
|
| 84 |
Activer la recherche web
|
| 85 |
</label>
|
| 86 |
+
|
| 87 |
+
<label for="file_upload" class="flex items-center cursor-pointer bg-white border border-gray-300 rounded-md px-3 py-1 hover:bg-gray-50 transition duration-150">
|
| 88 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 mr-2 text-gray-500">
|
| 89 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.122 2.122l7.81-7.81" />
|
| 90 |
+
</svg>
|
| 91 |
+
<span id="file-label-text">Joindre un fichier</span> (.jpg, .png, .pdf, .txt)
|
| 92 |
+
<input type="file" id="file_upload" name="file" class="hidden" accept=".jpg,.jpeg,.png,.pdf,.txt" onchange="updateFileLabel(this)">
|
| 93 |
+
</label>
|
| 94 |
</div>
|
| 95 |
+
|
| 96 |
+
<!-- Champ de saisie et bouton envoyer -->
|
| 97 |
+
<div class="flex items-center gap-2">
|
| 98 |
+
<input type="text" name="prompt" id="prompt-input" placeholder="Posez votre question à Mariam..." required autofocus
|
| 99 |
+
class="flex-grow p-3 border border-gray-300 rounded-full focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent transition duration-150"
|
| 100 |
+
:disabled="processing"> <!-- Désactivé pendant le traitement -->
|
| 101 |
+
|
| 102 |
+
<button type="submit" id="send-button"
|
| 103 |
+
class="bg-emerald-500 hover:bg-emerald-600 text-white rounded-full p-3 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-offset-1 transition duration-150 disabled:opacity-50 disabled:cursor-not-allowed"
|
| 104 |
+
:disabled="processing"> <!-- Désactivé pendant le traitement -->
|
| 105 |
+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
|
| 106 |
+
<path stroke-linecap="round" stroke-linejoin="round" d="M6 12 3.269 3.125A59.769 59.769 0 0 1 21.485 12 59.768 59.768 0 0 1 3.27 20.875L5.999 12Zm0 0h7.5" />
|
| 107 |
+
</svg>
|
| 108 |
+
</button>
|
| 109 |
</div>
|
| 110 |
+
</form>
|
| 111 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
</div>
|
| 113 |
|
| 114 |
<script>
|
| 115 |
+
// Fonction pour faire défiler vers le bas
|
| 116 |
+
function scrollToBottom() {
|
| 117 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 118 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// Fonction pour mettre à jour le label du fichier
|
| 122 |
+
function updateFileLabel(input) {
|
| 123 |
+
const fileLabel = document.getElementById('file-label-text');
|
| 124 |
+
if (input.files && input.files.length > 0) {
|
| 125 |
+
fileLabel.textContent = input.files[0].name;
|
| 126 |
+
} else {
|
| 127 |
+
fileLabel.textContent = 'Joindre un fichier';
|
| 128 |
+
}
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
// Faire défiler vers le bas au chargement initial
|
| 132 |
+
window.addEventListener('load', scrollToBottom);
|
| 133 |
+
|
| 134 |
+
// Optionnel : Faire défiler après un léger délai pour s'assurer que tout est rendu (peut aider sur certains navigateurs)
|
| 135 |
+
// setTimeout(scrollToBottom, 100);
|
| 136 |
+
|
| 137 |
+
// Optionnel : Si vous vouliez effacer le champ après envoi (ne fonctionne pas bien avec le rechargement de page standard)
|
| 138 |
+
/*
|
| 139 |
+
const chatForm = document.getElementById('chat-form');
|
| 140 |
+
const promptInput = document.getElementById('prompt-input');
|
| 141 |
+
chatForm.addEventListener('submit', function() {
|
| 142 |
+
// Déjà géré par Alpine.js : document.getElementById('send-button').disabled = true;
|
| 143 |
+
// Peut causer des problèmes si la soumission échoue avant le rechargement
|
| 144 |
+
// setTimeout(() => { promptInput.value = ''; }, 50);
|
| 145 |
+
});
|
| 146 |
+
*/
|
| 147 |
+
|
| 148 |
</script>
|
| 149 |
|
| 150 |
</body>
|