TarSh8654 commited on
Commit
145e34f
·
verified ·
1 Parent(s): 190c0a6

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +160 -75
templates/index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>AI Multi-Modal Chat</title>
7
  <!-- Tailwind CSS CDN -->
8
  <script src="https://cdn.tailwindcss.com"></script>
9
  <!-- Inter font from Google Fonts -->
@@ -11,85 +11,111 @@
11
  <style>
12
  body {
13
  font-family: 'Inter', sans-serif;
14
- background-color: #1a202c; /* Dark background */
15
  display: flex;
16
  justify-content: center;
17
  align-items: center;
18
  min-height: 100vh;
19
  margin: 0;
20
- color: #e2e8f0; /* Light text color */
21
  }
22
  .chat-container {
23
  display: flex;
24
  flex-direction: column;
25
  width: 100%;
26
  max-width: 800px;
27
- height: 90vh; /* Make it take up most of the viewport height */
28
- background-color: #2d3748; /* Darker container background */
29
- border-radius: 1rem;
30
- box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4); /* Stronger shadow */
31
- overflow: hidden; /* Ensure content doesn't spill */
 
32
  }
33
  .chat-header {
34
- padding: 1.5rem;
35
- border-bottom: 1px solid #4a5568; /* Darker border */
36
  text-align: center;
37
- font-size: 1.75rem; /* Larger title */
38
  font-weight: 700;
39
- color: #e2e8f0; /* Light text */
 
 
 
 
 
 
40
  }
41
  .messages-area {
42
- flex-grow: 1; /* Takes up available space */
43
- overflow-y: auto; /* Scrollable */
44
  padding: 1.5rem;
45
  display: flex;
46
  flex-direction: column;
47
- gap: 1rem; /* Space between messages */
 
48
  }
49
  .message-bubble {
50
- max-width: 80%;
51
- padding: 0.75rem 1rem;
52
- border-radius: 0.75rem;
53
- line-height: 1.5;
54
- word-wrap: break-word; /* Ensure long words wrap */
 
 
 
 
55
  }
56
  .user-message {
57
  background-color: #4299e1; /* Blue-400 */
58
  color: white;
59
- align-self: flex-end; /* Align to right */
60
- border-bottom-right-radius: 0.25rem; /* Sharpen one corner for bubble effect */
61
  }
62
  .ai-message {
63
- background-color: #4a5568; /* Gray-700 */
64
- color: #e2e8f0; /* Light text */
65
- align-self: flex-start; /* Align to left */
66
- border-bottom-left-radius: 0.25rem; /* Sharpen one corner for bubble effect */
 
 
 
 
 
 
 
 
 
 
67
  }
68
  .input-area {
69
  padding: 1.5rem;
70
- border-top: 1px solid #4a5568; /* Light gray border */
 
71
  display: flex;
 
72
  gap: 0.75rem;
73
- align-items: center;
74
  }
75
  textarea {
76
- resize: none; /* Prevent manual resizing */
77
  flex-grow: 1;
78
- min-height: 2.5rem;
79
  max-height: 8rem;
80
  overflow-y: auto;
81
- background-color: #2d3748; /* Same as container */
82
- color: #e2e8f0; /* Light text */
83
- border: 1px solid #4a5568; /* Darker border */
 
 
84
  }
85
  textarea:focus {
86
- border-color: #4299e1; /* Blue-400 on focus */
87
- box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.5); /* Blue shadow */
 
88
  }
89
  /* Custom spinner for loading */
90
  .spinner {
91
- border: 3px solid rgba(255, 255, 255, 0.2); /* Lighter border for dark mode */
92
- border-left-color: #4299e1; /* Blue-400 */
93
  border-radius: 50%;
94
  width: 20px;
95
  height: 20px;
@@ -101,75 +127,113 @@
101
  }
102
  .loading-message {
103
  align-self: flex-start;
104
- background-color: #4a5568;
105
  color: #e2e8f0;
106
  padding: 0.75rem 1rem;
107
  border-radius: 0.75rem;
108
  display: flex;
109
  align-items: center;
110
  gap: 0.5rem;
 
111
  }
