Update static/index.html
Browse files- static/index.html +40 -0
static/index.html
CHANGED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>ChatBot</title>
|
7 |
+
<style>
|
8 |
+
body { font-family: Arial, sans-serif; margin: 20px; }
|
9 |
+
#chatbox { border: 1px solid #ccc; padding: 10px; width: 300px; height: 400px; overflow-y: scroll; }
|
10 |
+
#input { margin-top: 10px; width: 300px; }
|
11 |
+
</style>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
<h1>ChatBot</h1>
|
15 |
+
<div id="chatbox"></div>
|
16 |
+
<input id="input" type="text" placeholder="Scrivi un messaggio...">
|
17 |
+
<button onclick="sendMessage()">Invia</button>
|
18 |
+
|
19 |
+
<script>
|
20 |
+
async function sendMessage() {
|
21 |
+
const inputField = document.getElementById('input');
|
22 |
+
const message = inputField.value;
|
23 |
+
inputField.value = '';
|
24 |
+
|
25 |
+
const chatbox = document.getElementById('chatbox');
|
26 |
+
chatbox.innerHTML += `<div>Tu: ${message}</div>`;
|
27 |
+
|
28 |
+
const response = await fetch('/chat', {
|
29 |
+
method: 'POST',
|
30 |
+
headers: { 'Content-Type': 'application/json' },
|
31 |
+
body: JSON.stringify({ prompt: message })
|
32 |
+
});
|
33 |
+
|
34 |
+
const data = await response.json();
|
35 |
+
chatbox.innerHTML += `<div>BOT: ${data.response}</div>`;
|
36 |
+
chatbox.scrollTop = chatbox.scrollHeight;
|
37 |
+
}
|
38 |
+
</script>
|
39 |
+
</body>
|
40 |
+
</html>
|