Spaces:
Running
Running
Update My_health.html
Browse files- 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 |
-
<
|
| 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 |
-
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 |
-
<
|
| 103 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
<
|
| 106 |
-
|
| 107 |
-
|
| 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 |
-
|
| 115 |
-
const
|
| 116 |
-
|
| 117 |
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 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>
|