112
  .file-input-group {
113
  display: flex;
114
- gap: 0.5rem;
115
- margin-bottom: 0.75rem;
116
  }
117
  .file-input-group label {
118
  cursor: pointer;
119
- background-color: #4a5568; /* Dark gray */
120
- color: #e2e8f0; /* Light text */
121
- padding: 0.5rem 0.75rem;
122
- border-radius: 0.5rem;
123
- transition: background-color 0.2s;
124
- font-size: 0.875rem;
125
  display: inline-flex;
126
  align-items: center;
127
- gap: 0.25rem;
 
128
  }
129
  .file-input-group label:hover {
130
- background-color: #616e80; /* Slightly lighter on hover */
 
131
  }
132
  .file-input-group input[type="file"] {
133
- display: none; /* Hide actual file input */
134
- }
135
- .uploaded-file-preview {
136
- max-width: 100%;
137
- height: auto;
138
- border-radius: 0.5rem;
139
- margin-top: 0.5rem;
140
- border: 1px solid #4a5568;
141
- }
142
- .message-image-preview {
143
- max-width: 100%;
144
- height: auto;
145
- border-radius: 0.5rem;
146
- margin-top: 0.5rem;
147
- border: 1px solid #616e80; /* Border for image in message bubble */
148
  }
149
  .clear-file-button {
150
- background-color: #e53e3e; /* Red-500 */
151
  color: white;
152
- padding: 0.25rem 0.5rem;
153
- border-radius: 0.5rem;
154
- font-size: 0.75rem;
155
  margin-left: 0.5rem;
156
  cursor: pointer;
157
- transition: background-color 0.2s;
 
158
  }
159
  .clear-file-button:hover {
160
- background-color: #c53030; /* Darker red */
 
161
  }
162
  .file-name-display {
163
  font-size: 0.875rem;
164
- color: #a0aec0; /* Gray-400 */
165
  margin-left: 0.5rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
167
  </style>
168
  </head>
169
  <body class="p-4">
170
  <div class="chat-container">
171
  <div class="chat-header">
172
- AI Multi-Modal Assistant
 
 
 
 
173
  </div>
174
  <div id="messagesArea" class="messages-area">
175
  <!-- Chat messages will be appended here -->
@@ -209,7 +273,7 @@
209
  ></textarea>
210
  <button
211
  id="sendButton"
212
- class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg flex items-center justify-center transition duration-300 ease-in-out transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50"
213
  >
214
  Send
215
  </button>
@@ -217,7 +281,7 @@
217
  </div>
218
 
219
  <!-- Message Box for alerts -->
220
- <div id="messageBox" class="fixed inset-0 bg-gray-600 bg-opacity50 flex items-center justify-center hidden">
221
  <div class="bg-white p-6 rounded-lg shadow-xl max-w-sm w-full text-gray-800">
222
  <h3 class="text-lg font-bold mb-4" id="messageBoxTitle"></h3>
223
  <p class="text-gray-700 mb-6" id="messageBoxContent"></p>
@@ -242,6 +306,7 @@
242
  const messageBoxTitle = document.getElementById('messageBoxTitle');
243
  const messageBoxContent = document.getElementById('messageBoxContent');
244
  const messageBoxClose = document.getElementById('messageBoxClose');
 
245
 
246
  let sessionId = localStorage.getItem('aiChatSessionId');
247
  if (!sessionId) {
@@ -288,7 +353,8 @@
288
  } else if (typeof content === 'string') {
289
  messageDiv.innerHTML = marked.parse(content); // Render Markdown for text
290
  } else if (typeof content === 'object' && content.type === 'image') {
291
- // Display image in message bubble (if AI sends image back, or if re-introduced)
 
292
  const img = document.createElement('img');
293
  img.src = content.src;
294
  img.alt = "Uploaded image";
@@ -300,7 +366,7 @@
300
  messageDiv.appendChild(textDiv);
301
  }
302
  } else if (typeof content === 'object' && content.type === 'document') {
303
- // Display document info in message bubble (if AI sends document back, or if re-introduced)
304
  const docInfoDiv = document.createElement('div');
305
  docInfoDiv.innerHTML = `<strong>Document Uploaded:</strong> ${content.name}<br>`;
306
  if (content.textPreview) {
@@ -568,6 +634,25 @@
568
  }
569
  });
