-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchatbot.html
More file actions
171 lines (149 loc) · 5.17 KB
/
chatbot.html
File metadata and controls
171 lines (149 loc) · 5.17 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LeetCode Analytics Assistant</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.chat-container {
background-color: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.input-container {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
input[type="text"] {
flex-grow: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
.response-container {
margin-top: 20px;
}
.response-text {
margin-bottom: 20px;
padding: 10px;
background-color: #f8f9fa;
border-radius: 5px;
}
.chart-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
}
.chart-item {
background: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.chart-title {
font-weight: bold;
margin-bottom: 10px;
color: #333;
}
.suggestions {
margin-top: 20px;
padding: 10px;
background-color: #e9ecef;
border-radius: 5px;
}
.suggestions p {
margin: 5px 0;
color: #666;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.error-message {
color: #dc3545;
padding: 10px;
background-color: #f8d7da;
border-radius: 5px;
text-align: center;
}
</style>
</head>
<body>
<h1>LeetCode Analytics Assistant</h1>
<div class="chat-container">
<div class="input-container">
<input type="text" id="queryInput" placeholder="Ask about student performance...">
<button onclick="sendQuery()">Analyze</button>
</div>
<div class="suggestions">
<p>Example queries:</p>
<p>- "Who has solved the most problems?"</p>
<p>- "Show me the difficulty breakdown for all students"</p>
<p>- "How active was Alice last month?"</p>
<p>- "Compare student rankings"</p>
<p>- "Show me acceptance rates"</p>
</div>
<div class="response-container">
<div class="response-text" id="responseText"></div>
<div class="chart-grid" id="chartGrid"></div>
</div>
</div>
<script>
function sendQuery() {
const query = document.getElementById('queryInput').value;
if (!query) return;
document.getElementById('responseText').textContent = 'Analyzing...';
document.getElementById('chartGrid').innerHTML = ''; // Clear previous charts
fetch('/query', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: query }),
})
.then(response => response.text()) // Expecting HTML as response
.then(html => {
// Clean up the received HTML by removing unwanted newlines and extra spaces
let cleanedHtml = html.replace(/\n+/g, ' ').trim(); // Replace multiple newlines with a single one
// Insert the cleaned HTML just below the chat input box
const responseContainer = document.createElement('div');
responseContainer.innerHTML = cleanedHtml; // Use innerHTML to insert the cleaned content
document.querySelector('.response-container').appendChild(responseContainer);
})
.catch(error => {
console.error('Error:', error);
document.getElementById('responseText').textContent = 'An error occurred while processing your request. Please try again.';
document.getElementById('chartGrid').innerHTML = '<div class="error-message">Failed to generate visualizations</div>';
});
document.getElementById('queryInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendQuery();
}
});
}
</script>
</body>
</html>