Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>Serenity - Emotional Support Companion</title> | |
| <style> | |
| body { | |
| background: #f4f7fb; | |
| font-family: "Inter", sans-serif; | |
| margin: 0; | |
| padding: 0; | |
| display: flex; | |
| flex-direction: column; | |
| height: 100vh; | |
| color: #222; | |
| } | |
| header { | |
| background: #5b6ef5; | |
| color: #fff; | |
| text-align: center; | |
| padding: 1rem; | |
| font-size: 1.3rem; | |
| font-weight: 600; | |
| letter-spacing: 0.5px; | |
| } | |
| #chat-container { | |
| flex: 1; | |
| overflow-y: auto; | |
| padding: 1rem; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| .message { | |
| margin: 0.6rem 0; | |
| max-width: 75%; | |
| padding: 0.7rem 1rem; | |
| border-radius: 12px; | |
| line-height: 1.5; | |
| animation: fadeIn 0.3s ease; | |
| word-wrap: break-word; | |
| } | |
| .user { | |
| align-self: flex-end; | |
| background: #dbe2ff; | |
| } | |
| .bot { | |
| align-self: flex-start; | |
| background: #fff; | |
| border: 1px solid #e0e0e0; | |
| } | |
| .meta { | |
| font-size: 0.7rem; | |
| color: #777; | |
| margin-top: 0.2rem; | |
| text-align: right; | |
| } | |
| #input-container { | |
| display: flex; | |
| padding: 0.7rem; | |
| background: #fff; | |
| border-top: 1px solid #ddd; | |
| } | |
| #user-input { | |
| flex: 1; | |
| border: 1px solid #ccc; | |
| border-radius: 10px; | |
| padding: 0.6rem 0.8rem; | |
| font-size: 1rem; | |
| } | |
| button { | |
| margin-left: 0.5rem; | |
| background: #5b6ef5; | |
| color: #fff; | |
| border: none; | |
| padding: 0.6rem 1rem; | |
| border-radius: 8px; | |
| cursor: pointer; | |
| transition: background 0.2s; | |
| } | |
| button:hover { | |
| background: #4d5fe3; | |
| } | |
| #controls { | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| padding: 0.5rem 1rem; | |
| background: #f0f2ff; | |
| border-bottom: 1px solid #ddd; | |
| font-size: 0.9rem; | |
| } | |
| select { | |
| border: 1px solid #ccc; | |
| border-radius: 8px; | |
| padding: 0.3rem 0.6rem; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; transform: translateY(6px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <header>🪷 Serenity – Your Emotional Support Companion</header> | |
| <div id="controls"> | |
| <div> | |
| <label for="voice-profile">Voice/Personality: </label> | |
| <select id="voice-profile"> | |
| <option value="neutral">Neutral (balanced)</option> | |
| <option value="calm_male">Calm Male</option> | |
| <option value="deep_male">Deep Male</option> | |
| <option value="soothing_male">Soothing Male</option> | |
| <option value="gentle_female">Gentle Female</option> | |
| <option value="feminine_female">Feminine Female</option> | |
| <option value="deep_female">Deep Female</option> | |
| <option value="soothing_female">Soothing Female</option> | |
| </select> | |
| </div> | |
| <button id="reset">Reset Chat</button> | |
| </div> | |
| <div id="chat-container"></div> | |
| <div id="input-container"> | |
| <input id="user-input" type="text" placeholder="Type your message..." /> | |
| <button id="send">Send</button> | |
| </div> | |
| <script> | |
| const chatContainer = document.getElementById("chat-container"); | |
| const input = document.getElementById("user-input"); | |
| const sendBtn = document.getElementById("send"); | |
| const voiceSelect = document.getElementById("voice-profile"); | |
| const resetBtn = document.getElementById("reset"); | |
| let session = localStorage.getItem("session_id"); | |
| if (!session) { | |
| session = "sess_" + Math.random().toString(36).substring(2, 10); | |
| localStorage.setItem("session_id", session); | |
| } | |
| async function appendMessage(sender, text, emotion, intent) { | |
| const div = document.createElement("div"); | |
| div.classList.add("message", sender); | |
| div.textContent = text; | |
| chatContainer.appendChild(div); | |
| if (emotion || intent) { | |
| const meta = document.createElement("div"); | |
| meta.classList.add("meta"); | |
| meta.textContent = `(${intent || "..."}, ${emotion || "..."})`; | |
| div.appendChild(meta); | |
| } | |
| chatContainer.scrollTop = chatContainer.scrollHeight; | |
| } | |
| async function sendMessage() { | |
| const text = input.value.trim(); | |
| if (!text) return; | |
| appendMessage("user", text); | |
| input.value = ""; | |
| const body = { | |
| session: session, | |
| message: text, | |
| personality: voiceSelect.value | |
| }; | |
| try { | |
| const res = await fetch("/chat", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify(body) | |
| }); | |
| const data = await res.json(); | |
| appendMessage("bot", data.reply, data.emotion, data.intent); | |
| } catch (err) { | |
| appendMessage("bot", "Sorry, I had trouble connecting. Please try again."); | |
| } | |
| } | |
| async function initChat() { | |
| const res = await fetch("/chat", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ session: session, init: true, personality: voiceSelect.value }) | |
| }); | |
| const data = await res.json(); | |
| appendMessage("bot", data.reply, data.emotion, data.intent); | |
| } | |
| async function resetChat() { | |
| await fetch("/reset_session", { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json" }, | |
| body: JSON.stringify({ session }) | |
| }); | |
| localStorage.removeItem("session_id"); | |
| session = "sess_" + Math.random().toString(36).substring(2, 10); | |
| localStorage.setItem("session_id", session); | |
| chatContainer.innerHTML = ""; | |
| appendMessage("bot", "🔄 Chat reset. Let's start fresh!"); | |
| initChat(); | |
| } | |
| sendBtn.addEventListener("click", sendMessage); | |
| input.addEventListener("keypress", (e) => { | |
| if (e.key === "Enter") sendMessage(); | |
| }); | |
| resetBtn.addEventListener("click", resetChat); | |
| initChat(); | |
| </script> | |
| </body> | |
| </html> |