Utkarsh Verma commited on
Commit
c13e300
·
1 Parent(s): dd124d4

Changes in UI

Browse files
Files changed (1) hide show
  1. templates/index.html +162 -148
templates/index.html CHANGED
@@ -1,157 +1,171 @@
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>AI Chatbot</title>
7
- <style>
8
- body {
9
- background-color: #121212;
10
- color: #f1f1f1;
11
- font-family: 'Segoe UI', sans-serif;
12
- display: flex;
13
- flex-direction: column;
14
- align-items: center;
15
- padding: 20px;
16
- }
17
-
18
- #chat-box {
19
- border: 1px solid #444;
20
- background-color: #1e1e1e;
21
- width: 80%;
22
- max-width: 800px;
23
- height: 400px;
24
- overflow-y: auto;
25
- padding: 10px;
26
- border-radius: 10px;
27
- margin-bottom: 10px;
28
- }
29
-
30
- #user-input {
31
- width: 60%;
32
- padding: 10px;
33
- border-radius: 5px;
34
- border: none;
35
- margin-right: 10px;
36
- }
37
-
38
- #send-btn, #mic-btn {
39
- padding: 10px 15px;
40
- border: none;
41
- background-color: #1db954;
42
- color: white;
43
- cursor: pointer;
44
- border-radius: 5px;
45
- margin-right: 5px;
46
- }
47
-
48
- #send-btn:hover, #mic-btn:hover {
49
- background-color: #1ed760;
50
- }
51
-
52
- .typing {
53
- font-style: italic;
54
- opacity: 0.7;
55
- }
56
-
57
- .chat-wrapper {
58
- display: flex;
59
- align-items: center;
60
- width: 80%;
61
- max-width: 800px;
62
- }
63
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  </head>
65
  <body>
66
- <h1>🧠 AI Chatbot</h1>
67
- <div id="chat-box"></div>
68
-
69
- <div class="chat-wrapper">
70
- <input type="text" id="user-input" placeholder="Type a message..." />
71
- <button id="send-btn" onclick="sendMessage()">Send</button>
72
- <button id="mic-btn" onclick="startListening()">🎤</button>
73
- </div>
74
-
75
- <script>
76
- // Load saved chat history
77
- window.onload = function () {
78
- const history = localStorage.getItem("chatHistory");
79
- if (history) {
80
- document.getElementById("chat-box").innerHTML = history;
81
- }
82
- };
83
-
84
- // Save chat history
85
- function saveHistory() {
86
- const chatBox = document.getElementById("chat-box");
87
- localStorage.setItem("chatHistory", chatBox.innerHTML);
88
- }
89
-
90
- function updateChatBox(role, message) {
91
- let chatBox = document.getElementById("chat-box");
92
- const tag = role === "user" ? "You" : "Bot";
93
- chatBox.innerHTML += `<p><b>${tag}:</b> ${message}</p>`;
94
- chatBox.scrollTop = chatBox.scrollHeight;
95
- saveHistory();
96
- }
97
-
98
- async function sendMessage() {
99
- let userInput = document.getElementById("user-input").value.trim();
100
- if (!userInput) return;
101
-
102
- updateChatBox("user", userInput);
103
-
104
- document.getElementById("user-input").value = "";
105
-
106
- const chatBox = document.getElementById("chat-box");
107
- const typingIndicator = document.createElement("p");
108
- typingIndicator.className = "typing";
109
- typingIndicator.innerText = "Bot is typing...";
110
- chatBox.appendChild(typingIndicator);
111
- chatBox.scrollTop = chatBox.scrollHeight;
112
-
113
- try {
114
- const response = await fetch("/chat", {
115
- method: "POST",
116
- headers: { "Content-Type": "application/json" },
117
- body: JSON.stringify({ message: userInput })
118
- });
119
-
120
- const data = await response.json();
121
- chatBox.removeChild(typingIndicator);
122
- updateChatBox("bot", data.reply || "Error in response");
123
- } catch (err) {
124
- chatBox.removeChild(typingIndicator);
125
- updateChatBox("bot", "Something went wrong.");
126
- }
127
- }
128
-
129
- // Send with Enter key
130
- document.getElementById("user-input").addEventListener("keydown", function (event) {
131
- if (event.key === "Enter") {
132
- event.preventDefault();
133
- sendMessage();
134
- }
135
  });
136
 
