Shresthh03 commited on
Commit
b56c516
·
verified ·
1 Parent(s): c19fc55

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +132 -145
index.html CHANGED
@@ -4,170 +4,157 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>💛 Emotional Support Assistant</title>
 
7
  <style>
8
- body {
9
- background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);
10
- font-family: 'Poppins', sans-serif;
11
- color: #333;
12
- margin: 0;
13
- padding: 0;
14
- display: flex;
15
- flex-direction: column;
16
- height: 100vh;
17
- }
18
-
19
- header {
20
- text-align: center;
21
- padding: 20px;
22
- background: rgba(255, 255, 255, 0.2);
23
- backdrop-filter: blur(10px);
24
- font-size: 1.6rem;
25
- font-weight: 600;
26
- color: #fff;
27
- }
28
-
29
- #chat-container {
30
- flex: 1;
31
- overflow-y: auto;
32
- padding: 20px;
33
- display: flex;
34
- flex-direction: column;
35
- }
36
-
37
- .message {
38
- max-width: 70%;
39
- margin-bottom: 15px;
40
- padding: 12px 18px;
41
- border-radius: 18px;
42
- font-size: 1rem;
43
- line-height: 1.4;
44
- }
45
-
46
- .user {
47
- align-self: flex-end;
48
- background: #fff;
49
- color: #444;
50
- border-bottom-right-radius: 4px;
51
- }
52
-
53
- .bot {
54
- align-self: flex-start;
55
- background: rgba(255, 255, 255, 0.3);
56
- color: #fff;
57
- border-bottom-left-radius: 4px;
58
- }
59
-
60
- #input-area {
61
- display: flex;
62
- padding: 15px;
63
- background: rgba(255, 255, 255, 0.3);
64
- backdrop-filter: blur(10px);
65
- }
66
-
67
- #user-input {
68
- flex: 1;
69
- padding: 10px;
70
- border: none;
71
- border-radius: 20px;
72
- outline: none;
73
- font-size: 1rem;
74
- }
75
-
76
- #send-btn, #mic-btn, #stop-btn {
77
- margin-left: 10px;
78
- border: none;
79
- border-radius: 50%;
80
- padding: 12px;
81
- font-size: 1.2rem;
82
- cursor: pointer;
83
- color: white;
84
- background-color: #6a11cb;
85
- transition: 0.3s;
86
- }
87
-
88
- #send-btn:hover, #mic-btn:hover, #stop-btn:hover {
89
- background-color: #2575fc;
90
- }
91
-
92
- #typing-indicator {
93
- font-style: italic;
94
- color: #f1f1f1;
95
- font-size: 0.9rem;
96
- margin-top: 5px;
97
- }
98
  </style>
99
  </head>
100
- <body>
101
- <header>💛 Emotional Support Assistant</header>
102
- <div id="chat-container"></div>
103
-
104
- <div id="input-area">
105
- <input type="text" id="user-input" placeholder="Type your message..." autocomplete="off" />
106
- <button id="send-btn">➤</button>
107
- <button id="mic-btn">🎙️</button>
108
- <button id="stop-btn">⏹️</button>
 
 
 
 
109
  </div>
 
 
110
 
111
  <script>
112
- const chatContainer = document.getElementById('chat-container');
113
- const userInput = document.getElementById('user-input');
114
- const sendBtn = document.getElementById('send-btn');
115
- const micBtn = document.getElementById('mic-btn');
116
- const stopBtn = document.getElementById('stop-btn');
117
  let recognition;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- function appendMessage(sender, text) {
120
- const msg = document.createElement('div');
121
- msg.className = 'message ' + sender;
122
- msg.textContent = text;
123
- chatContainer.appendChild(msg);
124
- chatContainer.scrollTop = chatContainer.scrollHeight;
 
 
 
 
 
 
 
 
 
125
  }
126
 
127
- function showTyping() {
128
- const typing = document.createElement('div');
129
- typing.id = 'typing-indicator';
130
- typing.textContent = "Assistant is typing...";
131
- chatContainer.appendChild(typing);
132
- chatContainer.scrollTop = chatContainer.scrollHeight;
 
133
  }
