SkillForge45 commited on
Commit
592da9c
verified
1 Parent(s): 23e05b4

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +233 -0
templates/index.html ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Hybrid Chatbot</title>
7
+ <style>
8
+ body {
9
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
10
+ max-width: 800px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background-color: #f5f5f5;
14
+ }
15
+ .chat-container {
16
+ background: white;
17
+ border-radius: 10px;
18
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
19
+ height: 500px;
20
+ overflow-y: auto;
21
+ padding: 20px;
22
+ margin-bottom: 20px;
23
+ }
24
+ .message {
25
+ margin-bottom: 15px;
26
+ padding: 10px 15px;
27
+ border-radius: 18px;
28
+ max-width: 70%;
29
+ }
30
+ .user-message {
31
+ background-color: #e3f2fd;
32
+ margin-left: auto;
33
+ border-bottom-right-radius: 5px;
34
+ }
35
+ .bot-message {
36
+ background-color: #f1f1f1;
37
+ margin-right: auto;
38
+ border-bottom-left-radius: 5px;
39
+ }
40
+ .input-area {
41
+ display: flex;
42
+ gap: 10px;
43
+ }
44
+ input {
45
+ flex-grow: 1;
46
+ padding: 10px;
47
+ border: 1px solid #ddd;
48
+ border-radius: 20px;
49
+ outline: none;
50
+ }
51
+ button {
52
+ background-color: #4285f4;
53
+ color: white;
54
+ border: none;
55
+ border-radius: 20px;
56
+ padding: 10px 20px;
57
+ cursor: pointer;
58
+ }
59
+ button:hover {
60
+ background-color: #3367d6;
61
+ }
62
+ .controls {
63
+ display: flex;
64
+ gap: 10px;
65
+ margin-top: 10px;
66
+ }
67
+ .tab {
68
+ display: none;
69
+ }
70
+ .tab.active {
71
+ display: block;
72
+ }
73
+ .tab-buttons {
74
+ display: flex;
75
+ margin-bottom: 10px;
76
+ }
77
+ .tab-button {
78
+ padding: 10px 15px;
79
+ background: #ddd;
80
+ border: none;
81
+ cursor: pointer;
82
+ }
83
+ .tab-button.active {
84
+ background: #4285f4;
85
+ color: white;
86
+ }
87
+ </style>
88
+ </head>
89
+ <body>
90
+ <h1>Hybrid Chatbot</h1>
91
+
92
+ <div class="tab-buttons">
93
+ <button class="tab-button active" onclick="openTab('chat')">Chat</button>
94
+ <button class="tab-button" onclick="openTab('teach')">Teach Bot</button>
95
+ <button class="tab-button" onclick="openTab('search')">Web Search</button>
96
+ </div>
97
+
98
+ <div id="chat" class="tab active">
99
+ <div class="chat-container" id="chat-box"></div>
100
+ <div class="input-area">
101
+ <input type="text" id="user-input" placeholder="Type your message...">
102
+ <button onclick="sendMessage()">Send</button>
103
+ </div>
104
+ <div class="controls">
105
+ <button onclick="startVoiceInput()">馃帳 Voice Input</button>
106
+ </div>
107
+ </div>
108
+
109
+ <div id="teach" class="tab">
110
+ <h2>Teach the Bot</h2>
111
+ <div>
112
+ <input type="text" id="teach-question" placeholder="Enter question" style="width: 100%; margin-bottom: 10px;">
113
+ <textarea id="teach-answer" placeholder="Enter answer" style="width: 100%; height: 100px; margin-bottom: 10px;"></textarea>
114
+ <button onclick="teachBot()">Teach</button>
115
+ </div>
116
+ </div>
117
+
118
+ <div id="search" class="tab">
119
+ <h2>Web Search</h2>
120
+ <div>
121
+ <input type="text" id="search-query" placeholder="Enter search query" style="width: 100%; margin-bottom: 10px;">
122
+ <button onclick="performSearch()">Search</button>
123
+ <div id="search-results" style="margin-top: 20px;"></div>
124
+ </div>
125
+ </div>
126
+
127
+ <script>
128
+ const chatBox = document.getElementById('chat-box');
129
+ const userInput = document.getElementById('user-input');
130
+
131
+ function addMessage(text, isUser) {
132
+ const messageDiv = document.createElement('div');
133
+ messageDiv.classList.add('message');
134
+ messageDiv.classList.add(isUser ? 'user-message' : 'bot-message');
135
+ messageDiv.textContent = text;
136
+ chatBox.appendChild(messageDiv);
137
+ chatBox.scrollTop = chatBox.scrollHeight;
138
+ }
139
+
140
+ function sendMessage() {
141
+ const message = userInput.value.trim();
142
+ if (message) {
143
+ addMessage(message, true);
144
+ userInput.value = '';
145
+
146
+ fetch('/chat', {
147
+ method: 'POST',
148
+ headers: {
149
+ 'Content-Type': 'application/json',
150
+ },
151
+ body: JSON.stringify({message: message}),
152
+ })
153
+ .then(response => response.json())
154
+ .then(data => {
155
+ addMessage(data.response, false);
156
+ });
157
+ }
158
+ }
159
+
160
+ function startVoiceInput() {
161
+ alert("Voice input would be implemented here with Web Speech API");
162
+ // Actual implementation would require Web Speech API integration
163
+ }
164
+
165
+ function teachBot() {
166
+ const question = document.getElementById('teach-question').value.trim();
167
+ const answer = document.getElementById('teach-answer').value.trim();
168
+
169
+ if (question && answer) {
170
+ fetch('/teach', {
171
+ method: 'POST',
172
+ headers: {
173
+ 'Content-Type': 'application/json',
174
+ },
175
+ body: JSON.stringify({question: question, answer: answer}),
176
+ })
177
+ .then(response => response.json())
178
+ .then(data => {
179
+ if (data.success) {
180
+ alert("Bot has learned the new response!");
181
+ document.getElementById('teach-question').value = '';
182
+ document.getElementById('teach-answer').value = '';
183
+ }
184
+ });
185
+ } else {
186
+ alert("Please enter both question and answer");
187
+ }
188
+ }
189
+
190
+ function performSearch() {
191
+ const query = document.getElementById('search-query').value.trim();
192
+ if (query) {
193
+ fetch('/chat', {
194
+ method: 'POST',
195
+ headers: {
196
+ 'Content-Type': 'application/json',
197
+ },
198
+ body: JSON.stringify({message: `search the web for ${query}`}),
199
+ })
200
+ .then(response => response.json())
201
+ .then(data => {
202
+ document.getElementById('search-results').innerHTML =
203
+ `<h3>Search Results for "${query}":</h3><p>${data.response.replace(/\n/g, '<br>')}</p>`;
204
+ });
205
+ }
206
+ }
207
+
208
+ function openTab(tabName) {
209
+ const tabs = document.getElementsByClassName('tab');
210
+ for (let tab of tabs) {
211
+ tab.classList.remove('active');
212
+ }
213
+
214
+ const tabButtons = document.getElementsByClassName('tab-button');
215
+ for (let button of tabButtons) {
216
+ button.classList.remove('active');
217
+ }
218
+
219
+ document.getElementById(tabName).classList.add('active');
220
+ event.currentTarget.classList.add('active');
221
+ }
222
+
223
+ userInput.addEventListener('keypress', function(e) {
224
+ if (e.key === 'Enter') {
225
+ sendMessage();
226
+ }
227
+ });
228
+
229
+ // Initial greeting
230
+ addMessage("Hello! How can I help you today?", false);
231
+ </script>
232
+ </body>
233
+ </html>