-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex_blue.html
More file actions
234 lines (212 loc) · 8.92 KB
/
index_blue.html
File metadata and controls
234 lines (212 loc) · 8.92 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>S.A.G.A.R Chatbot</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
margin: 0;
padding: 0;
overflow: hidden;
background: linear-gradient(rgba(15, 23, 42, 0.6), rgba(15, 23, 42, 0.6)),
url('/static/bg4.jpg') center center / cover no-repeat;
color: #cbd5e1;
}
#chat-messages-container {
flex-grow: 1;
overflow-y: auto;
scroll-behavior: smooth;
backdrop-filter: blur(8px);
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background-color: #06b6d4;
border-radius: 10px;
}
.message-bubble {
padding: 1rem;
border-radius: 1.5rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
max-width: 75%;
word-wrap: break-word;
}
.user-msg {
background: linear-gradient(to right, #06b6d4, #22d3ee);
color: white;
border-bottom-right-radius: 0.25rem;
}
.bot-msg {
background: rgba(255, 255, 255, 0.05);
border: 1px solid #334155;
color: #cbd5e1;
border-bottom-left-radius: 0.25rem;
}
.suggested-btn {
background-color: #06b6d4;
color: white;
border-radius: 9999px;
padding: 0.5rem 1rem;
font-size: 0.875rem;
transition: background-color 0.2s ease;
}
.suggested-btn:hover {
background-color: #0891b2;
}
</style>
</head>
<body class="flex flex-col h-screen text-white">
<header class="bg-gradient-to-r from-slate-900 via-slate-800 to-slate-900 p-3 shadow-2xl rounded-b-xl border-b border-slate-700">
<div class="flex items-center justify-center gap-4">
<div class="w-3 h-3 rounded-full bg-cyan-400 animate-bounce"></div>
<h1 class="text-4xl font-bold tracking-wider font-mono uppercase drop-shadow-md">S.A.G.A.R</h1>
<div class="w-3 h-3 rounded-full bg-cyan-400 animate-bounce"></div>
</div>
</header>
<div id="chat-messages-container" class="custom-scrollbar p-4 space-y-4 pt-8 pb-24 overflow-y-auto">
<div id="initial-welcome" class="flex justify-center items-center h-full">
<p class="text-slate-300 text-lg italic">Start a conversation! Type your message below.</p>
</div>
</div>
<div class="fixed bottom-24 left-0 right-0 px-6 flex flex-wrap justify-center gap-2 z-10">
<button class="suggested-btn">Write a python code for a To-do app</button>
<button class="suggested-btn">Weather in Sambhaji Nagar</button>
<button class="suggested-btn">Tell me a Horror Story</button>
</div>
<form id="chat-form" class="p-4 bg-slate-900 border-t border-slate-700 shadow-xl fixed bottom-0 left-0 right-0 z-10">
<div class="flex items-center space-x-3 max-w-2xl mx-auto">
<label for="file-input" class="cursor-pointer bg-slate-800 p-3 rounded-full hover:bg-slate-700 transition">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
</svg>
</label>
<input type="file" id="file-input" class="hidden" />
<input type="text" id="message-input" placeholder="Say something..."
class="flex-1 p-3 border border-cyan-500 rounded-full focus:outline-none focus:ring-2 focus:ring-cyan-400 bg-slate-800 text-white" />
<button type="submit" id="send-button"
class="bg-cyan-500 text-white p-3 rounded-full shadow-lg hover:bg-cyan-600 focus:ring-2 focus:ring-cyan-400 disabled:opacity-50 transition transform hover:scale-105">
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" class="w-6 h-6" viewBox="0 0 24 24">
<path d="M3.478 2.405a.75.75 0 0 0-.926.94l2.432 7.905H13.5a.75.75 0 0 1 0 1.5H4.984l-2.432 7.905a.75.75 0 0 0 .926.94 60.542 60.542 0 0 0 18.445-8.986.75.75 0 0 0 0-1.218A60.542 60.542 0 0 0 3.478 2.405Z" />
</svg>
</button>
</div>
</form>
<script>
const chatMessagesContainer = document.getElementById('chat-messages-container');
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
const chatForm = document.getElementById('chat-form');
const fileInput = document.getElementById('file-input');
let initialWelcome = document.getElementById('initial-welcome');
let uploadedFilename = "";
function addMessageToChat(role, text) {
if (initialWelcome) {
initialWelcome.remove();
initialWelcome = null;
}
const messageDiv = document.createElement('div');
messageDiv.className = `flex ${role === 'user' ? 'justify-end' : 'justify-start'}`;
const bubbleDiv = document.createElement('div');
bubbleDiv.className = `message-bubble ${role === 'user' ? 'user-msg' : 'bot-msg'}`;
bubbleDiv.innerHTML = text
.replace(/```(?:\w+)?\n([\s\S]*?)```/g, '<pre class="bg-black text-green-400 p-2 rounded-md overflow-x-auto"><code>$1</code></pre>')
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n/g, "<br>");
messageDiv.appendChild(bubbleDiv);
chatMessagesContainer.appendChild(messageDiv);
chatMessagesContainer.scrollTop = chatMessagesContainer.scrollHeight;
}
function showTypingIndicator(show) {
const existing = document.getElementById('typing-indicator');
if (show && !existing) {
const indicator = document.createElement('div');
indicator.id = 'typing-indicator';
indicator.className = 'flex justify-start';
indicator.innerHTML = `
<div class="max-w-[75%] p-4 rounded-2xl bg-white/10 border border-gray-500 text-white rounded-bl-sm">
<div class="flex space-x-2">
<div class="w-2 h-2 bg-white rounded-full animate-bounce"></div>
<div class="w-2 h-2 bg-white rounded-full animate-bounce delay-200"></div>
<div class="w-2 h-2 bg-white rounded-full animate-bounce delay-400"></div>
</div>
</div>`;
chatMessagesContainer.appendChild(indicator);
chatMessagesContainer.scrollTop = chatMessagesContainer.scrollHeight;
} else if (!show && existing) {
existing.remove();
}
}
chatForm.addEventListener('submit', async (e) => {
e.preventDefault();
const userMessage = messageInput.value.trim();
if (!userMessage) return;
sendButton.disabled = true;
messageInput.disabled = true;
addMessageToChat('user', userMessage);
showTypingIndicator(true);
try {
let res;
if (uploadedFilename && userMessage.toLowerCase().includes('explain')) {
// Ask about uploaded file
res = await fetch("http://localhost:5000/ask-file", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
filename: uploadedFilename,
question: userMessage
})
});
} else {
// Regular chat
res = await fetch("http://localhost:5000/chat", {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: userMessage })
});
}
const data = await res.json();
addMessageToChat('model', data.response || '❌ No response.');
} catch (err) {
console.error(err);
addMessageToChat('model', '❌ Error sending message.');
} finally {
sendButton.disabled = false;
messageInput.disabled = false;
messageInput.value = '';
showTypingIndicator(false);
messageInput.focus();
}
});
fileInput.addEventListener('change', async () => {
const file = fileInput.files[0];
if (!file) return;
const formData = new FormData();
formData.append('file', file);
showTypingIndicator(true);
try {
const res = await fetch("http://localhost:5000/upload", {
method: 'POST',
body: formData
});
const data = await res.json();
if (data.error) {
addMessageToChat('model', `❌ Upload failed: ${data.error}`);
} else {
uploadedFilename = data.filename;
addMessageToChat('model', `✅ Uploaded file: ${data.filename}`);
}
} catch (err) {
console.error(err);
addMessageToChat('model', '❌ Upload failed (network/server error).');
} finally {
fileInput.value = '';
showTypingIndicator(false);
}
});
</script>
</body>
</html>