570
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
571
  // Marked.js for Markdown rendering (simple CDN inclusion)
572
  const script = document.createElement('script');
573
  script.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Own AI Assistant</title> <!-- Changed title -->
7
  <!-- Tailwind CSS CDN -->
8
  <script src="https://cdn.tailwindcss.com"></script>
9
  <!-- Inter font from Google Fonts -->
 
11
  <style>
12
  body {
13
  font-family: 'Inter', sans-serif;
14
+ background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%); /* Subtle gradient background */
15
  display: flex;
16
  justify-content: center;
17
  align-items: center;
18
  min-height: 100vh;
19
  margin: 0;
20
+ color: #e2e8f0;
21
  }
22
  .chat-container {
23
  display: flex;
24
  flex-direction: column;
25
  width: 100%;
26
  max-width: 800px;
27
+ height: 90vh;
28
+ background-color: #202a36; /* Slightly darker than body for depth */
29
+ border-radius: 1.5rem; /* More rounded corners */
30
+ box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5); /* Deeper shadow */
31
+ overflow: hidden;
32
+ border: 1px solid rgba(74, 85, 104, 0.3); /* Subtle border */
33
  }
34
  .chat-header {
35
+ padding: 1.5rem 2rem; /* More padding */
36
+ border-bottom: 1px solid #3a4759; /* Darker border */
37
  text-align: center;
38
+ font-size: 2rem; /* Larger title */
39
  font-weight: 700;
40
+ color: #e2e8f0;
41
+ background: linear-gradient(90deg, #2d3748, #3a4759); /* Header gradient */
42
+ position: relative;
43
+ z-index: 10; /* Ensure header is above messages */
44
+ display: flex;
45
+ justify-content: space-between;
46
+ align-items: center;
47
  }
48
  .messages-area {
49
+ flex-grow: 1;
50
+ overflow-y: auto;
51
  padding: 1.5rem;
52
  display: flex;
53
  flex-direction: column;
54
+ gap: 0.75rem; /* Slightly less gap */
55
+ scroll-behavior: smooth; /* Smooth scrolling */
56
  }
57
  .message-bubble {
58
+ max-width: 85%; /* Slightly wider bubbles */
59
+ padding: 0.85rem 1.2rem; /* More padding */
60
+ border-radius: 1.2rem; /* More rounded */
61
+ line-height: 1.6;
62
+ word-wrap: break-word;
63
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Subtle bubble shadow */
64
+ opacity: 0; /* For animation */
65
+ transform: translateY(10px); /* For animation */
66
+ animation: fadeInSlideUp 0.3s ease-out forwards; /* Animation */
67
  }
68
  .user-message {
69
  background-color: #4299e1; /* Blue-400 */
70
  color: white;
71
+ align-self: flex-end;
72
+ border-bottom-right-radius: 0.4rem; /* Sharpen one corner for bubble effect */
73
  }
74
  .ai-message {
75
+ background-color: #3a4759; /* Darker gray for AI */
76
+ color: #e2e8f0;
77
+ align-self: flex-start;
78
+ border-bottom-left-radius: 0.4rem; /* Sharpen one corner for bubble effect */
79
+ }
80
+ @keyframes fadeInSlideUp {
81
+ from {
82
+ opacity: 0;
83
+ transform: translateY(10px);
84
+ }
85
+ to {
86
+ opacity: 1;
87
+ transform: translateY(0);
88
+ }
89
  }
90
  .input-area {
91
  padding: 1.5rem;
92
+ border-top: 1px solid #3a4759;
93
+ background-color: #2d3748; /* Matches body gradient start */
94
  display: flex;
95
+ flex-direction: column; /* Stack file inputs above text input */
96
  gap: 0.75rem;
 
97
  }
98
  textarea {
99
+ resize: none;
100
  flex-grow: 1;
101
+ min-height: 2.75rem; /* Slightly taller */
102
  max-height: 8rem;
103
  overflow-y: auto;
104
+ background-color: #202a36; /* Matches chat container */
105
+ color: #e2e8f0;
106
+ border: 1px solid #4a5568;
107
+ border-radius: 0.75rem; /* More rounded */
108
+ padding: 0.75rem 1rem;
109
  }
110
  textarea:focus {
111
+ border-color: #4299e1;
112
+ box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.4); /* Stronger shadow */
113
+ outline: none;
114
  }
