maxxxi100 commited on
Commit
b861a93
·
verified ·
1 Parent(s): 0d8ffe1

Update My_health.html

Browse files
Files changed (1) hide show
  1. My_health.html +91 -168
My_health.html CHANGED
@@ -1,183 +1,106 @@
1
  <!DOCTYPE html>
2
  <html lang="ca">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>My Health Dashboard</title>
7
- <style>
8
- body {
9
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
10
- background: #f5f7fa;
11
- margin: 0;
12
- padding: 0;
13
- }
14
- h1 { text-align: center; margin-top: 20px; color: #333; }
15
- p { text-align:center; color: #555; }
16
- #chat-widget {
17
- position: fixed;
18
- bottom: 20px;
19
- right: 20px;
20
- width: 320px;
21
- max-height: 450px;
22
- background: white;
23
- border-radius: 12px;
24
- box-shadow: 0 8px 20px rgba(0,0,0,0.25);
25
- display: flex;
26
- flex-direction: column;
27
- overflow: hidden;
28
- font-size: 14px;
29
- z-index: 9999;
30
- transition: all 0.3s ease;
31
- }
32
- #chat-header {
33
- background: #4e9af1;
34
- color: white;
35
- padding: 12px;
36
- font-weight: bold;
37
- cursor: pointer;
38
- user-select: none;
39
- }
40
- #chat-messages {
41
- flex: 1;
42
- padding: 10px;
43
- overflow-y: auto;
44
- scroll-behavior: smooth;
45
- display: flex;
46
- flex-direction: column;
47
- }
48
- .message {
49
- margin-bottom: 10px;
50
- padding: 8px 12px;
51
- border-radius: 16px;
52
- max-width: 75%;
53
- opacity: 0;
54
- transform: translateY(10px);
55
- animation: slideIn 0.3s forwards;
56
- word-wrap: break-word;
57
- }
58
- .message.user {
59
- background: #d1e7ff;
60
- align-self: flex-end;
61
- }
62
- .message.bot {
63
- background: #f1f1f1;
64
- align-self: flex-start;
65
- }
66
- @keyframes slideIn {
67
- to {
68
- opacity: 1;
69
- transform: translateY(0);
70
- }
71
- }
72
- #chat-input {
73
- display: flex;
74
- border-top: 1px solid #ccc;
75
- }
76
- #chat-input input {
77
- flex: 1;
78
- padding: 10px;
79
- border: none;
80
- outline: none;
81
- font-size: 14px;
82
- }
83
- #chat-input button {
84
- background: #4e9af1;
85
- color: white;
86
- border: none;
87
- padding: 0 15px;
88
- cursor: pointer;
89
- transition: background 0.2s;
90
- }
91
- #chat-input button:hover {
92
- background: #3b7ed0;
93
- }
94
- .typing {
95
- font-style: italic;
96
- color: #888;
97
- }
98
- </style>
99
  </head>
100
  <body>
 
 
101
 
102
- <h1>🏥 My Health Dashboard</h1>
103
- <p>Interactua amb l'assistent de salut directament des d'aquí.</p>
 
 
 
 
 
104
 
105
- <div id="chat-widget">
106
- <div id="chat-header">Chat Assistència</div>
107
- <div id="chat-messages"></div>
108
- <div id="chat-input">
109
- <input type="text" id="message" placeholder="Escriu la teva pregunta...">
110
- <button onclick="sendMessage()">Enviar</button>
111
- </div>
112
- </div>
113
 
114
- <script>
115
- const chatMessages = document.getElementById("chat-messages");
116
- const input = document.getElementById("message");
117
 
118
- async function sendMessage() {
119
- const msg = input.value.trim();
120
- if (!msg) return;
 
 
121
 
122
- appendMessage(msg, "user");
123
- input.value = "";
124
- chatMessages.scrollTop = chatMessages.scrollHeight;
125
 
126
- // Mostrar "escrivint..."
127
- const typingEl = appendMessage("📝 Escrivint...", "bot", true);
 
 
 
 
 
 
128
 
129
- try {
130
- const res = await fetch("/chat", {
131
- method: "POST",
132
- headers: { "Content-Type": "application/json" },
133
- body: JSON.stringify({
134
- message: msg,
135
- system_message: "Ets un assistent de salut. Respon en català de manera concisa i útil."
136
- })
137
- });
138
- const data = await res.json();
139
-
140
- // Remplaza el mensaje de typing
141
- typingEl.textContent = data.response;
142
- typingEl.classList.remove("typing");
143
- chatMessages.scrollTop = chatMessages.scrollHeight;
144
- } catch (err) {
145
- typingEl.textContent = "⚠️ Error al connectar amb el servidor";
146
- typingEl.classList.remove("typing");
147
- }
148
- }
149
-
150
- function appendMessage(msg, sender, typing=false) {
151
- const div = document.createElement("div");
152
- div.className = `message ${sender}`;
153
- if(typing) div.classList.add("typing");
154
- div.textContent = msg;
155
- chatMessages.appendChild(div);
156
- chatMessages.scrollTop = chatMessages.scrollHeight;
157
- return div;
158
- }
159
-
160
- // Enviar con Enter
161
- input.addEventListener("keydown", function(e){
162
- if(e.key === "Enter") sendMessage();
163
- });
164
-
165
- // Permitir plegar el chat
166
- const chatWidget = document.getElementById("chat-widget");
167
- const chatHeader = document.getElementById("chat-header");
168
- chatHeader.addEventListener("click", () => {
169
- chatWidget.classList.toggle("collapsed");
170
- if(chatWidget.classList.contains("collapsed")){
171
- chatMessages.style.display = "none";
172
- document.getElementById("chat-input").style.display = "none";
173
- chatWidget.style.height = "50px";
174
- } else {
175
- chatMessages.style.display = "flex";
176
- document.getElementById("chat-input").style.display = "flex";
177
- chatWidget.style.height = "450px";
178
- }
179
- });
180
- </script>
181
 
 
 
 
 
 
182
  </body>
