Shresthh03 commited on
Commit
c097254
·
verified ·
1 Parent(s): d89e7d9

Update it all and make it functional.

Browse files
Files changed (1) hide show
  1. index.html +217 -195
index.html CHANGED
@@ -1,211 +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>🌸 Serenity - Emotional Support Chatbot</title>
7
-
8
- <style>
9
- body {
10
- font-family: "Poppins", sans-serif;
11
- background: linear-gradient(135deg, #d7efff, #f9e7fe);
12
- display: flex;
13
- flex-direction: column;
14
- align-items: center;
15
- justify-content: center;
16
- height: 100vh;
17
- margin: 0;
18
- transition: background 1s ease-in-out;
19
- animation: gradientShift 12s infinite alternate;
20
- }
21
-
22
- @keyframes gradientShift {
23
- 0% { background: linear-gradient(135deg, #d7efff, #f9e7fe); }
24
- 50% { background: linear-gradient(135deg, #e3ffe7, #d9e7ff); }
25
- 100% { background: linear-gradient(135deg, #f9e7fe, #ffe8d6); }
26
- }
27
-
28
- h1 {
29
- text-align: center;
30
- font-size: 2rem;
31
- color: #333;
32
- margin-bottom: 10px;
33
- }
34
-
35
- .chat-container {
36
- width: 90%;
37
- max-width: 480px;
38
- background: white;
39
- box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
40
- border-radius: 16px;
41
- overflow: hidden;
42
- display: flex;
43
- flex-direction: column;
44
- height: 70vh;
45
- position: relative;
46
- }
47
-
48
- .avatar {
49
- width: 70px;
50
- height: 70px;
51
- border-radius: 50%;
52
- background: radial-gradient(circle at 30% 30%, #a8cfff, #6a7bff);
53
- margin: 15px auto;
54
- animation: breathe 5s ease-in-out infinite;
55
- }
56
-
57
- @keyframes breathe {
58
- 0%, 100% { transform: scale(1); }
59
- 50% { transform: scale(1.05); }
60
- }
61
-
62
- #chat-box {
63
- flex-grow: 1;
64
- padding: 15px;
65
- overflow-y: auto;
66
- display: flex;
67
- flex-direction: column;
68
- }
69
-
70
- .user-msg, .bot-msg {
71
- margin: 8px 0;
72
- padding: 12px 14px;
73
- border-radius: 16px;
74
- max-width: 80%;
75
- line-height: 1.4;
76
- word-wrap: break-word;
77
- font-size: 0.95rem;
78
- }
79
-
80
- .user-msg {
81
- background: #dceefb;
82
- align-self: flex-end;
83
- border-bottom-right-radius: 2px;
84
- }
85
-
86
- .bot-msg {
87
- background: #f1f0ff;
88
- align-self: flex-start;
89
- border-bottom-left-radius: 2px;
90
- }
91
-
92
- .controls {
93
- display: flex;
94
- padding: 10px;
95
- background: #fff;
96
- border-top: 1px solid #eee;
97
- align-items: center;
98
- }
99
-
100
- input {
101
- flex-grow: 1;
102
- padding: 10px;
103
- border: none;
104
- outline: none;
105
- border-radius: 10px;
106
- background: #f5f5f5;
107
- margin-right: 10px;
108
- font-size: 0.95rem;
109
- }
110
-
111
- button {
112
- background: #8b6ef7;
113
- color: white;
114
- border: none;
115
- padding: 10px 16px;
116
- border-radius: 10px;
117
- cursor: pointer;
118
- transition: 0.3s;
119
- }
120
-
121
- button:hover {
122
- background: #755eea;
123
- }
124
-
125
- .typing {
126
- font-size: 0.8rem;
127
- color: #777;
128
- padding: 6px 15px;
129
- }
130
-
131
- select {
132
- border: none;
133
- background: #f5f5f5;
134
- padding: 6px 8px;
135
- border-radius: 8px;
136
- font-size: 0.9rem;
137
- margin-right: 8px;
138
- }
139
- </style>
140
  </head>
141
-
142
- <body>
143
- <h1>🌸 Serenity - Your Calm Companion</h1>
144
-
145
  <div class="chat-container">
146
  <div class="avatar" id="avatar"></div>
 
147
 
148
- <div id="chat-box"></div>
149
- <div id="typing" class="typing" style="display: none;">Serenity is thinking...</div>
150
-
151
- <div class="controls">
152
  <select id="personality">
153
- <option value="calm">🌿 Calm</option>
154
- <option value="gentle">🌸 Gentle</option>
155
- <option value="deep">🌊 Deep</option>
156
- <option value="friendly">☀️ Friendly</option>
157
- <option value="soothing">💫 Soothing</option>
158
  </select>
159
-
160
- <input type="text" id="user-input" placeholder="Type something..." />
161
- <button onclick="sendMessage()">Send</button>
162
  </div>
163
- </div>
164
-
165
- <script>
166
- const chatBox = document.getElementById("chat-box");
167
- const typingIndicator = document.getElementById("typing");
168
- const personalitySelector = document.getElementById("personality");
169
-
170
- function appendMessage(sender, text) {
171
- const msg = document.createElement("div");
172
- msg.className = sender === "user" ? "user-msg" : "bot-msg";
173
- msg.textContent = text;
174
- chatBox.appendChild(msg);
175
- chatBox.scrollTop = chatBox.scrollHeight;
176
- }
177
-
178
- async function sendMessage() {
179
- const input = document.getElementById("user-input");
180
- const message = input.value.trim();
181
- const personality = personalitySelector.value;
182
-
183
- if (!message) return;
184
-
185
- appendMessage("user", message);
186
- input.value = "";
187
- typingIndicator.style.display = "block";
188
 
189
- try {
190
- const res = await fetch("/chat", {
191
- method: "POST",
192
- headers: { "Content-Type": "application/json" },
193
- body: JSON.stringify({ message, personality }),
194
- });
195
 
196
- const data = await res.json();
197
- typingIndicator.style.display = "none";
198
-
199
- appendMessage("bot", data.reply || "Hmm... I'm not sure what to say just yet 💭");
200
- } catch (err) {
201
- typingIndicator.style.display = "none";
202
- appendMessage("bot", "⚠️ Oops, something went wrong. Please try again later.");
203
- }
204
- }
205
 
206
- document.getElementById("user-input").addEventListener("keydown", (e) => {
207
- if (e.key === "Enter") sendMessage();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  });
209
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  </body>
211
  </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>🌸 Serenity Emotional Support Chatbot</title>
7
+ <style>
8
+ body {
9
+ font-family: "Poppins", sans-serif;
10
+ background: linear-gradient(120deg, #a1c4fd, #c2e9fb);
11
+ transition: background 3s ease;
12
+ height: 100vh;
13
+ margin: 0;
14
+ display: flex;
15
+ flex-direction: column;
16
+ justify-content: center;
17
+ align-items: center;
18
+ }
19
+
20
+ @keyframes colorShift {
21
+ 0% { background: linear-gradient(120deg, #a1c4fd, #c2e9fb); }
22
+ 25% { background: linear-gradient(120deg, #fbc2eb, #a6c1ee); }
23
+ 50% { background: linear-gradient(120deg, #ffecd2, #fcb69f); }
24
+ 75% { background: linear-gradient(120deg, #d4fc79, #96e6a1); }
25
+ 100% { background: linear-gradient(120deg, #a1c4fd, #c2e9fb); }
26
+ }
27
+
28
+ body.animated {
29
+ animation: colorShift 20s infinite alternate ease-in-out;
30
+ }
31
+
32
+ .chat-container {
33
+ width: 95%;
34
+ max-width: 600px;
35
+ background: rgba(255,255,255,0.85);
36
+ border-radius: 20px;
37
+ padding: 20px;
38
+ box-shadow: 0 10px 30px rgba(0,0,0,0.2);
39
+ overflow: hidden;
40
+ display: flex;
41
+ flex-direction: column;
42
+ height: 80vh;
43
+ }
44
+
45
+ .avatar {
46
+ width: 80px;
47
+ height: 80px;
48
+ border-radius: 50%;
49
+ margin: 10px auto;
50
+ background: radial-gradient(circle at 30% 30%, #ffd6e0, #c6d8ff);
51
+ animation: breathe 4s ease-in-out infinite;
52
+ }
53
+
54
+ @keyframes breathe {
55
+ 0%, 100% { transform: scale(1); opacity: 0.9; }
56
+ 50% { transform: scale(1.05); opacity: 1; }
57
+ }
58
+
59
+ .chat-box {
60
+ flex: 1;
61
+ overflow-y: auto;
62
+ padding: 10px;
63
+ }
64
+
65
+ .message {
66
+ margin: 8px 0;
67
+ padding: 10px 14px;
68
+ border-radius: 12px;
69
+ max-width: 75%;
70
+ }
71
+
72
+ .user {
73
+ align-self: flex-end;
74
+ background: #a1c4fd;
75
+ color: #fff;
76
+ }
77
+
78
+ .bot {
79
+ align-self: flex-start;
80
+ background: #f0f0f0;
81
+ color: #333;
82
+ }
83
+
84
+ .controls {
85
+ display: flex;
86
+ gap: 10px;
87
+ margin-top: 10px;
88
+ }
89
+
90
+ input {
91
+ flex: 1;
92
+ padding: 10px;
93
+ border-radius: 10px;
94
+ border: none;
95
+ font-size: 1em;
96
+ outline: none;
97
+ }
98
+
99
+ button {
100
+ background: #a1c4fd;
101
+ color: white;
102
+ border: none;
103
+ border-radius: 10px;
104
+ padding: 10px 16px;
105
+ cursor: pointer;
106
+ transition: background 0.3s;
107
+ }
108
+
109
+ button:hover {
110
+ background: #7ea6f5;
111
+ }
112
+
113
+ select {
114
+ border-radius: 10px;
115
+ padding: 8px;
116
+ border: 1px solid #ccc;
117
+ font-size: 0.9em;
118
+ }
119
+
120
+ .typing {
121
+ font-style: italic;
122
+ color: #555;
123
+ margin-top: 4px;
124
+ }
125
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  </head>
127
+ <body class="animated">
 
 
 
128
  <div class="chat-container">
129
  <div class="avatar" id="avatar"></div>
130
+ <h2 style="text-align:center;">🌸 Serenity Emotional Support Chatbot</h2>
131
 
132
+ <div style="text-align:center; margin-bottom:10px;">
133
+ <label for="personality">🧠 Personality:</label>
 
 
134
  <select id="personality">
135
+ <option value="serene">Serene (Calm & Supportive)</option>
136
+ <option value="deep_male">Atlas (Deep Male)</option>
137
+ <option value="gentle_female">Luna (Gentle Female)</option>
138
+ <option value="neutral">Ari (Neutral Friendly)</option>
 
139
  </select>
140
+ <button id="toggleVoice">🔈 Voice: ON</button>
 
 
141
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
+ <div class="chat-box" id="chatBox"></div>
 
 
 
 
 
144
 
145
+ <div class="controls">
146
+ <input type="text" id="userInput" placeholder="Type your message..." />
147
+ <button id="sendBtn">Send</button>
148
+ </div>
149
+ </div>
 
 
 
 
150
 
151
+ <script>
152
+ const chatBox = document.getElementById("chatBox");
153
+ const userInput = document.getElementById("userInput");
154
+ const sendBtn = document.getElementById("sendBtn");
155
+ const personalitySelect = document.getElementById("personality");
156
+ const toggleVoiceBtn = document.getElementById("toggleVoice");
157
+ let voiceEnabled = true;
158
+ let userId = "user_" + Math.floor(Math.random() * 99999);
159
+
160
+ // 💬 Add message to chat
161
+ function addMessage(sender, text) {
162
+ const msg = document.createElement("div");
163
+ msg.className = "message " + sender;
164
+ msg.textContent = text;
165
+ chatBox.appendChild(msg);
166
+ chatBox.scrollTop = chatBox.scrollHeight;
167
+ }
168
+
169
+ // 🎤 Speak response
170
+ function speakText(text, voiceName = "Google UK English Female") {
171
+ if (!voiceEnabled) return;
172
+ const utter = new SpeechSynthesisUtterance(text);
173
+ utter.voice = speechSynthesis.getVoices().find(v => v.name.includes(voiceName)) || null;
174
+ utter.rate = 1;
175
+ utter.pitch = 1;
176
+ speechSynthesis.speak(utter);
177
+ }
178
+
179
+ // 🧠 Send message to backend
180
+ async function sendMessage() {
181
+ const text = userInput.value.trim();
182
+ if (!text) return;
183
+ addMessage("user", text);
184
+ userInput.value = "";
185
+
186
+ const typing = document.createElement("div");
187
+ typing.className = "typing";
188
+ typing.textContent = "Serenity is typing...";
189
+ chatBox.appendChild(typing);
190
+ chatBox.scrollTop = chatBox.scrollHeight;
191
+
192
+ try {
193
+ const res = await fetch("/chat", {
194
+ method: "POST",
195
+ headers: { "Content-Type": "application/json" },
196
+ body: JSON.stringify({
197
+ user_id: userId,
198
+ message: text,
199
+ personality: personalitySelect.value
200
+ }),
201
  });
202
+
203
+ const data = await res.json();
204
+ typing.remove();
205
+
206
+ if (data.reply) {
207
+ addMessage("bot", data.reply);
208
+ speakText(data.reply);
209
+ } else {
210
+ addMessage("bot", "Hmm, something went wrong 😔");
211
+ }
212
+
213
+ } catch (err) {
214
+ typing.remove();
215
+ addMessage("bot", "⚠️ Unable to connect to the server.");
216
+ }
217
+ }
218
+
219
+ // Event listeners
220
+ sendBtn.addEventListener("click", sendMessage);
221
+ userInput.addEventListener("keypress", (e) => {
222
+ if (e.key === "Enter") sendMessage();
223
+ });
224
+ toggleVoiceBtn.addEventListener("click", () => {
225
+ voiceEnabled = !voiceEnabled;
226
+ toggleVoiceBtn.textContent = voiceEnabled ? "🔈 Voice: ON" : "🔇 Voice: OFF";
227
+ });
228
+
229
+ // Initialize with greeting
230
+ addMessage("bot", "Hey there 🌼 I'm Serenity — your emotional support companion. How are you feeling today?");
231
+ </script>
232
  </body>
233
  </html>