-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHelo.html
304 lines (276 loc) · 10.6 KB
/
Helo.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
304
<!DOCTYPE html>
<html>
<head>
<title>Corpus Base Chatbot</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
</head>
<body>
<br>
<br>
<!-- Choosing the paper and submitting it to the flask api for building the rules -->
<div id="myform">
<h4 id="sub"></h4>
<label id="uploadfile" widht="200px">
<input id="Files" name="file" type="file" onchange="Submitpaper()" accept=".pdf, .docx"/>
Chose Paper
</label>
<br>
<br>
<br>
<input id="submitfile" type="submit" value="Submit" onclick="UploadFile()">
<h4 id="paper">Choose paper for chatbot</h4>
</div>
<!-- Chatbot interface showing chatbot replies on the left and users message on the right while getting user response from the bottom of the div -->
<div id="container">
<div id="message">
<table id="mymessage">
<tr>
<th colspan="2" width="100%"></th>
<th width="100%"></th>
</tr>
<tr>
<td id="h11">Hello! How can i help you with the paper?</td>
<td></td>
</tr>
</table>
</div>
<hr style="height:1px;border:0;color:black;background-color:black;margin: 0;padding: 0;">
<div id="InputDiv">
<input id="input" type="text" name="message" placeholder="Enter Message!">
<a id="btn" onclick="userMessage()">Send</a>
</div>
</div>
<!-- Floating button that shows option of chosing paper when clicked and initiate chat -->
<button id="chatbot" style="position:fixed;right:1%;bottom:1%;" onclick="Chatbot()">Chatbot</button>
<!-- In Line Styles For Web Page -->
<style>
.spinner {
animation: rotate 2s linear infinite;
z-index: 2;
position: absolute;
top: 50%;
left: 50%;
margin: -25px 0 0 -25px;
width: 50px;
height: 50px;
}
.path {
animation: rotate 2s linear infinite;
z-index: 2;
position: absolute;
top: 50%;
left: 50%;
margin: -25px 0 0 -25px;
width: 50px;
height: 50px;
stroke: hsl(210, 70, 75);
stroke-linecap: round;
animation: dash 1.5s ease-in-out infinite;
}
@keyframes rotate {
100% {
transform: rotate(360deg);
}
}
@keyframes dash {
0% {
stroke-dasharray: 1, 150;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 90, 150;
stroke-dashoffset: -124;
}
}
#h12 {
font-size: medium;
padding: 10px;
background-color: #B4DEC5;
width: fit-content;
border-radius: 10px;
float: right;
}
#mymessage {
padding: 10px;
width: 100%;
}
#h11 {
padding: 10px;
font-size: medium;
width: 60%;
border-radius: 10px;
background-color: #B4B9DE;
text-align: left;
}
#input {
width: 86%;
border-radius: 0 0 0 10px;
padding: 1%;
color: black;
height: 4vh;
border-width: 0 1px 0 0;
background-color: rgb(203, 203, 203);
}
#input:focus,
input:focus {
outline: none;
}
#btn {
border-radius: 0 0 10px 0;
height: 4vh;
cursor: pointer;
border: black;
color: rgb(130, 7, 7);
}
#container {
visibility: hidden;
margin-top: -3%;
background-color: rgb(203, 203, 203);
border-radius: 10px;
margin-left: 30%;
margin-right: 30%;
}
#message {
margin-top: 15%;
height: 400px;
overflow-y: scroll;
}
#message::-webkit-scrollbar {
display: none;
}
#title {
font-size: xx-large;
font-weight: bold;
color: white;
}
input[type="file"] {
display: none;
}
#myform {
text-align: center;
visibility: hidden;
}
#uploadfile {
margin-top: 2%;
color: rgb(255, 255, 255);
background-color: #727272;
border-radius: 10px;
padding: 1%;
cursor: pointer;
text-decoration: none;
width: 100%;
}
#chatbot {
color: rgb(255, 255, 255);
background-color: #3d7bb0;
border-color: transparent;
border-radius: 10px;
padding: 1%;
cursor: pointer;
text-decoration: none;
}
#submitfile {
color: rgb(255, 255, 255);
background-color: #3d4ddc;
border-color: transparent;
border-radius: 10px;
padding: 1%;
cursor: pointer;
text-decoration: none;
}
</style>
<script>
function Submitpaper() {
var paper = document.getElementById('paper');
paper.innerHTML = "Submit the selected paper"
}
// Function caling flask api when click on the submit button and file is send in the API to flask
$(function () {
$('#submitfile').click(function () {
var sub = document.getElementById('sub');
sub.innerHTML = "✅ Your paper is submitted wait for some seconds to chat..."
const formData = new FormData();
formData.append("file", document.getElementById('Files').files[0]);
$.ajax({
type: 'POST',
url: "http://127.0.0.1:3000/chosecsv",
data: formData,
contentType: false,
cache: false,
processData: false,
success: function (data) {
var ins = document.getElementById('container');
ins.style.visibility = "visible"
var sub = document.getElementById('sub');
sub.innerHTML = ""
var paper = document.getElementById('paper');
paper.innerHTML = ""
}
});
});
});
// Fuction initiate chat by when click on the chatbot floating button
function Chatbot() {
var ins = document.getElementById('myform');
ins.style.visibility = "visible"
}
// Fuction Checking if a file is uploaded before submitting if not then it wil show a alert
function UploadFile() {
var ins = document.getElementById('Files').files.length;
if (ins === 0) {
alert("No File Selected")
}
}
// Checking whether enter is pressed while getting response from the user and if yes then call user message function by activating
// on click function on element with btn id
input.addEventListener("keypress", function (event) {
if (event.key === "Enter") {
event.preventDefault();
document.getElementById("btn").click();
}
});
// Function that call flask API to send the user response to the chatbot and get the chatbot response in return
function userMessage() {
let myphase = document.querySelector("#convophase");
let userInput = document.querySelector("#input");
let message = document.querySelector("#message");
let mymessage = document.querySelector("#mymessage");
if (userInput.value != "") {
let table = document.getElementById("mymessage");
let row = table.insertRow(-1);
let c1 = row.insertCell(0);
let c2 = row.insertCell(1);
c1.innerText = ""
c2.innerText = userInput.value
c2.setAttribute("id", "h12")
$.ajax({
url: "http://127.0.0.1:3000/response",
method: "post",
data: {
usermessage: userInput.value
},
success: function (reply) {
let table = document.getElementById("mymessage");
let row = table.insertRow(-1);
let c1 = row.insertCell(0);
let c2 = row.insertCell(1);
c1.innerText = reply
c2.innerText = ""
c1.setAttribute("id", "h11")
userInput.value = ""
var objDiv = document.getElementById("message");
objDiv.scrollTop = objDiv.scrollHeight;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("errorThrown");
}
})
}
}
</script>
</body>
</html>