Update templates/index.html
Browse files- templates/index.html +157 -34
templates/index.html
CHANGED
|
@@ -1,44 +1,167 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html lang="
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<
|
|
|
|
|
|
|
| 6 |
<style>
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
</style>
|
| 13 |
</head>
|
| 14 |
<body>
|
| 15 |
-
<
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
<
|
| 19 |
-
<
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
</div>
|
| 41 |
-
|
| 42 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</body>
|
| 44 |
-
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Mariam AI</title>
|
| 7 |
+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
| 8 |
<style>
|
| 9 |
+
.chat-container {
|
| 10 |
+
max-width: 800px;
|
| 11 |
+
margin: 50px auto;
|
| 12 |
+
border: 1px solid #ddd;
|
| 13 |
+
border-radius: 5px;
|
| 14 |
+
padding: 20px;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.message {
|
| 18 |
+
margin-bottom: 10px;
|
| 19 |
+
padding: 10px;
|
| 20 |
+
border-radius: 5px;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.user {
|
| 24 |
+
background-color: #f0f0f0;
|
| 25 |
+
text-align: right;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
.assistant {
|
| 29 |
+
background-color: #e0f7fa;
|
| 30 |
+
text-align: left;
|
| 31 |
+
}
|
| 32 |
+
.settings-container {
|
| 33 |
+
margin-bottom: 20px;
|
| 34 |
+
}
|
| 35 |
+
.hidden {
|
| 36 |
+
display: none;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
</style>
|
| 40 |
</head>
|
| 41 |
<body>
|
| 42 |
+
<div class="container">
|
| 43 |
+
<h1 class="text-center">Mariam AI</h1>
|
| 44 |
+
|
| 45 |
+
<div class="settings-container">
|
| 46 |
+
<div class="form-check">
|
| 47 |
+
<input class="form-check-input" type="checkbox" id="webSearchToggle" {% if web_search %}checked{% endif %}>
|
| 48 |
+
<label class="form-check-label" for="webSearchToggle">
|
| 49 |
+
Activer la recherche web
|
| 50 |
+
</label>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<button id="clearChatBtn" class="btn btn-danger mt-2">Clear Chat</button>
|
| 54 |
+
|
| 55 |
+
</div>
|
| 56 |
+
<div class="chat-container">
|
| 57 |
+
<div id="chatMessages">
|
| 58 |
+
{% for message in chat %}
|
| 59 |
+
<div class="message {{ message.role }}">
|
| 60 |
+
{{ message.text }}
|
| 61 |
+
</div>
|
| 62 |
+
{% endfor %}
|
| 63 |
+
</div>
|
| 64 |
+
|
| 65 |
+
<div class="form-group">
|
| 66 |
+
<label for="fileInput">Télécharger un fichier (image/document)</label>
|
| 67 |
+
<input type="file" class="form-control-file" id="fileInput">
|
| 68 |
+
</div>
|
| 69 |
+
|
| 70 |
+
<div class="input-group">
|
| 71 |
+
<input type="text" id="promptInput" class="form-control" placeholder="Hey?">
|
| 72 |
+
<div class="input-group-append">
|
| 73 |
+
<button id="sendButton" class="btn btn-primary">Send</button>
|
| 74 |
+
</div>
|
| 75 |
+
</div>
|
| 76 |
+
<div id="loadingIndicator" class="spinner-border text-primary mt-2 hidden" role="status">
|
| 77 |
+
<span class="sr-only">Loading...</span>
|
| 78 |
</div>
|
| 79 |
+
</div>
|
| 80 |
</div>
|
| 81 |
+
|
| 82 |
+
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
| 83 |
+
<script>
|
| 84 |
+
$(document).ready(function() {
|
| 85 |
+
function addMessage(role, text) {
|
| 86 |
+
const messageClass = role === 'user' ? 'user' : 'assistant';
|
| 87 |
+
$('#chatMessages').append(`<div class="message ${messageClass}">${text}</div>`);
|
| 88 |
+
//Scroll to the bottom
|
| 89 |
+
$('#chatMessages').scrollTop($('#chatMessages')[0].scrollHeight);
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
$('#sendButton').click(function() {
|
| 94 |
+
const prompt = $('#promptInput').val();
|
| 95 |
+
const webSearchEnabled = $('#webSearchToggle').is(':checked');
|
| 96 |
+
const file = $('#fileInput')[0].files[0]; // Get the file
|
| 97 |
+
if (!prompt && !file) {
|
| 98 |
+
return; // Prevent sending empty messages without a file.
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
addMessage('user', prompt);
|
| 103 |
+
$('#promptInput').val(''); // Clear input after sending
|
| 104 |
+
$("#loadingIndicator").removeClass("hidden"); // Show the spinner
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
const formData = new FormData();
|
| 108 |
+
formData.append('prompt', prompt);
|
| 109 |
+
formData.append('web_search', webSearchEnabled);
|
| 110 |
+
|
| 111 |
+
if (file) {
|
| 112 |
+
formData.append('file', file);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
$.ajax({
|
| 116 |
+
url: '/send_message',
|
| 117 |
+
type: 'POST',
|
| 118 |
+
data: formData,
|
| 119 |
+
processData: false, // Important for FormData
|
| 120 |
+
contentType: false, // Important for FormData
|
| 121 |
+
success: function(response) {
|
| 122 |
+
addMessage('assistant', response.text);
|
| 123 |
+
},
|
| 124 |
+
error: function(xhr, status, error) {
|
| 125 |
+
addMessage('assistant', "Error: " + xhr.responseJSON.text); // Display error
|
| 126 |
+
},
|
| 127 |
+
complete: function(){
|
| 128 |
+
$("#loadingIndicator").addClass("hidden"); // Hide spinner
|
| 129 |
+
}
|
| 130 |
+
});
|
| 131 |
+
});
|
| 132 |
+
|
| 133 |
+
$('#webSearchToggle').change(function() {
|
| 134 |
+
$.ajax({
|
| 135 |
+
url: '/toggle_web_search',
|
| 136 |
+
type: 'POST',
|
| 137 |
+
success: function(response) {
|
| 138 |
+
console.log("Web search toggled:", response.web_search);
|
| 139 |
+
}
|
| 140 |
+
});
|
| 141 |
+
});
|
| 142 |
+
|
| 143 |
+
$("#clearChatBtn").click(function() {
|
| 144 |
+
$.ajax({
|
| 145 |
+
url: "/clear_chat",
|
| 146 |
+
type: "POST",
|
| 147 |
+
success: function(response) {
|
| 148 |
+
$("#chatMessages").empty(); // Clear the chat display
|
| 149 |
+
},
|
| 150 |
+
error: function(xhr) {
|
| 151 |
+
console.error("Error clearing chat:", xhr.statusText);
|
| 152 |
+
}
|
| 153 |
+
});
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
+
// Allow sending messages with Enter key
|
| 157 |
+
$('#promptInput').keypress(function (e) {
|
| 158 |
+
if (e.which == 13) { // Enter key pressed
|
| 159 |
+
$('#sendButton').click();
|
| 160 |
+
return false; // Prevent default behavior
|
| 161 |
+
}
|
| 162 |
+
});
|
| 163 |
+
|
| 164 |
+
});
|
| 165 |
+
</script>
|
| 166 |
</body>
|
| 167 |
+
</html>
|