-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
236 lines (221 loc) · 11.3 KB
/
index.html
File metadata and controls
236 lines (221 loc) · 11.3 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
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdn.tailwindcss.com"></script>
<title>AI Chatbot</title>
</head>
<body>
<div class="flex-1 p-2 sm:p-6 justify-between flex flex-col h-screen">
<div
class="flex sm:items-center justify-between py-3 border-b-2 border-gray-200"
>
<div class="relative flex items-center space-x-4">
<div class="relative">
<span class="absolute text-green-500 right-0 bottom-0">
<svg width="20" height="20">
<circle cx="8" cy="8" r="8" fill="currentColor"></circle>
</svg>
</span>
<img
src="https://img.freepik.com/free-vector/cute-robot-holding-phone-with-laptop-cartoon-vector-icon-illustration-science-technology-isolated_138676-4870.jpg"
alt=""
class="w-10 sm:w-16 h-10 sm:h-16 rounded-full"
/>
</div>
<div class="flex flex-col leading-tight">
<div class="text-2xl mt-1 flex items-center">
<span class="text-gray-700 mr-3">AI Chatbot</span>
</div>
<span class="text-lg text-gray-600 text-xl">Document Assistant</span>
</div>
</div>
<div class="flex items-center space-x-2">
<button
type="button"
class="inline-flex items-center justify-center rounded-lg border h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
></path>
</svg>
</button>
<button
type="button"
class="inline-flex items-center justify-center rounded-lg border h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
></path>
</svg>
</button>
<button
type="button"
class="inline-flex items-center justify-center rounded-lg border h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none"
>
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
class="h-6 w-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
></path>
</svg>
</button>
</div>
</div>
<div id="messages" class="flex flex-col space-y-4 p-3 overflow-y-auto scrollbar-thumb-blue scrollbar-thumb-rounded scrollbar-track-blue-lighter scrollbar-w-2 scrolling-touch">
<div class="flex items-start">
<div class="flex flex-col space-y-2 text-xs max-w-xs mx-2 order-2 items-start">
<div>
<span class="px-4 py-2 rounded-lg inline-block bg-gray-300 text-gray-600 text-xl">Hey there 👋 How can I assist you today?</span>
</div>
</div>
<img src="https://img.freepik.com/free-vector/cute-robot-holding-phone-with-laptop-cartoon-vector-icon-illustration-science-technology-isolated_138676-4870.jpg" alt="Bot Profile" class="w-6 h-6 rounded-full order-${isUser ? "2" : "1"}">
</div>
<!-- Existing chat messages will be dynamically added here -->
</div>
<div class="border-t-2 border-gray-200 px-4 pt-4 mb-2 sm:mb-0">
<div class="relative flex">
<span class="absolute inset-y-0 flex items-center">
<button type="button" class="inline-flex items-center justify-center rounded-full h-12 w-12 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="h-6 w-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 11-6 0 3 3 0 016 0z"></path>
</svg>
</button>
</span>
<input type="text" placeholder="Write your message!" class="w-full focus:outline-none focus:placeholder-gray-400 text-gray-600 text-xl placeholder-gray-600 pl-12 bg-gray-200 rounded-md py-3" id="user-query" />
<div class="absolute right-0 items-center inset-y-0 hidden sm:flex">
<button type="button" class="inline-flex items-center justify-center rounded-full h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="h-6 w-6 text-gray-600 text-xl">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
</svg>
</button>
<button type="button" class="inline-flex items-center justify-center rounded-full h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="h-6 w-6 text-gray-600 text-xl">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path>
</svg>
</button>
<button type="button" class="inline-flex items-center justify-center rounded-full h-10 w-10 transition duration-500 ease-in-out text-gray-500 hover:bg-gray-300 focus:outline-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="h-6 w-6 text-gray-600 text-xl">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path>
</svg>
</button>
<button type="button" class="inline-flex items-center justify-center rounded-lg px-4 py-3 transition duration-500 ease-in-out text-white bg-blue-500 hover:bg-blue-400 focus:outline-none" onclick="sendMessage()">
<span class="font-bold">Send</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="h-6 w-6 ml-2 transform rotate-90">
<path d="M10.894 2.553a1 1 0 00-1.788 0l-7 14a1 1 0 001.169 1.409l5-1.429A1 1 0 009 15.571V11a1 1 0 112 0v4.571a1 1 0 00.725.962l5 1.428a1 1 0 001.17-1.408l-7-14z"></path>
</svg>
</button>
</div>
</div>
</div>
</div>
<style>
.scrollbar-w-2::-webkit-scrollbar {
width: 0.25rem;
height: 0.25rem;
}
.scrollbar-track-blue-lighter::-webkit-scrollbar-track {
--bg-opacity: 1;
background-color: #f7fafc;
background-color: rgba(247, 250, 252, var(--bg-opacity));
}
.scrollbar-thumb-blue::-webkit-scrollbar-thumb {
--bg-opacity: 1;
background-color: #edf2f7;
background-color: rgba(237, 242, 247, var(--bg-opacity));
}
.scrollbar-thumb-rounded::-webkit-scrollbar-thumb {
border-radius: 0.25rem;
}
</style>
<script>
const messagesContainer = document.getElementById("messages");
const userInput = document.getElementById("user-query");
function addMessage(isUser, text) {
const messageDiv = document.createElement("div");
messageDiv.className = "chat-message";
messageDiv.innerHTML = `
<div class="flex ${isUser ? "items-end justify-end" : "items-start"}">
<div class="flex flex-col space-y-2 text-xs max-w-xs mx-2 order-${isUser ? "1" : "2"} items-${isUser ? "end" : "start"}">
<div>
<span class="px-4 py-2 rounded-lg inline-block ${
isUser ? "rounded-br-none bg-blue-600 text-white" : "bg-gray-300 text-gray-600"
} text-xl">${text}</span>
</div>
</div>
<img src="${isUser ? "https://img.freepik.com/premium-vector/person-icon-flat-design-template-isolated-avatar-sign-vector-illustration_109161-1681.jpg" : "https://img.freepik.com/free-vector/cute-robot-holding-phone-with-laptop-cartoon-vector-icon-illustration-science-technology-isolated_138676-4870.jpg"}" alt="Profile" class="w-6 h-6 rounded-full order-${isUser ? "2" : "1"}">
</div>
`;
messagesContainer.appendChild(messageDiv);
}
function sendMessage() {
const userMessage = userInput.value.trim();
if (userMessage === "") return;
// Display user message
addMessage(true, userMessage);
// Clear input field
userInput.value = "";
// Display loading message
addMessage(false, "Typing...");
// Make API request
fetch("http://127.0.0.1:5000/response", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ user_input: userMessage }),
})
.then((response) => response.json())
.then((data) => {
// Remove the "Loading response..." message
messagesContainer.removeChild(messagesContainer.lastChild);
// Display recommended document
const recommendedDocument = data.response.recommended_document;
addMessage(false, `The document I recommend is:\n${recommendedDocument}`);
// Display steps in bullet points
const steps = data.response.steps;
const stepsText = steps.map((step) => `➢ ${step}`).join("\n");
addMessage(false, `Steps:\n${stepsText}`);
// Display additional advice
const additionalAdvice = data.response.additional_advice;
addMessage(false, `Additional Advice:\n${additionalAdvice}`);
})
.catch((error) => {
console.error("Error fetching data:", error);
// Remove the "Loading response..." message in case of an error
messagesContainer.removeChild(messagesContainer.lastChild);
addMessage(false, "Error in API request");
});
}
</script>
</body>
</html>