Spaces:
Sleeping
Sleeping
Create index.html
Browse files- index.html +127 -0
index.html
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>AI Chat</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: Arial, sans-serif;
|
10 |
+
background-color: #f4f4f9;
|
11 |
+
margin: 0;
|
12 |
+
padding: 0;
|
13 |
+
}
|
14 |
+
.chat-container {
|
15 |
+
max-width: 600px;
|
16 |
+
margin: 50px auto;
|
17 |
+
padding: 20px;
|
18 |
+
background-color: white;
|
19 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
20 |
+
border-radius: 8px;
|
21 |
+
}
|
22 |
+
.chat-box {
|
23 |
+
max-height: 400px;
|
24 |
+
overflow-y: auto;
|
25 |
+
padding: 10px;
|
26 |
+
background-color: #fafafa;
|
27 |
+
border-radius: 8px;
|
28 |
+
margin-bottom: 20px;
|
29 |
+
}
|
30 |
+
.user-message, .bot-message {
|
31 |
+
padding: 10px;
|
32 |
+
margin-bottom: 10px;
|
33 |
+
border-radius: 8px;
|
34 |
+
}
|
35 |
+
.user-message {
|
36 |
+
background-color: #e1f5fe;
|
37 |
+
align-self: flex-end;
|
38 |
+
text-align: right;
|
39 |
+
}
|
40 |
+
.bot-message {
|
41 |
+
background-color: #f1f1f1;
|
42 |
+
align-self: flex-start;
|
43 |
+
text-align: left;
|
44 |
+
}
|
45 |
+
.input-box {
|
46 |
+
display: flex;
|
47 |
+
justify-content: space-between;
|
48 |
+
align-items: center;
|
49 |
+
border-top: 1px solid #ddd;
|
50 |
+
padding: 10px;
|
51 |
+
}
|
52 |
+
.input-box input {
|
53 |
+
width: 80%;
|
54 |
+
padding: 10px;
|
55 |
+
border-radius: 4px;
|
56 |
+
border: 1px solid #ddd;
|
57 |
+
}
|
58 |
+
.input-box button {
|
59 |
+
padding: 10px;
|
60 |
+
background-color: #007BFF;
|
61 |
+
color: white;
|
62 |
+
border: none;
|
63 |
+
border-radius: 4px;
|
64 |
+
cursor: pointer;
|
65 |
+
}
|
66 |
+
.input-box button:hover {
|
67 |
+
background-color: #0056b3;
|
68 |
+
}
|
69 |
+
</style>
|
70 |
+
</head>
|
71 |
+
<body>
|
72 |
+
|
73 |
+
<div class="chat-container">
|
74 |
+
<div class="chat-box" id="chat-box"></div>
|
75 |
+
<div class="input-box">
|
76 |
+
<input type="text" id="user-input" placeholder="Type a message..." />
|
77 |
+
<button onclick="sendMessage()">Send</button>
|
78 |
+
</div>
|
79 |
+
</div>
|
80 |
+
|
81 |
+
<script>
|
82 |
+
const chatBox = document.getElementById('chat-box');
|
83 |
+
const userInput = document.getElementById('user-input');
|
84 |
+
|
85 |
+
// Function to add message to the chat box
|
86 |
+
function addMessage(message, type) {
|
87 |
+
const messageDiv = document.createElement('div');
|
88 |
+
messageDiv.classList.add(type + '-message');
|
89 |
+
messageDiv.innerText = message;
|
90 |
+
chatBox.appendChild(messageDiv);
|
91 |
+
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
|
92 |
+
}
|
93 |
+
|
94 |
+
// Function to send a message to the backend
|
95 |
+
function sendMessage() {
|
96 |
+
const message = userInput.value.trim();
|
97 |
+
if (message === '') return;
|
98 |
+
|
99 |
+
addMessage(message, 'user');
|
100 |
+
userInput.value = ''; // Clear input field
|
101 |
+
|
102 |
+
// Send the message to the backend
|
103 |
+
fetch('/generate', {
|
104 |
+
method: 'POST',
|
105 |
+
headers: {
|
106 |
+
'Content-Type': 'application/x-www-form-urlencoded'
|
107 |
+
},
|
108 |
+
body: `message=${encodeURIComponent(message)}`
|
109 |
+
})
|
110 |
+
.then(response => response.json())
|
111 |
+
.then(data => {
|
112 |
+
addMessage(data.response, 'bot');
|
113 |
+
})
|
114 |
+
.catch(error => {
|
115 |
+
console.error('Error:', error);
|
116 |
+
});
|
117 |
+
}
|
118 |
+
|
119 |
+
// Enable enter key to send message
|
120 |
+
userInput.addEventListener('keydown', (e) => {
|
121 |
+
if (e.key === 'Enter') {
|
122 |
+
sendMessage();
|
123 |
+
}
|
124 |
+
});
|
125 |
+
</script>
|
126 |
+
</body>
|
127 |
+
</html>
|