Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +89 -208
index.html
CHANGED
|
@@ -1,233 +1,114 @@
|
|
| 1 |
-
<!
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="
|
| 5 |
-
<meta name="viewport" content="width=device-width,
|
| 6 |
-
<title
|
| 7 |
<style>
|
| 8 |
-
body {
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
}
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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
|
| 128 |
-
|
|
|
|
|
|
|
| 129 |
<div class="avatar" id="avatar"></div>
|
| 130 |
-
<
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
<
|
| 134 |
-
<
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 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
|
| 147 |
-
<button id="
|
| 148 |
</div>
|
|
|
|
| 149 |
</div>
|
|
|
|
| 150 |
|
| 151 |
<script>
|
| 152 |
-
const
|
| 153 |
-
const
|
| 154 |
-
const sendBtn = document.getElementById("
|
| 155 |
-
const
|
| 156 |
-
const
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 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 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 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:
|
| 195 |
-
headers: {
|
| 196 |
-
body: JSON.stringify({
|
| 197 |
-
user_id: userId,
|
| 198 |
-
message: text,
|
| 199 |
-
personality: personalitySelect.value
|
| 200 |
-
}),
|
| 201 |
});
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
if
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
addMessage("bot", "⚠️ Unable to connect to the server.");
|
| 216 |
}
|
| 217 |
}
|
| 218 |
|
| 219 |
-
// Event listeners
|
| 220 |
sendBtn.addEventListener("click", sendMessage);
|
| 221 |
-
|
| 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 |
-
//
|
| 230 |
-
|
| 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 — I’m Serenity. How are you feeling today?");
|
| 112 |
</script>
|
| 113 |
</body>
|
| 114 |
</html>
|