-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
126 lines (92 loc) · 2.71 KB
/
index.html
File metadata and controls
126 lines (92 loc) · 2.71 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
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
#chatbox {
border: 3px solid #ccc;
padding: 60px;
width: 900px;
background-color: #fff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
#chatlogs {
height: 200px;
overflow-y: auto;
margin-bottom: 20px;
border: 1px solid #ccc;
padding: 10px;
}
#chatlogs div {
margin-bottom: 10px;
}
#query {
width: 100%;
padding: 5px;
}
</style>
</head>
<body>
<h2>Content Master PRO</h2>
<div id="chatbox">
<div id="chatlogs">
<!-- Chat logs will be inserted here -->
</div>
<form id="chatForm">
<input type="text" id="query" name="query" placeholder="Type your message here...">
<input type="submit" value="Submit">
</form>
</div>
<div id="output"></div>
<!-- The output of the chat will be displayed here -->
<script>
document.getElementById('chatForm').addEventListener('submit', function (event) {
event.preventDefault();
var query = document.getElementById('query').value;
var chatlogs = document.getElementById('chatlogs');
// Append user's query to chatlogs
var userDiv = document.createElement('div');
userDiv.innerHTML = `<strong>You:</strong> ${query}`;
chatlogs.appendChild(userDiv);
fetch('/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: query,
}),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
// Check if the data has a 'response' key
if (data.hasOwnProperty('response')) {
// Append bot's response to chatlogs
var botDiv = document.createElement('div');
botDiv.innerHTML = `<strong>Bot:</strong> ${data.response}`;
chatlogs.appendChild(botDiv); // Display the output of the chat in the output div
} else {
console.error('The server\'s response doesn\'t have a \'response\' key');
}
})
.catch((error) => {
console.error('Error:', error);
});
// Clear the query input field
document.getElementById('query').value = '';
});
</script>
</body>
</html>