134
 
135
- function hideTyping() {
136
- const typing = document.getElementById('typing-indicator');
137
- if (typing) typing.remove();
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
- sendBtn.addEventListener('click', async () => {
141
- const text = userInput.value.trim();
142
  if (!text) return;
143
- appendMessage('user', text);
144
- userInput.value = '';
145
- showTyping();
146
-
147
- const res = await fetch('/chat', {
148
- method: 'POST',
149
- headers: { 'Content-Type': 'application/json' },
150
- body: JSON.stringify({ message: text })
151
- });
152
 
153
- const data = await res.json();
154
- hideTyping();
155
- appendMessage('bot', data.reply);
156
- });
157
 
158
- micBtn.addEventListener('click', () => {
159
- recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
160
- recognition.lang = 'en-US';
 
161
  recognition.onresult = (e) => {
162
  const transcript = e.results[0][0].transcript;
163
- userInput.value = transcript;
 
164
  };
165
- recognition.start();
166
- });
167
-
168
- stopBtn.addEventListener('click', () => {
169
- if (recognition) recognition.stop();
170
- });
 
 
 
 
 
 
 
 
171
  </script>
172
  </body>
173
- </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>💛 Emotional Support Assistant</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
  <style>
9
+ body {
10
+ transition: background 3s ease-in-out;
11
+ background: linear-gradient(135deg, #cce6ff, #fef6ff);
12
+ }
13
+ .chat-container {
14
+ max-width: 500px;
15
+ margin: 50px auto;
16
+ background: rgba(255,255,255,0.25);
17
+ backdrop-filter: blur(12px);
18
+ border-radius: 20px;
19
+ box-shadow: 0 8px 32px rgba(0,0,0,0.1);
20
+ padding: 20px;
21
+ }
22
+ .avatar {
23
+ width: 100px;
24
+ height: 100px;
25
+ border-radius: 50%;
26
+ margin: auto;
27
+ animation: breathe 4s ease-in-out infinite;
28
+ background: radial-gradient(circle at center, #a0c4ff, #4361ee);
29
+ }
30
+ @keyframes breathe {
31
+ 0%, 100% { transform: scale(1); opacity: 0.9; }
32
+ 50% { transform: scale(1.1); opacity: 1; }
33
+ }
34
+ .humanoid {
35
+ width: 100px; height: 100px;
36
+ border-radius: 50%;
37
+ background: radial-gradient(circle at 50% 30%, #f8f9fa 20%, #4361ee 80%);
38
+ animation: breathe 5s infinite ease-in-out;
39
+ }
40
+ .hidden { display: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  </style>
42
  </head>
43
+ <body class="flex flex-col items-center justify-center h-screen">
44
+
45
+ <div class="chat-container text-center">
46
+ <div id="orb" class="avatar"></div>
47
+ <div id="humanoid" class="humanoid hidden"></div>
48
+ <button id="switchAvatar" class="text-sm mt-2 underline text-blue-700">Switch Style</button>
49
+
50
+ <div id="chat" class="h-80 overflow-y-auto text-left p-3 text-gray-800"></div>
51
+ <input id="userInput" class="w-full mt-4 p-2 rounded-md border" placeholder="Type your message..." />
52
+ <div class="mt-3 flex justify-around">
53
+ <button id="sendBtn" class="bg-blue-500 text-white px-4 py-2 rounded-md">Send</button>
54
+ <button id="startBtn" class="bg-green-500 text-white px-4 py-2 rounded-md">🎙️ Start</button>
55
+ <button id="stopBtn" class="bg-red-500 text-white px-4 py-2 rounded-md">⏹️ Stop</button>
56
  </div>
57
+ <select id="voiceSelect" class="mt-3 w-full rounded-md p-2 border"></select>
58
+ </div>
59
 
60
  <script>
61
+ let recognizing = false;
 
 
 
 
62
  let recognition;
63
+ let voices = [];
64
+ let selectedVoice;
65
+ const synth = window.speechSynthesis;
66
+
67
+ function populateVoices() {
68
+ voices = synth.getVoices();
69
+ const voiceSelect = document.getElementById("voiceSelect");
70
+ voiceSelect.innerHTML = voices.map(v => `<option>${v.name}</option>`).join("");
71
+ voiceSelect.onchange = () => {
72
+ selectedVoice = voices.find(v => v.name === voiceSelect.value);
73
+ };
74
+ }
75
+ populateVoices();
76
+ if (speechSynthesis.onvoiceschanged !== undefined) {
77
+ speechSynthesis.onvoiceschanged = populateVoices;
78
+ }
79
 
80
+ document.getElementById("switchAvatar").onclick = () => {
81
+ document.getElementById("orb").classList.toggle("hidden");
82
+ document.getElementById("humanoid").classList.toggle("hidden");
83
+ };
84
+
85
+ function changeBackground(emotion) {
86
+ const map = {
87
+ joy: "linear-gradient(135deg,#fff9c4,#ffecb3)",
88
+ sadness: "linear-gradient(135deg,#a7c7e7,#d4f1f4)",
89
+ anger: "linear-gradient(135deg,#ffb3b3,#ff6666)",
90
+ love: "linear-gradient(135deg,#ffc1cc,#ffb6c1)",
91
+ fear: "linear-gradient(135deg,#c8d8e4,#a7bed3)",
92
+ crisis: "linear-gradient(135deg,#444,#ff5555)"
93
+ };
94
+ document.body.style.background = map[emotion] || "linear-gradient(135deg,#cce6ff,#fef6ff)";
95
  }
96
 
97
+ function appendMessage(sender, text) {
98
+ const chat = document.getElementById("chat");
99
+ const msg = document.createElement("div");
100
+ msg.className = sender === "user" ? "text-right mb-2" : "text-left mb-2";
101
+ msg.innerHTML = `<b>${sender}:</b> ${text}`;
102
+ chat.appendChild(msg);
103
+ chat.scrollTop = chat.scrollHeight;
104
  }
105
 
106
+ async function sendMessage() {
107
+ const input = document.getElementById("userInput");
108
+ const message = input.value.trim();
109
+ if (!message) return;
110
+ appendMessage("You", message);
111
+ input.value = "";
112
+
113
+ const res = await fetch("/chat", {
114
+ method: "POST",
115
+ headers: { "Content-Type": "application/json" },
116
+ body: JSON.stringify({ message })
117
+ });
118
+ const data = await res.json();
119
+ appendMessage("Assistant", data.reply);
120
+ changeBackground(data.emotion);
121
+ speak(data.reply);
122
  }
123
 
124
+ function speak(text) {
 
125
  if (!text) return;
126
+ const utter = new SpeechSynthesisUtterance(text);
127
+ utter.voice = selectedVoice || voices[0];
128
+ utter.pitch = 0.8;
129
+ utter.rate = 1.0;
130
+ synth.speak(utter);
131
+ }
 
 
 
132
 
133
+ document.getElementById("sendBtn").onclick = sendMessage;
 
 
 
134
 
135
+ if ("webkitSpeechRecognition" in window) {
136
+ recognition = new webkitSpeechRecognition();
137
+ recognition.continuous = false;
138
+ recognition.lang = "en-US";
139
  recognition.onresult = (e) => {
140
  const transcript = e.results[0][0].transcript;
141
+ document.getElementById("userInput").value = transcript;
142
+ sendMessage();
143
  };
144
+ document.getElementById("startBtn").onclick = () => {
145
+ if (!recognizing) {
146
+ recognizing = true;
147
+ recognition.start();
148
+ }
149
+ };
150
+ document.getElementById("stopBtn").onclick = () => {
151
+ if (recognizing) {
152
+ recognizing = false;
153
+ recognition.stop();
154
+ synth.cancel();
155
+ }
156
+ };
157
+ }
158
  </script>
159
  </body>
160
+ </html>