Spaces:
Sleeping
Sleeping
Update it all and make it functional.
Browse files- index.html +217 -195
index.html
CHANGED
|
@@ -1,211 +1,233 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 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
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
<div class="controls">
|
| 152 |
<select id="personality">
|
| 153 |
-
<option value="
|
| 154 |
-
<option value="
|
| 155 |
-
<option value="
|
| 156 |
-
<option value="
|
| 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 |
-
|
| 190 |
-
const res = await fetch("/chat", {
|
| 191 |
-
method: "POST",
|
| 192 |
-
headers: { "Content-Type": "application/json" },
|
| 193 |
-
body: JSON.stringify({ message, personality }),
|
| 194 |
-
});
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
typingIndicator.style.display = "none";
|
| 202 |
-
appendMessage("bot", "⚠️ Oops, something went wrong. Please try again later.");
|
| 203 |
-
}
|
| 204 |
-
}
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
});
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|