srinuksv commited on
Commit
d776cdd
1 Parent(s): 59eea30

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +92 -26
static/index.html CHANGED
@@ -4,6 +4,7 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
 
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
@@ -15,38 +16,43 @@
15
  max-width: 600px;
16
  margin: auto;
17
  padding: 20px;
18
- border-radius: 10px;
19
- background-color: #f9f9f9;
20
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
21
  }
22
  #chat-history {
23
  height: 400px;
24
  overflow-y: auto;
25
  margin-bottom: 10px;
26
- border: 1px solid #ddd;
27
- background: white;
28
- border-radius: 10px;
29
  padding: 10px;
 
 
 
30
  }
31
  .message {
32
- margin: 5px 0;
33
- padding: 10px;
34
- border-radius: 10px;
35
  position: relative;
36
- max-width: 80%;
 
 
 
 
 
 
37
  }
38
  .user-message {
39
- background-color: #d1ecf1;
40
- border: 1px solid #bee5eb;
41
  color: #0c5460;
42
  margin-left: auto;
43
  }
44
  .bot-message {
45
- background-color: #f8d7da;
46
- border: 1px solid #f5c6cb;
47
  color: #721c24;
48
  margin-right: auto;
49
  }
 
 
 
 
50
  #loading {
51
  display: none;
52
  margin: 10px 0;
@@ -54,21 +60,33 @@
54
  }
55
  #user-input {
56
  border: 1px solid #ccc;
 
57
  }
58
  #user-input:focus {
59
  border-color: #007bff;
60
  outline: none;
61
  }
62
- .btn-send {
63
  background-color: #007bff;
64
  color: white;
65
  }
66
- .btn-send:hover {
67
- background-color: #0056b3;
68
- transform: scale(1.05);
69
  }
70
- .btn-send:active {
71
- transform: scale(0.95);
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
  </style>
74
  <title>Chat Interface</title>
@@ -79,14 +97,21 @@
79
  <div id="loading" class="spinner-border text-primary" role="status">
80
  <span class="sr-only">Loading...</span>
81
  </div>
82
- <div class="input-group">
83
  <input type="text" id="user-input" class="form-control" placeholder="Type your message..." aria-label="Message input">
84
  <div class="input-group-append">
85
- <button id="send-button" class="btn btn-send" aria-label="Send message">Send</button>
 
 
 
 
 
86
  </div>
87
  </div>
88
  </div>
89
  <script>
 
 
90
  document.getElementById("send-button").addEventListener("click", sendMessage);
91
  document.getElementById("user-input").addEventListener("keypress", function(event) {
92
  if (event.key === "Enter") {
@@ -94,7 +119,9 @@
94
  sendMessage();
95
  }
96
  });
97
-
 
 
98
  async function sendMessage() {
99
  const input = document.getElementById("user-input");
100
  const message = input.value.trim();
@@ -102,10 +129,12 @@
102
  return;
103
  }
104
  addMessage("User", message, "user-message");
 
105
  input.value = "";
106
 
107
  // Show loading spinner
108
  document.getElementById("loading").style.display = "block";
 
109
 
110
  try {
111
  const response = await fetch("/chat/", {
@@ -120,23 +149,60 @@
120
  }
121
  const data = await response.json();
122
  addMessage("Bot", data.response, "bot-message");
 
123
  } catch (error) {
124
  console.error('Error:', error);
125
  addMessage("Bot", "Sorry, something went wrong.", "bot-message");
126
  } finally {
127
  // Hide loading spinner
128
  document.getElementById("loading").style.display = "none";
 
129
  }
130
  }
131
-
132
  function addMessage(sender, message, className) {
133
  const chatHistory = document.getElementById("chat-history");
134
  const messageElement = document.createElement("div");
135
  messageElement.className = `message ${className}`;
136
- messageElement.innerHTML = `<strong>${sender}:</strong> ${message}`;
 
 
 
 
 
137
  chatHistory.appendChild(messageElement);
138
  chatHistory.scrollTop = chatHistory.scrollHeight;
139
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  </script>
141
  </body>
142
- </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
8
  <style>
9
  body {
10
  font-family: Arial, sans-serif;
 
16
  max-width: 600px;
17
  margin: auto;
18
  padding: 20px;
19
+ border-radius: 30px; /* Modern rounded corners */
20
+ background-color: #fff;
21
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
22
  }
23
  #chat-history {
24
  height: 400px;
25
  overflow-y: auto;
26
  margin-bottom: 10px;
 
 
 
27
  padding: 10px;
28
+ background-color: #f9f9f9;
29
+ border-radius: 20px; /* Rounded corners for chat history */
30
+ box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
31
  }
32
  .message {
 
 
 
33
  position: relative;
34
+ padding: 8px 12px;
35
+ margin: 5px 0;
36
+ border-radius: 20px; /* Rounded corners for messages */
37
+ max-width: 70%;
38
+ font-size: 0.85em;
39
+ cursor: pointer;
40
+ transition: background-color 0.3s;
41
  }
42
  .user-message {
43
+ background: linear-gradient(135deg, #d1ecf1 0%, #a8d8e0 100%);
 
44
  color: #0c5460;
45
  margin-left: auto;
46
  }
47
  .bot-message {
48
+ background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
 
49
  color: #721c24;
50
  margin-right: auto;
51
  }
52
+ .user-icon, .bot-icon {
53
+ margin-right: 8px;
54
+ font-size: 1.1em;
55
+ }
56
  #loading {
57
  display: none;
58
  margin: 10px 0;
 
60
  }
61
  #user-input {
62
  border: 1px solid #ccc;
63
+ border-radius: 5px;
64
  }
