-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
202 lines (192 loc) · 6.97 KB
/
index.html
File metadata and controls
202 lines (192 loc) · 6.97 KB
1
2
3
4
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-lite/1.3.0/material.indigo-pink.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Assistant</title>
<style>
body {
margin: 0;
font-family: Roboto, sans-serif;
background-color: #FAFAFA; /* Light background */
color: #212121;
}
.header {
background-color: #6200EA; /* Purple 500 */
color: white;
padding: 16px;
text-align: center;
font-size: 24px;
}
.container {
display: flex;
flex-direction: column;
height: 100vh;
max-width: 400px;
margin: auto;
border: 1px solid #E0E0E0;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
background-color: white;
}
.chatbox {
flex: 1;
padding: 16px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 8px;
}
.chat-message {
padding: 10px 15px;
border-radius: 20px;
max-width: 80%;
word-wrap: break-word; /* Ensure long words break */
animation: fadeIn 0.3s ease forwards; /* Apply fade-in animation */
}
.user-message {
align-self: flex-end;
background-color: #6200EA; /* Purple 500 */
color: white;
border-top-left-radius: 0;
}
.assistant-message {
align-self: flex-start;
background-color: #E0E0E0; /* Light grey */
color: #212121;
border-top-right-radius: 0;
}
.input-area {
padding: 10px;
border-top: 1px solid #E0E0E0;
background-color: #F5F5F5; /* Slightly darker grey */
display: flex;
align-items: center;
}
.input-area input {
flex: 1;
padding: 10px;
border: 1px solid #E0E0E0;
border-radius: 20px;
margin-right: 10px;
transition: border-color 0.3s;
}
.input-area input:focus {
outline: none;
border-color: #6200EA; /* Purple 500 */
}
.input-area button {
padding: 10px 15px;
border: none;
border-radius: 20px;
background-color: #6200EA; /* Purple 500 */
color: white;
cursor: pointer;
display: flex;
align-items: center;
}
.input-area button:hover {
background-color: #3700B3; /* Darker Purple 700 */
}
.input-area .material-icons {
margin-right: 5px;
}
.spinner {
display: none;
border: 4px solid rgba(0, 0, 0, 0.1);
width: 24px;
height: 24px;
border-radius: 50%;
border-top-color: #6200EA; /* Purple 500 */
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="header">Chat Assistant</div>
<div class="container">
<div id="chatbox" class="chatbox"></div>
<div class="input-area">
<input id="chatInput" type="text" placeholder="Type your message" />
<button id="sendButton">
<span class="material-icons">send</span> Send
</button>
</div>
</div>
<script>
const sendButton = document.getElementById("sendButton");
const chatInput = document.getElementById('chatInput');
const chatbox = document.getElementById('chatbox');
async function displayMessage(message, isUser) {
const msgElem = document.createElement('div');
msgElem.textContent = message;
msgElem.className = `chat-message ${isUser ? 'user-message' : 'assistant-message'}`;
chatbox.appendChild(msgElem);
chatbox.scrollTop = chatbox.scrollHeight; // Scroll to the bottom
// For assistant messages, add a slight delay before displaying
if (!isUser) {
msgElem.style.opacity = 0; // Start with opacity 0
await new Promise(resolve => setTimeout(resolve, 300)); // Delay
msgElem.style.opacity = 1; // Fade in
}
}
async function callApi(apiUrl, prompt) {
chatInput.value = "Typing...";
chatInput.disabled = true;
sendButton.disabled = true;
const response = await fetch(apiUrl, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({prompt})
});
chatInput.value = "";
chatInput.disabled = false;
sendButton.disabled = false;
chatInput.focus();
return response.json();
}
chatInput.focus();
sendButton.addEventListener('click', async () => {
const message = chatInput.value.trim();
if (!message) return;
displayMessage(message, true);
chatInput.value = '';
const apiUrl = message.startsWith('/image') ?
'https://backend.buildpicoapps.com/aero/run/image-generation-api?pk=v1-Z0FBQUFBQm5HUEtMSjJkakVjcF9IQ0M0VFhRQ0FmSnNDSHNYTlJSblE0UXo1Q3RBcjFPcl9YYy1OZUhteDZWekxHdWRLM1M1alNZTkJMWEhNOWd4S1NPSDBTWC12M0U2UGc9PQ==' :
'https://backend.buildpicoapps.com/aero/run/llm-api?pk=v1-Z0FBQUFBQm5HUEtMSjJkakVjcF9IQ0M0VFhRQ0FmSnNDSHNYTlJSblE0UXo1Q3RBcjFPcl9YYy1OZUhteDZWekxHdWRLM1M1alNZTkJMWEhNOWd4S1NPSDBTWC12M0U2UGc9PQ==';
try {
const data = await callApi(apiUrl, message);
if (data.status === 'success') {
displayMessage(data.text, false);
} else {
displayMessage('An error occurred. Please try again.', false);
}
} catch (error) {
console.error('Error:', error);
displayMessage('An error occurred. Please try again.', false);
}
});
</script>
</body>
</html>