luizdal18 commited on
Commit
694023c
·
verified ·
1 Parent(s): 641538f

reaf all usert input and enhance add llm to all this as a bot helper a new way to interact with innterface

Browse files
Files changed (2) hide show
  1. components/chatbot.js +319 -0
  2. index.html +3 -2
components/chatbot.js ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class ChatBot extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ :host {
7
+ position: fixed;
8
+ bottom: 20px;
9
+ right: 20px;
10
+ z-index: 1000;
11
+ font-family: 'Inter', sans-serif;
12
+ }
13
+
14
+ .chat-container {
15
+ position: relative;
16
+ }
17
+
18
+ .chat-toggle {
19
+ width: 60px;
20
+ height: 60px;
21
+ border-radius: 50%;
22
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
23
+ color: white;
24
+ border: none;
25
+ cursor: pointer;
26
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
27
+ display: flex;
28
+ align-items: center;
29
+ justify-content: center;
30
+ transition: all 0.3s ease;
31
+ }
32
+
33
+ .chat-toggle:hover {
34
+ transform: scale(1.1);
35
+ box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
36
+ }
37
+
38
+ .chat-window {
39
+ position: absolute;
40
+ bottom: 70px;
41
+ right: 0;
42
+ width: 350px;
43
+ height: 450px;
44
+ background: white;
45
+ border-radius: 16px;
46
+ box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
47
+ display: flex;
48
+ flex-direction: column;
49
+ opacity: 0;
50
+ visibility: hidden;
51
+ transform: translateY(20px);
52
+ transition: all 0.3s ease;
53
+ }
54
+
55
+ .chat-window.open {
56
+ opacity: 1;
57
+ visibility: visible;
58
+ transform: translateY(0);
59
+ }
60
+
61
+ .chat-header {
62
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
63
+ color: white;
64
+ padding: 16px;
65
+ border-radius: 16px 16px 0 0;
66
+ display: flex;
67
+ align-items: center;
68
+ justify-content: space-between;
69
+ }
70
+
71
+ .chat-title {
72
+ font-weight: 600;
73
+ font-size: 16px;
74
+ }
75
+
76
+ .close-chat {
77
+ background: none;
78
+ border: none;
79
+ color: white;
80
+ cursor: pointer;
81
+ font-size: 20px;
82
+ }
83
+
84
+ .chat-messages {
85
+ flex: 1;
86
+ padding: 16px;
87
+ overflow-y: auto;
88
+ display: flex;
89
+ flex-direction: column;
90
+ gap: 12px;
91
+ }
92
+
93
+ .message {
94
+ max-width: 80%;
95
+ padding: 12px 16px;
96
+ border-radius: 18px;
97
+ font-size: 14px;
98
+ line-height: 1.4;
99
+ }
100
+
101
+ .user-message {
102
+ align-self: flex-end;
103
+ background: #667eea;
104
+ color: white;
105
+ border-bottom-right-radius: 4px;
106
+ }
107
+
108
+ .bot-message {
109
+ align-self: flex-start;
110
+ background: #f1f5f9;
111
+ color: #1e293b;
112
+ border-bottom-left-radius: 4px;
113
+ }
114
+
115
+ .chat-input {
116
+ display: flex;
117
+ padding: 16px;
118
+ border-top: 1px solid #e2e8f0;
119
+ gap: 8px;
120
+ }
121
+
122
+ .message-input {
123
+ flex: 1;
124
+ padding: 12px 16px;
125
+ border: 1px solid #cbd5e1;
126
+ border-radius: 24px;
127
+ font-size: 14px;
128
+ outline: none;
129
+ transition: border-color 0.2s;
130
+ }
131
+
132
+ .message-input:focus {
133
+ border-color: #667eea;
134
+ }
135
+
136
+ .send-button {
137
+ width: 40px;
138
+ height: 40px;
139
+ border-radius: 50%;
140
+ background: #667eea;
141
+ color: white;
142
+ border: none;
143
+ cursor: pointer;
144
+ display: flex;
145
+ align-items: center;
146
+ justify-content: center;
147
+ transition: background 0.2s;
148
+ }
149
+
150
+ .send-button:hover {
151
+ background: #5a6fd8;
152
+ }
153
+
154
+ .typing-indicator {
155
+ align-self: flex-start;
156
+ background: #f1f5f9;
157
+ padding: 12px 16px;
158
+ border-radius: 18px;
159
+ display: none;
160
+ }
161
+
162
+ .typing-dots {
163
+ display: flex;
164
+ gap: 4px;
165
+ }
166
+
167
+ .dot {
168
+ width: 8px;
169
+ height: 8px;
170
+ background: #94a3b8;
171
+ border-radius: 50%;
172
+ animation: bounce 1.5s infinite;
173
+ }
174
+
175
+ .dot:nth-child(2) {
176
+ animation-delay: 0.2s;
177
+ }
178
+
179
+ .dot:nth-child(3) {
180
+ animation-delay: 0.4s;
181
+ }
182
+
183
+ @keyframes bounce {
184
+ 0%, 100% { transform: translateY(0); }
185
+ 50% { transform: translateY(-5px); }
186
+ }
187
+ </style>
188
+
189
+ <div class="chat-container">
190
+ <button class="chat-toggle" id="chatToggle">
191
+ <i data-feather="message-circle"></i>
192
+ </button>
193
+
194
+ <div class="chat-window" id="chatWindow">
195
+ <div class="chat-header">
196
+ <div class="chat-title">SoccerViz Assistant</div>
197
+ <button class="close-chat" id="closeChat">×</button>
198
+ </div>
199
+
200
+ <div class="chat-messages" id="chatMessages">
201
+ <div class="message bot-message">
202
+ Hello! I'm your SoccerViz assistant. How can I help you with football analytics today?
203
+ </div>
204
+ </div>
205
+
206
+ <div class="typing-indicator" id="typingIndicator">
207
+ <div class="typing-dots">
208
+ <div class="dot"></div>
209
+ <div class="dot"></div>
210
+ <div class="dot"></div>
211
+ </div>
212
+ </div>
213
+
214
+ <div class="chat-input">
215
+ <input type="text" class="message-input" id="messageInput" placeholder="Ask about players, teams, or stats...">
216
+ <button class="send-button" id="sendButton">
217
+ <i data-feather="send"></i>
218
+ </button>
219
+ </div>
220
+ </div>
221
+ </div>
222
+ `;
223
+
224
+ this.init();
225
+ }
226
+
227
+ init() {
228
+ // Load Feather icons
229
+ if (typeof feather !== 'undefined') {
230
+ setTimeout(() => {
231
+ feather.replace();
232
+ }, 100);
233
+ }
234
+
235
+ // Get elements
236
+ this.chatToggle = this.shadowRoot.getElementById('chatToggle');
237
+ this.chatWindow = this.shadowRoot.getElementById('chatWindow');
238
+ this.closeChat = this.shadowRoot.getElementById('closeChat');
239
+ this.chatMessages = this.shadowRoot.getElementById('chatMessages');
240
+ this.messageInput = this.shadowRoot.getElementById('messageInput');
241
+ this.sendButton = this.shadowRoot.getElementById('sendButton');
242
+ this.typingIndicator = this.shadowRoot.getElementById('typingIndicator');
243
+
244
+ // Event listeners
245
+ this.chatToggle.addEventListener('click', () => this.toggleChat());
246
+ this.closeChat.addEventListener('click', () => this.closeChatWindow());
247
+ this.sendButton.addEventListener('click', () => this.sendMessage());
248
+ this.messageInput.addEventListener('keypress', (e) => {
249
+ if (e.key === 'Enter') {
250
+ this.sendMessage();
251
+ }
252
+ });
253
+ }
254
+
255
+ toggleChat() {
256
+ this.chatWindow.classList.toggle('open');
257
+ }
258
+
259
+ closeChatWindow() {
260
+ this.chatWindow.classList.remove('open');
261
+ }
262
+
263
+ async sendMessage() {
264
+ const message = this.messageInput.value.trim();
265
+ if (!message) return;
266
+
267
+ // Add user message
268
+ this.addMessage(message, 'user');
269
+ this.messageInput.value = '';
270
+
271
+ // Show typing indicator
272
+ this.typingIndicator.style.display = 'block';
273
+ this.chatMessages.scrollTop = this.chatMessages.scrollHeight;
274
+
275
+ try {
276
+ // Simulate API call to LLM
277
+ const response = await this.getLLMResponse(message);
278
+ this.typingIndicator.style.display = 'none';
279
+ this.addMessage(response, 'bot');
280
+ } catch (error) {
281
+ this.typingIndicator.style.display = 'none';
282
+ this.addMessage("Sorry, I encountered an error. Please try again.", 'bot');
283
+ }
284
+ }
285
+
286
+ async getLLMResponse(message) {
287
+ // Simulate API delay
288
+ await new Promise(resolve => setTimeout(resolve, 1000));
289
+
290
+ // Simple response logic - in a real app, this would call an actual LLM API
291
+ const responses = {
292
+ "hello": "Hi there! I'm here to help you with football analytics. What would you like to know?",
293
+ "help": "I can help you with player stats, team comparisons, match insights, and more. Try asking questions like 'Who is the top scorer?' or 'Compare Messi and Ronaldo'.",
294
+ "player": "I can show you detailed stats for any player. Which player would you like to know more about?",
295
+ "team": "I have data on teams from major leagues. Which team are you interested in?",
296
+ "stat": "I can provide various statistics including goals, assists, passing accuracy, defensive actions, and more.",
297
+ "default": "I understand you're asking about football analytics. Could you be more specific? I can help with player stats, team performance, or match insights."
298
+ };
299
+
300
+ const lowerMessage = message.toLowerCase();
301
+ if (lowerMessage.includes("hello") || lowerMessage.includes("hi")) return responses.hello;
302
+ if (lowerMessage.includes("help")) return responses.help;
303
+ if (lowerMessage.includes("player")) return responses.player;
304
+ if (lowerMessage.includes("team")) return responses.team;
305
+ if (lowerMessage.includes("stat")) return responses.stat;
306
+
307
+ return responses.default;
308
+ }
309
+
310
+ addMessage(text, sender) {
311
+ const messageDiv = document.createElement('div');
312
+ messageDiv.className = `message ${sender}-message`;
313
+ messageDiv.textContent = text;
314
+ this.chatMessages.appendChild(messageDiv);
315
+ this.chatMessages.scrollTop = this.chatMessages.scrollHeight;
316
+ }
317
+ }
318
+
319
+ customElements.define('chat-bot', ChatBot);
index.html CHANGED
@@ -94,9 +94,9 @@
94
  </main>
95
 
96
  <custom-footer></custom-footer>
97
-
98
  <script src="components/navbar.js"></script>
99
  <script src="components/footer.js"></script>
 
100
  <script src="script.js"></script>
101
  <script>
102
  feather.replace();
@@ -113,6 +113,7 @@
113
  backgroundColor: 0xf1f5f9
114
  });
115
  </script>
 
116
  <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
117
  </body>
118
- </html>
 
94
  </main>
95
 
96
  <custom-footer></custom-footer>
 
97
  <script src="components/navbar.js"></script>
98
  <script src="components/footer.js"></script>
99
+ <script src="components/chatbot.js"></script>
100
  <script src="script.js"></script>
101
  <script>
102
  feather.replace();
 
113
  backgroundColor: 0xf1f5f9
114
  });
115
  </script>
116
+ <chat-bot></chat-bot>
117
  <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
118
  </body>
119
+ </html>