-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
303 lines (261 loc) · 10.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
<title>JoeyGPT</title>
<style>
body {
background-color: #1e1e1e; /* Dark background */
color: #e0e0e0; /* Light text */
font-family: Arial, sans-serif;
display: flex;
height: 100vh;
}
#sidebar {
width: 200px;
padding: 20px;
background-color: #2c2c2c;
overflow-y: auto;
border-right: 1px solid #444;
}
#main {
flex-grow: 1;
padding: 20px;
}
#chat-container {
display: flex;
flex-direction: column;
height: calc(100% - 60px);
overflow-y: auto;
opacity: 1; /* Set initial opacity */
transition: opacity 0.5s ease; /* Smooth opacity transition */
}
.user-prompt {
align-self: flex-end;
background-color: #3a3a3a;
padding: 10px;
border-radius: 5px;
color: black; /* User prompt color */
margin: 5px 0;
animation: fadeIn 0.3s ease-in-out; /* Apply fade-in animation */
}
.ai-response {
display: flex; /* Use flexbox for aligning profile picture and text */
align-items: center; /* Center vertically */
background-color: #444;
padding: 10px;
border-radius: 5px;
color: #e0e0e0; /* AI response color */
margin: 5px 0;
line-height: 2; /* Double spacing */
max-width: 110ch; /* Limit to 110 characters */
word-wrap: break-word; /* Break long words */
animation: fadeIn 0.3s ease-in-out; /* Apply fade-in animation */
}
.ai-response img {
width: 32px; /* Adjust size if needed */
height: 32px;
margin-right: 10px; /* Space between image and text */
}
#input-area {
display: flex;
margin-top: 10px;
}
#prompt-input {
flex-grow: 1;
padding: 10px;
border: 1px solid #555;
border-radius: 5px;
background-color: #3a3a3a;
color: #e0e0e0;
line-height: 1.5; /* Spacing between lines */
}
#send-button {
padding: 10px 20px;
border: none;
background-color: #28a745;
color: white;
border-radius: 5px;
margin-left: 5px;
cursor: pointer;
transition: background-color 0.3s ease; /* Transition effect */
}
#send-button:hover {
background-color: #218838; /* Darken send button on hover */
}
#send-button:disabled {
background-color: gray;
cursor: not-allowed;
}
#new-conversation {
background-color: #444;
color: #e0e0e0;
padding: 10px;
border-radius: 5px;
margin: 5px 0;
cursor: pointer;
transition: background-color 0.3s ease; /* Transition effect */
}
#new-conversation:hover {
background-color: #555; /* Darken new conversation button on hover */
}
/* Loading spinner styles */
.loading {
display: flex;
align-items: center;
background-color: #444;
padding: 10px;
border-radius: 5px;
color: #e0e0e0;
margin: 5px 0;
}
.loading img {
width: 32px;
height: 32px;
margin-right: 10px;
}
.spinner {
border: 4px solid rgba(255, 255, 255, 0.3);
border-top: 4px solid white;
border-radius: 50%;
width: 16px;
height: 16px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Add animation for messages */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<div id="sidebar">
<div id="new-conversation">New Conversation</div>
</div>
<div id="main">
<div id="chat-container"></div>
<div id="input-area">
<input type="text" id="prompt-input" placeholder="Type your message here...">
<button id="send-button">Send</button>
</div>
</div>
<script>
let conversationHistory = [];
document.getElementById('send-button').addEventListener('click', sendPrompt);
document.getElementById('prompt-input').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
sendPrompt();
}
});
document.getElementById('new-conversation').addEventListener('click', startNewConversation);
function startNewConversation() {
const confirmStart = confirm("Are you sure you want to start a new conversation? This will clear all your session memory.");
if (confirmStart) {
// Clear the chat in the main area
clearChat();
// Clear memory in the backend
fetch('/clear_memory', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(data => {
console.log(data.message); // Log success message
})
.catch(error => {
console.error('Error:', error);
});
}
}
function clearChat() {
document.getElementById('chat-container').innerHTML = '';
document.getElementById('prompt-input').value = '';
}
function sendPrompt() {
const input = document.getElementById('prompt-input');
const prompt = input.value.trim();
if (!prompt) return;
const userMessage = { type: 'user', content: prompt };
addMessageToChat(userMessage);
// Show loading box while waiting for AI response
showLoadingSpinner();
// Disable the send button
const sendButton = document.getElementById('send-button');
sendButton.disabled = true;
fetch('/send_prompt', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt })
})
.then(response => response.json())
.then(data => {
const aiMessage = { type: 'ai', content: data.response };
addMessageToChat(aiMessage);
// Remove loading box once response is received
removeLoadingSpinner();
// Re-enable the button
sendButton.disabled = false;
// Store the message in the current conversation
conversationHistory.push(userMessage);
conversationHistory.push(aiMessage);
})
.catch(error => {
console.error('Error:', error);
});
input.value = '';
}
function addMessageToChat(message) {
const div = document.createElement('div');
div.className = message.type === 'user' ? 'user-prompt' : 'ai-response';
if (message.type === 'ai') {
const img = document.createElement('img');
img.src = '{{ url_for("static", filename="favicon-32x32.png") }}'; // Use Flask's url_for for dynamic path
img.alt = 'AI Profile Picture';
// Create a span for the AI message content
const messageContent = document.createElement('span');
messageContent.innerHTML = message.content.replace(/(\*\*|__)(.*?)\1/g, '<strong>$2</strong>').replace(/(\*|_)(.*?)\1/g, '<em>$2</em>');
// Append image and message content to the response div
div.appendChild(img);
div.appendChild(messageContent);
} else {
div.innerHTML = message.content;
}
// Set initial opacity to 0 and append message
const chatContainer = document.getElementById('chat-container');
chatContainer.style.opacity = '0'; // Fade out effect before adding new message
chatContainer.appendChild(div);
// Fade in effect
setTimeout(() => {
chatContainer.style.opacity = '1'; // Fade in effect
}, 50); // Small delay to trigger the transition
}
function showLoadingSpinner() {
const loadingDiv = document.createElement('div');
loadingDiv.classList.add('loading');
const img = document.createElement('img');
img.src = '{{ url_for("static", filename="favicon-32x32.png") }}'; // Use Flask's url_for for dynamic path
img.alt = 'AI Profile Picture';
loadingDiv.appendChild(img);
const spinner = document.createElement('div');
spinner.classList.add('spinner');
loadingDiv.appendChild(spinner);
document.getElementById('chat-container').appendChild(loadingDiv);
}
function removeLoadingSpinner() {
const loadingDiv = document.querySelector('.loading');
if (loadingDiv) {
loadingDiv.remove();
}
}
</script>
</body>
</html>