Shresthh03 commited on
Commit
80e2d73
·
verified ·
1 Parent(s): bea454b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +89 -208
index.html CHANGED
@@ -1,233 +1,114 @@
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>
 
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" />
6
+ <title>Serenity Chat</title>
7
  <style>
8
+ body { font-family: Arial, Helvetica, sans-serif; margin:0; background: linear-gradient(135deg,#e6f0ff,#fff0f6); transition: background .8s; }
9
+ header{ background:#6c8ef0; color:#fff; padding:12px; text-align:center; font-weight:700; }
10
+ .wrap{ max-width:900px; margin:20px auto; padding:12px; display:flex; gap:12px; align-items:flex-start; }
11
+ .left{ width:140px; text-align:center; }
12
+ .avatar{ width:120px; height:120px; border-radius:50%; margin:8px auto; background: radial-gradient(circle at 30% 30%, #fff,#8fb7ff); animation:breathe 4s ease-in-out infinite; }
13
+ @keyframes breathe{0%,100%{transform:scale(1)}50%{transform:scale(1.06)}}
14
+ .main{ flex:1; display:flex; flex-direction:column; gap:8px; }
15
+ .chat{ background:rgba(255,255,255,0.95); padding:12px; border-radius:10px; height:520px; overflow:auto; }
16
+ .bubble{ max-width:70%; padding:10px 12px; border-radius:12px; margin:8px 0; }
17
+ .user{ margin-left:auto; background:linear-gradient(135deg,#dff3ff,#bfe6ff); text-align:right; }
18
+ .bot{ margin-right:auto; background:linear-gradient(135deg,#fff0f6,#ffe6f0); text-align:left; }
19
+ .controls{ display:flex; gap:8px; align-items:center; margin-top:6px; }
20
+ input[type=text]{ flex:1; padding:10px 12px; border-radius:10px; border:1px solid #ddd; }
21
+ button{ padding:10px 12px; border-radius:10px; border:none; cursor:pointer; background:#6c8ef0; color:white; }
22
+ select{ padding:8px; border-radius:8px; border:1px solid #ccc; }
23
+ .typing{ font-style:italic; color:#666; }
24
+ @media(max-width:720px){ .wrap{ flex-direction:column; } .left{ width:100%; } .chat{ height:60vh; } }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  </style>
26
  </head>
27
+ <body>
28
+ <header>🌸 Serenity — Emotional Support</header>
29
+ <div class="wrap">
30
+ <div class="left">
31
  <div class="avatar" id="avatar"></div>
32
+ <label for="persona">Persona:</label><br/>
33
+ <select id="persona">
34
+ <option value="calm">Calm</option>
35
+ <option value="friendly">Friendly</option>
36
+ <option value="motivational">Motivational</option>
37
+ <option value="spiritual">Spiritual</option>
38
+ <option value="neutral">Neutral</option>
39
+ </select>
40
+ </div>
 
 
 
 
 
41
 
42
+ <div class="main">
43
+ <div id="chat" class="chat" role="log" aria-live="polite"></div>
44
  <div class="controls">
45
+ <input id="msg" type="text" placeholder="Type your message..." />
46
+ <button id="send">Send</button>
47
  </div>
48
+ <div id="status" class="typing" style="display:none">Serenity is thinking…</div>
49
  </div>
50
+ </div>
51
 
52
  <script>
53
+ const chatEl = document.getElementById("chat");
54
+ const msgInput = document.getElementById("msg");
55
+ const sendBtn = document.getElementById("send");
56
+ const personaSel = document.getElementById("persona");
57
+ const statusEl = document.getElementById("status");
58
+ const sessionId = localStorage.getItem("serenity_session") || ("sess_" + Math.random().toString(36).slice(2,10));
59
+ localStorage.setItem("serenity_session", sessionId);
60
+
61
+ function appendBubble(who, text, meta){
62
+ const d = document.createElement("div");
63
+ d.className = "bubble " + (who === "user" ? "user" : "bot");
64
+ d.innerText = text;
65
+ if(meta){
66
+ const m = document.createElement("div"); m.style.fontSize="11px"; m.style.color="#666"; m.style.marginTop="6px";
67
+ m.innerText = `${meta.emotion || ""} ${meta.voice ? "· voice:"+meta.voice : ""}`;
68
+ d.appendChild(m);
69
+ }
70
+ chatEl.appendChild(d);
71
+ chatEl.scrollTop = chatEl.scrollHeight;
 
 
 
 
 
 
72
  }
73
 
74
+ async function sendMessage(){
75
+ const text = msgInput.value.trim();
76
+ if(!text) return;
77
+ appendBubble("user", text);
78
+ msgInput.value = "";
79
+ statusEl.style.display = "block";
80
+ try{
 
 
 
 
 
 
 
81
  const res = await fetch("/chat", {
82
+ method:"POST",
83
+ headers: {"Content-Type":"application/json"},
84
+ body: JSON.stringify({ session: sessionId, message: text, personality: personaSel.value })
 
 
 
 
85
  });
86
+ const j = await res.json();
87
+ statusEl.style.display = "none";
88
+ const reply = j.reply || j.response || j.message || "Sorry, no reply.";
89
+ appendBubble("bot", reply, { emotion: j.emotion, voice: j.voice });
90
+ // speak reply using browser TTS (if available)
91
+ if(window.speechSynthesis && j.voice){
92
+ const u = new SpeechSynthesisUtterance(reply);
93
+ // attempt to pick a voice by simple heuristics — browsers differ
94
+ const voices = window.speechSynthesis.getVoices();
95
+ // try to pick a female/male based on voice key
96
+ let chosen = voices.find(v=> v.lang && v.lang.startsWith("en")) || voices[0];
97
+ if(chosen) u.voice = chosen;
98
+ u.rate = 1.0; u.pitch = 1.0;
99
+ window.speechSynthesis.cancel(); window.speechSynthesis.speak(u);
100
  }
101
+ }catch(err){
102
+ statusEl.style.display = "none";
103
+ appendBubble("bot", "⚠️ Unable to reach server. Check logs.");
 
104
  }
105
  }
106
 
 
107
  sendBtn.addEventListener("click", sendMessage);
108
+ msgInput.addEventListener("keydown", e=>{ if(e.key==="Enter") sendMessage(); });
 
 
 
 
 
 
109
 
110
+ // initial greeting
111
+ appendBubble("bot","💛 Hi Im Serenity. How are you feeling today?");
112
  </script>
113
  </body>
114
  </html>