Spaces:
No application file
No application file
Create static/script.js
Browse files
(static/static/static/script.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.getElementById('send').addEventListener('click', async () => {
|
| 2 |
+
const input = document.getElementById('input');
|
| 3 |
+
const chat = document.getElementById('chat');
|
| 4 |
+
|
| 5 |
+
// Nutzernachricht anzeigen
|
| 6 |
+
chat.innerHTML += `<div class="user-msg">${input.value}</div>`;
|
| 7 |
+
|
| 8 |
+
// An Backend senden
|
| 9 |
+
const response = await fetch('/analyze', {
|
| 10 |
+
method: 'POST',
|
| 11 |
+
headers: { 'Content-Type': 'application/json' },
|
| 12 |
+
body: JSON.stringify({ text: input.value })
|
| 13 |
+
});
|
| 14 |
+
|
| 15 |
+
const data = await response.json();
|
| 16 |
+
|
| 17 |
+
// Bot-Antwort anzeigen
|
| 18 |
+
chat.innerHTML += `
|
| 19 |
+
<div class="bot-msg">
|
| 20 |
+
<strong>Dr. Schwanz:</strong> ${data.reply}
|
| 21 |
+
<div class="tone">Ton: ${data.toneLabel} (${Math.round(data.toneScore * 100)}%)</div>
|
| 22 |
+
</div>
|
| 23 |
+
`;
|
| 24 |
+
|
| 25 |
+
input.value = '';
|
| 26 |
+
});
|