115
  /* Custom spinner for loading */
116
  .spinner {
117
+ border: 3px solid rgba(255, 255, 255, 0.2);
118
+ border-left-color: #4299e1;
119
  border-radius: 50%;
120
  width: 20px;
121
  height: 20px;
 
127
  }
128
  .loading-message {
129
  align-self: flex-start;
130
+ background-color: #3a4759;
131
  color: #e2e8f0;
132
  padding: 0.75rem 1rem;
133
  border-radius: 0.75rem;
134
  display: flex;
135
  align-items: center;
136
  gap: 0.5rem;
137
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
138
  }
139
  .file-input-group {
140
  display: flex;
141
+ gap: 0.75rem; /* Increased gap */
142
+ width: 100%;
143
  }
144
  .file-input-group label {
145
  cursor: pointer;
146
+ background-color: #4a5568;
147
+ color: #e2e8f0;
148
+ padding: 0.6rem 1rem; /* More padding */
149
+ border-radius: 0.75rem; /* More rounded */
150
+ transition: background-color 0.2s, transform 0.1s;
151
+ font-size: 0.9rem; /* Slightly larger font */
152
  display: inline-flex;
153
  align-items: center;
154
+ gap: 0.35rem;
155
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
156
  }
157
  .file-input-group label:hover {
158
+ background-color: #5a6a7e;
159
+ transform: translateY(-1px); /* Subtle lift */
160
  }