137
- // Speech to text
138
- function startListening() {
139
- const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
140
- recognition.lang = 'en-US';
141
- recognition.interimResults = false;
142
-
143
- recognition.onresult = function (event) {
144
- const transcript = event.results[0][0].transcript;
145
- document.getElementById("user-input").value = transcript;
146
- sendMessage();
147
- };
148
-
149
- recognition.onerror = function () {
150
- updateChatBox("bot", "Speech recognition failed.");
151
- };
152
-
153
- recognition.start();
154
- }
155
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  </body>
157
  </html>
 
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>AI Chatbot</title>
7
+ <style>
8
+ html, body {
9
+ margin: 0;
10
+ padding: 0;
11
+ height: 100%;
12
+ width: 100%;
13
+ font-family: 'Segoe UI', sans-serif;
14
+ background-color: #121212;
15
+ color: #f1f1f1;
16
+ }
17
+
18
+ body {
19
+ display: flex;
20
+ flex-direction: column;
21
+ }
22
+
23
+ h1 {
24
+ text-align: center;
25
+ margin: 10px 0;
26
+ }
27
+
28
+ #chat-box {
29
+ flex: 1;
30
+ border-top: 1px solid #444;
31
+ border-bottom: 1px solid #444;
32
+ background-color: #1e1e1e;
33
+ overflow-y: auto;
34
+ padding: 20px;
35
+ border-radius: 0;
36
+ }
37
+
38
+ .chat-wrapper {
39
+ display: flex;
40
+ justify-content: center;
41
+ align-items: center;
42
+ padding: 10px;
43
+ background-color: #1a1a1a;
44
+ }
45
+
46
+ #user-input {
47
+ flex: 1;
48
+ padding: 12px;
49
+ font-size: 16px;
50
+ border-radius: 6px;
51
+ border: none;
52
+ margin-right: 10px;
53
+ background-color: #2a2a2a;
54
+ color: #fff;
55
+ }
56
+
57
+ #send-btn, #mic-btn {
58
+ padding: 10px 15px;
59
+ border: none;
60
+ background-color: #1db954;
61
+ color: white;
62
+ cursor: pointer;
63
+ border-radius: 6px;
64
+ margin-left: 5px;
65
+ }
66
+
67
+ #send-btn:hover, #mic-btn:hover {
68
+ background-color: #1ed760;
69
+ }
70
+
71
+ .typing {
72
+ font-style: italic;
73
+ opacity: 0.7;
74
+ }
75
+
76
+ p {
77
+ margin: 8px 0;
78
+ line-height: 1.5;
79
+ }
80
+ </style>
81
  </head>
82
  <body>
83
+ <h1>🧠 AI Chatbot</h1>
84
+
85
+ <div id="chat-box"></div>
86
+
87
+ <div class="chat-wrapper">
88
+ <input type="text" id="user-input" placeholder="Type a message..." />
89
+ <button id="send-btn" onclick="sendMessage()">Send</button>
90
+ <button id="mic-btn" onclick="startListening()">🎤</button>
91
+ </div>
92
+
93
+ <script>
94
+ // Load saved chat history
95
+ window.onload = function () {
96
+ const history = localStorage.getItem("chatHistory");
97
+ if (history) {
98
+ document.getElementById("chat-box").innerHTML = history;
99
+ }
100
+ };
101
+
102
+ function saveHistory() {
103
+ const chatBox = document.getElementById("chat-box");
104
+ localStorage.setItem("chatHistory", chatBox.innerHTML);
105
+ }
106
+
107
+ function updateChatBox(role, message) {
108
+ let chatBox = document.getElementById("chat-box");
109
+ const tag = role === "user" ? "You" : "Bot";
110
+ chatBox.innerHTML += `<p><b>${tag}:</b> ${message}</p>`;
111
+ chatBox.scrollTop = chatBox.scrollHeight;
112
+ saveHistory();
113
+ }
114
+
115
+ async function sendMessage() {
116
+ let userInput = document.getElementById("user-input").value.trim();
117
+ if (!userInput) return;
118
+
119
+ updateChatBox("user", userInput);
120
+ document.getElementById("user-input").value = "";
121
+
122
+ const chatBox = document.getElementById("chat-box");
123
+ const typingIndicator = document.createElement("p");
124
+ typingIndicator.className = "typing";
125
+ typingIndicator.innerText = "Bot is typing...";
126
+ chatBox.appendChild(typingIndicator);
127
+ chatBox.scrollTop = chatBox.scrollHeight;
128
+
129
+ try {
130
+ const response = await fetch("/chat", {
131
+ method: "POST",
132
+ headers: { "Content-Type": "application/json" },
133
+ body: JSON.stringify({ message: userInput })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  });
135
 
136
+ const data = await response.json();
137
+ chatBox.removeChild(typingIndicator);
138
+ updateChatBox("bot", data.reply || "Error in response");
139
+ } catch (err) {
140
+ chatBox.removeChild(typingIndicator);
141
+ updateChatBox("bot", "Something went wrong.");
142
+ }
143
+ }
144
+
145
+ document.getElementById("user-input").addEventListener("keydown", function (event) {
146
+ if (event.key === "Enter") {
147
+ event.preventDefault();
148
+ sendMessage();
149
+ }
150
+ });
151
+
152
+ function startListening() {
153
+ const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
154
+ recognition.lang = 'en-US';
155
+ recognition.interimResults = false;
156
+
157
+ recognition.onresult = function (event) {
158
+ const transcript = event.results[0][0].transcript;
159
+ document.getElementById("user-input").value = transcript;
160
+ sendMessage();
161
+ };
162
+
163
+ recognition.onerror = function () {
164
+ updateChatBox("bot", "Speech recognition failed.");
165
+ };
166
+
167
+ recognition.start();
168
+ }
169
+ </script>
170
  </body>
171
  </html>