65
  #user-input:focus {
66
  border-color: #007bff;
67
  outline: none;
68
  }
69
+ .btn-icon {
70
  background-color: #007bff;
71
  color: white;
72
  }
73
+ .btn-close {
74
+ background-color: #dc3545;
75
+ color: white;
76
  }
77
+ .btn-close:hover {
78
+ background-color: #c82333;
79
+ }
80
+ .typing-indicator {
81
+ font-style: italic;
82
+ color: #aaa;
83
+ margin: 5px 0;
84
+ }
85
+ .timestamp {
86
+ font-size: 0.75em;
87
+ color: #aaa;
88
+ display: none; /* Hidden by default */
89
+ margin-top: 5px;
90
  }
91
  </style>
92
  <title>Chat Interface</title>
 
97
  <div id="loading" class="spinner-border text-primary" role="status">
98
  <span class="sr-only">Loading...</span>
99
  </div>
100
+ <div class="input-group mb-2">
101
  <input type="text" id="user-input" class="form-control" placeholder="Type your message..." aria-label="Message input">
102
  <div class="input-group-append">
103
+ <button id="send-button" class="btn btn-icon" aria-label="Send message">
104
+ <i class="fas fa-paper-plane"></i>
105
+ </button>
106
+ <button id="close-button" class="btn btn-close" aria-label="Close chat">
107
+ <i class="fas fa-times"></i>
108
+ </button>
109
  </div>
110
  </div>
111
  </div>
112
  <script>
113
+ let chatHistoryArray = [];
114
+
115
  document.getElementById("send-button").addEventListener("click", sendMessage);
116
  document.getElementById("user-input").addEventListener("keypress", function(event) {
117
  if (event.key === "Enter") {
 
119
  sendMessage();
120
  }
121
  });
122
+
123
+ document.getElementById("close-button").addEventListener("click", closeChat);
124
+
125
  async function sendMessage() {
126
  const input = document.getElementById("user-input");
127
  const message = input.value.trim();
 
129
  return;
130
  }
131
  addMessage("User", message, "user-message");
132
+ chatHistoryArray.push({ sender: "User", message: message });
133
  input.value = "";
134
 
135
  // Show loading spinner
136
  document.getElementById("loading").style.display = "block";
137
+ showTypingIndicator();
138
 
139
  try {
140
  const response = await fetch("/chat/", {
 
149
  }
150
  const data = await response.json();
151
  addMessage("Bot", data.response, "bot-message");
152
+ chatHistoryArray.push({ sender: "Bot", message: data.response });
153
  } catch (error) {
154
  console.error('Error:', error);
155
  addMessage("Bot", "Sorry, something went wrong.", "bot-message");
156
  } finally {
157
  // Hide loading spinner
158
  document.getElementById("loading").style.display = "none";
159
+ hideTypingIndicator();
160
  }
161
  }
162
+
163
  function addMessage(sender, message, className) {
164
  const chatHistory = document.getElementById("chat-history");
165
  const messageElement = document.createElement("div");
166
  messageElement.className = `message ${className}`;
167
+ const icon = sender === "User" ? '<i class="fas fa-user user-icon"></i>' : '<i class="fas fa-robot bot-icon"></i>';
168
+ messageElement.innerHTML = `${icon}<div>${message} <span class="timestamp">${new Date().toLocaleTimeString()}</span></div>`;
169
+ messageElement.onclick = function() {
170
+ const timestamp = messageElement.querySelector('.timestamp');
171
+ timestamp.style.display = timestamp.style.display === 'none' ? 'block' : 'none';
172
+ };
173
  chatHistory.appendChild(messageElement);
174
  chatHistory.scrollTop = chatHistory.scrollHeight;
175
  }
176
+
177
+ function showTypingIndicator() {
178
+ const typingElement = document.createElement("div");
179
+ typingElement.className = "typing-indicator";
180
+ typingElement.innerText = "Bot is typing...";
181
+ document.getElementById("chat-history").appendChild(typingElement);
182
+ }
183
+
184
+ function hideTypingIndicator() {
185
+ const typingIndicator = document.querySelector(".typing-indicator");
186
+ if (typingIndicator) {
187
+ typingIndicator.remove();
188
+ }
189
+ }
190
+
191
+ async function closeChat() {
192
+ try {
193
+ await fetch("/hist/", {
194
+ method: "POST",
195
+ headers: {
196
+ "Content-Type": "application/json"
197
+ },
198
+ body: JSON.stringify({ history: chatHistoryArray })
199
+ });
200
+ } catch (error) {
201
+ console.error('Error sending chat history:', error);
202
+ } finally {
203
+ window.location.href = "https://redfernstech.com";
204
+ }
205
+ }
206
  </script>
207
  </body>
208
+ </html>