183
  </html>
 
1
  <!DOCTYPE html>
2
  <html lang="ca">
3
  <head>
4
+ <meta charset="UTF-8">
5
+ <title>My Health Dashboard</title>
6
+ <style>
7
+ body { font-family: Arial, sans-serif; margin: 20px; }
8
+ #chat-container {
9
+ position: fixed;
10
+ bottom: 20px;
11
+ right: 20px;
12
+ width: 300px;
13
+ max-height: 400px;
14
+ border: 1px solid #ccc;
15
+ border-radius: 8px;
16
+ background: #f9f9f9;
17
+ display: flex;
18
+ flex-direction: column;
19
+ box-shadow: 0 4px 6px rgba(0,0,0,0.1);
20
+ }
21
+ #chat-messages {
22
+ flex: 1;
23
+ padding: 10px;
24
+ overflow-y: auto;
25
+ }
26
+ .message { margin-bottom: 10px; }
27
+ .user { font-weight: bold; color: #007bff; }
28
+ .bot { font-weight: bold; color: #28a745; }
29
+ #chat-input {
30
+ display: flex;
31
+ border-top: 1px solid #ccc;
32
+ }
33
+ #chat-input input {
34
+ flex: 1;
35
+ padding: 10px;
36
+ border: none;
37
+ border-radius: 0 0 0 8px;
38
+ }
39
+ #chat-input button {
40
+ padding: 10px;
41
+ border: none;
42
+ background: #007bff;
43
+ color: white;
44
+ cursor: pointer;
45
+ border-radius: 0 0 8px 0;
46
+ }
47
+ #chat-input button:hover { background: #0056b3; }
48
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  </head>
50
  <body>
51
+ <h1>Benvingut a My Health Dashboard</h1>
52
+ <p>Aquesta és la interfície de prova amb chat flotant integrat.</p>
53
 
54
+ <div id="chat-container">
55
+ <div id="chat-messages"></div>
56
+ <div id="chat-input">
57
+ <input type="text" id="message" placeholder="Escriu la teva pregunta...">
58
+ <button onclick="sendMessage()">Enviar</button>
59
+ </div>
60
+ </div>
61
 
62
+ <script>
63
+ const messagesDiv = document.getElementById("chat-messages");
64
+ const input = document.getElementById("message");
 
 
 
 
 
65
 
66
+ async function sendMessage() {
67
+ const message = input.value.trim();
68
+ if (!message) return;
69
 
70
+ // Mostrar mensaje del usuario
71
+ const userMsg = document.createElement("div");
72
+ userMsg.classList.add("message", "user");
73
+ userMsg.innerText = "Tu: " + message;
74
+ messagesDiv.appendChild(userMsg);
75
 
76
+ // Limpiar input
77
+ input.value = "";
78
+ messagesDiv.scrollTop = messagesDiv.scrollHeight;
79
 
80
+ // Enviar al backend
81
+ try {
82
+ const response = await fetch("/chat", {
83
+ method: "POST",
84
+ headers: { "Content-Type": "application/json" },
85
+ body: JSON.stringify({ message: message })
86
+ });
87
+ const data = await response.json();
88
 
89
+ // Mostrar respuesta del bot
90
+ const botMsg = document.createElement("div");
91
+ botMsg.classList.add("message", "bot");
92
+ botMsg.innerText = "Bot: " + data.response;
93
+ messagesDiv.appendChild(botMsg);
94
+ messagesDiv.scrollTop = messagesDiv.scrollHeight;
95
+ } catch (err) {
96
+ console.error("Error enviant missatge:", err);
97
+ }
98
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
+ // Permitir enviar con Enter
101
+ input.addEventListener("keypress", function(e) {
102
+ if (e.key === "Enter") sendMessage();
103
+ });
104
+ </script>
105
  </body>
106
  </html>