161
  .file-input-group input[type="file"] {
162
+ display: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
  .clear-file-button {
165
+ background-color: #e53e3e;
166
  color: white;
167
+ padding: 0.4rem 0.75rem; /* Adjusted padding */
168
+ border-radius: 0.75rem;
169
+ font-size: 0.8rem;
170
  margin-left: 0.5rem;
171
  cursor: pointer;
172
+ transition: background-color 0.2s, transform 0.1s;
173
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
174
  }
175
  .clear-file-button:hover {
176
+ background-color: #c53030;
177
+ transform: translateY(-1px);
178
  }
179
  .file-name-display {
180
  font-size: 0.875rem;
181
+ color: #a0aec0;
182
  margin-left: 0.5rem;
183
+ display: flex;
184
+ align-items: center;
185
+ flex-grow: 1; /* Allow it to take available space */
186
+ white-space: nowrap; /* Prevent wrapping */
187
+ overflow: hidden; /* Hide overflow */
188
+ text-overflow: ellipsis; /* Add ellipsis */
189
+ }
190
+ .send-button {
191
+ background: linear-gradient(90deg, #4299e1, #3182ce); /* Gradient button */
192
+ color: white;
193
+ font-weight: 600;
194
+ padding: 0.75rem 1.5rem;
195
+ border-radius: 0.75rem;
196
+ transition: transform 0.2s, box-shadow 0.2s;
197
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
198
+ }
199
+ .send-button:hover {
200
+ transform: translateY(-2px);
201
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
202
+ }
203
+ .send-button:disabled {
204
+ background: #4a5568;
205
+ cursor: not-allowed;
206
+ transform: none;
207
+ box-shadow: none;
208
+ opacity: 0.7;
209
+ }
210
+ .new-chat-button {
211
+ background-color: #63b3ed; /* Light blue for new chat */
212
+ color: #1a202c; /* Dark text */
213
+ padding: 0.5rem 1rem;
214
+ border-radius: 0.75rem;
215
+ font-size: 0.9rem;
216
+ font-weight: 600;
217
+ transition: background-color 0.2s, transform 0.1s;
218
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
219
+ display: flex;
220
+ align-items: center;
221
+ gap: 0.25rem;
222
+ }
223
+ .new-chat-button:hover {
224
+ background-color: #4299e1;
225
+ transform: translateY(-1px);
226
  }
227
  </style>
228
  </head>
229
  <body class="p-4">
230
  <div class="chat-container">
231
  <div class="chat-header">
232
+ <span>Own AI Assistant</span> <!-- Changed header text -->
233
+ <button id="newChatButton" class="new-chat-button">
234
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
235
+ New Chat
236
+ </button>
237
  </div>
238
  <div id="messagesArea" class="messages-area">
239
  <!-- Chat messages will be appended here -->
 
273
  ></textarea>
274
  <button
275
  id="sendButton"
276
+ class="send-button flex items-center justify-center"
277
  >
278
  Send
279
  </button>
 
281
  </div>
282
 
283
  <!-- Message Box for alerts -->
284
+ <div id="messageBox" class="fixed inset-0 bg-gray-600 bg-opacity-50 flex items-center justify-center hidden">
285
  <div class="bg-white p-6 rounded-lg shadow-xl max-w-sm w-full text-gray-800">
286
  <h3 class="text-lg font-bold mb-4" id="messageBoxTitle"></h3>
287
  <p class="text-gray-700 mb-6" id="messageBoxContent"></p>
 
306
  const messageBoxTitle = document.getElementById('messageBoxTitle');
307
  const messageBoxContent = document.getElementById('messageBoxContent');
308
  const messageBoxClose = document.getElementById('messageBoxClose');
309
+ const newChatButton = document.getElementById('newChatButton'); // New button
310
 
311
  let sessionId = localStorage.getItem('aiChatSessionId');
312
  if (!sessionId) {
 
353
  } else if (typeof content === 'string') {
354
  messageDiv.innerHTML = marked.parse(content); // Render Markdown for text
355
  } else if (typeof content === 'object' && content.type === 'image') {
356
+ // This block is now effectively unused for user messages as displayContent will be a string
357
+ // But keeping it here for potential future use or if AI sends image back
358
  const img = document.createElement('img');
359
  img.src = content.src;
360
  img.alt = "Uploaded image";
 
366
  messageDiv.appendChild(textDiv);
367
  }
368
  } else if (typeof content === 'object' && content.type === 'document') {
369
+ // This block is now effectively unused for user messages as displayContent will be a string
370
  const docInfoDiv = document.createElement('div');
371
  docInfoDiv.innerHTML = `<strong>Document Uploaded:</strong> ${content.name}<br>`;
372
  if (content.textPreview) {
 
634
  }
635
  });
636
 
637
+ // New Chat Button functionality
638
+ newChatButton.addEventListener('click', () => {
639
+ if (confirm("Are you sure you want to start a new chat? This will clear the current conversation history.")) {
640
+ localStorage.removeItem('aiChatSessionId'); // Clear session ID
641
+ sessionId = crypto.randomUUID(); // Generate new one
642
+ localStorage.setItem('aiChatSessionId', sessionId);
643
+ messagesArea.innerHTML = `
644
+ <div class="ai-message message-bubble">
645
+ Hello! How can I assist you today? You can type a message, or upload an image, a text document, or a PDF.
646
+ </div>
647
+ `; // Clear chat display
648
+ clearFileSelection(); // Clear any pending file uploads
649
+ messageInput.value = ''; // Clear text input
650
+ messageInput.style.height = 'auto'; // Reset textarea height
651
+ messageInput.focus();
652
+ console.log("New chat started. New session ID:", sessionId);
653
+ }
654
+ });
655
+
656
  // Marked.js for Markdown rendering (simple CDN inclusion)
657
  const script = document.createElement('script');
658
  script.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';