Spaces:
Runtime error
Runtime error
Update templates/index.html
Browse files- templates/index.html +541 -78
templates/index.html
CHANGED
@@ -1,82 +1,545 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
import
|
6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
context = [{"role": "system", "content": system_message}]
|
28 |
-
|
29 |
-
def chat_with_ai(message):
|
30 |
-
app.logger.debug(f"Received message: {message}")
|
31 |
-
context.append({"role": "user", "content": message})
|
32 |
-
|
33 |
-
# Prepare the full prompt
|
34 |
-
full_prompt = "\n".join([f"{msg['role']}: {msg['content']}" for msg in context])
|
35 |
-
|
36 |
-
app.logger.debug(f"Making API call with prompt: {full_prompt[:100]}...") # Log first 100 chars of prompt
|
37 |
-
try:
|
38 |
-
result = client.predict(
|
39 |
-
message=full_prompt,
|
40 |
-
request=MODEL,
|
41 |
-
param_3=0.5,
|
42 |
-
param_4=8192,
|
43 |
-
param_5=0.5,
|
44 |
-
param_6=0,
|
45 |
-
api_name="/chat"
|
46 |
-
)
|
47 |
-
app.logger.debug(f"Received result: {result[:100]}...") # Log first 100 chars of result
|
48 |
-
except Exception as e:
|
49 |
-
app.logger.error(f"Error in API call: {str(e)}")
|
50 |
-
app.logger.error(traceback.format_exc())
|
51 |
-
raise
|
52 |
-
|
53 |
-
# Add AI response to context
|
54 |
-
context.append({"role": "assistant", "content": result})
|
55 |
-
|
56 |
-
return result
|
57 |
-
|
58 |
-
@app.route('/')
|
59 |
-
def index():
|
60 |
-
return render_template('index.html')
|
61 |
-
|
62 |
-
@app.route('/chat', methods=['POST'])
|
63 |
-
def chat():
|
64 |
-
data = request.json
|
65 |
-
user_input = data.get('user_input')
|
66 |
|
67 |
-
|
68 |
-
|
|
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html><head><base href="blob:https://party.websim.ai/f044f1aa-28e1-467f-989e-abf9ac58ea88">
|
2 |
+
<title>Echo AI - Advanced Enterprise Intelligence Platform</title>
|
3 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
4 |
+
<style>
|
5 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
|
6 |
+
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&display=swap');
|
7 |
+
:root {
|
8 |
+
--primary-color: #6366f1;
|
9 |
+
--secondary-color: #4f46e5;
|
10 |
+
--background-color: #0f172a;
|
11 |
+
--surface-color: #1e293b;
|
12 |
+
--text-color: #f8fafc;
|
13 |
+
--text-color-muted: #94a3b8;
|
14 |
+
--message-bg-user: #334155;
|
15 |
+
--message-bg-bot: #1e293b;
|
16 |
+
--error-color: #ef4444;
|
17 |
+
--success-color: #22c55e;
|
18 |
+
}
|
19 |
+
* {
|
20 |
+
box-sizing: border-box;
|
21 |
+
}
|
22 |
+
body, html {
|
23 |
+
margin: 0;
|
24 |
+
padding: 0;
|
25 |
+
font-family: 'Inter', sans-serif;
|
26 |
+
height: 100%;
|
27 |
+
background-color: var(--background-color);
|
28 |
+
color: var(--text-color);
|
29 |
+
line-height: 1.6;
|
30 |
+
}
|
31 |
+
.chat-container {
|
32 |
+
display: flex;
|
33 |
+
flex-direction: column;
|
34 |
+
height: 100vh;
|
35 |
+
width: 100%;
|
36 |
+
max-width: 100%;
|
37 |
+
margin: 0 auto;
|
38 |
+
background-color: var(--surface-color);
|
39 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
40 |
+
}
|
41 |
+
.chat-header {
|
42 |
+
display: flex;
|
43 |
+
align-items: center;
|
44 |
+
padding: 1rem;
|
45 |
+
background-color: rgba(255, 255, 255, 0.05);
|
46 |
+
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
47 |
+
}
|
48 |
+
.chat-header h1 {
|
49 |
+
margin: 0;
|
50 |
+
font-size: 1.25rem;
|
51 |
+
font-weight: 600;
|
52 |
+
color: var(--text-color);
|
53 |
+
}
|
54 |
+
.chat-header .model-info {
|
55 |
+
margin-left: auto;
|
56 |
+
font-size: 0.75rem;
|
57 |
+
color: var(--text-color-muted);
|
58 |
+
}
|
59 |
+
.chat-messages {
|
60 |
+
flex-grow: 1;
|
61 |
+
overflow-y: auto;
|
62 |
+
padding: 1rem;
|
63 |
+
display: flex;
|
64 |
+
flex-direction: column;
|
65 |
+
gap: 1rem;
|
66 |
+
}
|
67 |
+
.message {
|
68 |
+
max-width: 85%;
|
69 |
+
padding: 0.75rem;
|
70 |
+
border-radius: 0.5rem;
|
71 |
+
animation: fadeIn 0.3s ease-out;
|
72 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
73 |
+
font-size: 0.9rem;
|
74 |
+
}
|
75 |
+
@keyframes fadeIn {
|
76 |
+
from { opacity: 0; transform: translateY(10px); }
|
77 |
+
to { opacity: 1; transform: translateY(0); }
|
78 |
+
}
|
79 |
+
.user-message {
|
80 |
+
background-color: var(--message-bg-user);
|
81 |
+
align-self: flex-end;
|
82 |
+
border-bottom-right-radius: 0;
|
83 |
+
}
|
84 |
+
.bot-message {
|
85 |
+
background-color: var(--message-bg-bot);
|
86 |
+
align-self: flex-start;
|
87 |
+
border-bottom-left-radius: 0;
|
88 |
+
border-left: 4px solid var(--primary-color);
|
89 |
+
}
|
90 |
+
.input-area {
|
91 |
+
display: flex;
|
92 |
+
padding: 0.75rem;
|
93 |
+
background-color: rgba(255, 255, 255, 0.05);
|
94 |
+
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
95 |
+
position: sticky;
|
96 |
+
bottom: 0;
|
97 |
+
}
|
98 |
+
.input-wrapper {
|
99 |
+
position: relative;
|
100 |
+
flex-grow: 1;
|
101 |
+
display: flex;
|
102 |
+
align-items: center;
|
103 |
+
}
|
104 |
+
#user-input, #chat-user-input {
|
105 |
+
width: 100%;
|
106 |
+
padding: 0.5rem 3rem 0.5rem 0.75rem;
|
107 |
+
border: 2px solid rgba(255, 255, 255, 0.2);
|
108 |
+
border-radius: 0.5rem;
|
109 |
+
background-color: rgba(255, 255, 255, 0.05);
|
110 |
+
color: var(--text-color);
|
111 |
+
resize: none;
|
112 |
+
font-size: 0.9rem;
|
113 |
+
line-height: 1.5;
|
114 |
+
transition: all 0.3s ease;
|
115 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
116 |
+
min-height: 2.5rem;
|
117 |
+
max-height: 10rem;
|
118 |
+
overflow-y: auto;
|
119 |
+
}
|
120 |
+
#user-input:focus, #chat-user-input:focus {
|
121 |
+
outline: none;
|
122 |
+
border-color: var(--primary-color);
|
123 |
+
box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
|
124 |
+
}
|
125 |
+
#send-button, #chat-send-button {
|
126 |
+
position: absolute;
|
127 |
+
right: 0.5rem;
|
128 |
+
top: 50%;
|
129 |
+
transform: translateY(-50%);
|
130 |
+
padding: 0.4rem 0.75rem;
|
131 |
+
background-color: var(--primary-color);
|
132 |
+
color: white;
|
133 |
+
border: none;
|
134 |
+
border-radius: 0.5rem;
|
135 |
+
cursor: pointer;
|
136 |
+
font-size: 0.85rem;
|
137 |
+
font-weight: 500;
|
138 |
+
transition: all 0.3s ease;
|
139 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
140 |
+
}
|
141 |
+
#send-button:hover, #chat-send-button:hover {
|
142 |
+
background-color: var(--secondary-color);
|
143 |
+
transform: translateY(-50%) scale(1.05);
|
144 |
+
}
|
145 |
+
#send-button:active, #chat-send-button:active {
|
146 |
+
transform: translateY(-50%) scale(0.95);
|
147 |
+
}
|
148 |
+
.code-block {
|
149 |
+
background-color: rgba(0, 0, 0, 0.3);
|
150 |
+
color: #e0e0e0;
|
151 |
+
padding: 0.75rem;
|
152 |
+
border-radius: 0.375rem;
|
153 |
+
font-family: 'Fira Code', monospace;
|
154 |
+
font-size: 0.85rem;
|
155 |
+
line-height: 1.6;
|
156 |
+
white-space: pre-wrap;
|
157 |
+
overflow-x: auto;
|
158 |
+
margin: 0.75rem 0;
|
159 |
+
border-left: 3px solid var(--primary-color);
|
160 |
+
}
|
161 |
+
.central-prompt {
|
162 |
+
display: flex;
|
163 |
+
flex-direction: column;
|
164 |
+
align-items: center;
|
165 |
+
justify-content: center;
|
166 |
+
height: 100%;
|
167 |
+
text-align: center;
|
168 |
+
padding: 1rem;
|
169 |
+
}
|
170 |
+
.central-prompt h2 {
|
171 |
+
font-size: 1.25rem;
|
172 |
+
margin-bottom: 1rem;
|
173 |
+
color: var(--text-color);
|
174 |
+
font-weight: 500;
|
175 |
+
}
|
176 |
+
.central-prompt .input-area {
|
177 |
+
width: 100%;
|
178 |
+
max-width: 600px;
|
179 |
+
background: none;
|
180 |
+
border: none;
|
181 |
+
padding: 0;
|
182 |
+
}
|
183 |
+
.logo {
|
184 |
+
width: 60px;
|
185 |
+
height: 60px;
|
186 |
+
margin-bottom: 1rem;
|
187 |
+
}
|
188 |
+
::-webkit-scrollbar {
|
189 |
+
width: 6px;
|
190 |
+
}
|
191 |
+
::-webkit-scrollbar-track {
|
192 |
+
background: var(--surface-color);
|
193 |
+
}
|
194 |
+
::-webkit-scrollbar-thumb {
|
195 |
+
background: var(--primary-color);
|
196 |
+
border-radius: 3px;
|
197 |
+
}
|
198 |
+
::-webkit-scrollbar-thumb:hover {
|
199 |
+
background: var(--secondary-color);
|
200 |
+
}
|
201 |
+
.typing-indicator {
|
202 |
+
display: flex;
|
203 |
+
padding: 0.5rem;
|
204 |
+
background: var(--message-bg-bot);
|
205 |
+
border-radius: 0.375rem;
|
206 |
+
margin-bottom: 0.5rem;
|
207 |
+
align-items: center;
|
208 |
+
align-self: flex-start;
|
209 |
+
}
|
210 |
+
.typing-indicator span {
|
211 |
+
height: 6px;
|
212 |
+
width: 6px;
|
213 |
+
background: var(--text-color-muted);
|
214 |
+
border-radius: 50%;
|
215 |
+
display: inline-block;
|
216 |
+
margin-right: 4px;
|
217 |
+
animation: pulse 1.5s infinite ease-in-out;
|
218 |
+
}
|
219 |
+
.typing-indicator span:nth-child(2) {
|
220 |
+
animation-delay: 0.2s;
|
221 |
+
}
|
222 |
+
.typing-indicator span:nth-child(3) {
|
223 |
+
animation-delay: 0.4s;
|
224 |
+
}
|
225 |
+
@keyframes pulse {
|
226 |
+
0% { transform: scale(0.8); opacity: 0.5; }
|
227 |
+
50% { transform: scale(1.2); opacity: 1; }
|
228 |
+
100% { transform: scale(0.8); opacity: 0.5; }
|
229 |
+
}
|
230 |
+
.menu-icon {
|
231 |
+
cursor: pointer;
|
232 |
+
margin-left: 0.75rem;
|
233 |
+
font-size: 1.25rem;
|
234 |
+
color: var(--text-color-muted);
|
235 |
+
transition: color 0.3s ease;
|
236 |
+
}
|
237 |
+
.menu-icon:hover {
|
238 |
+
color: var(--text-color);
|
239 |
+
}
|
240 |
+
.dropdown-menu {
|
241 |
+
position: absolute;
|
242 |
+
top: 3.5rem;
|
243 |
+
right: 0.75rem;
|
244 |
+
background-color: var(--surface-color);
|
245 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
246 |
+
border-radius: 0.375rem;
|
247 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
248 |
+
display: none;
|
249 |
+
z-index: 10;
|
250 |
+
}
|
251 |
+
.dropdown-menu.show {
|
252 |
+
display: block;
|
253 |
+
}
|
254 |
+
.dropdown-menu button {
|
255 |
+
display: block;
|
256 |
+
width: 100%;
|
257 |
+
padding: 0.6rem 0.75rem;
|
258 |
+
text-align: left;
|
259 |
+
background: none;
|
260 |
+
border: none;
|
261 |
+
color: var(--text-color);
|
262 |
+
cursor: pointer;
|
263 |
+
transition: background-color 0.3s ease;
|
264 |
+
font-size: 0.9rem;
|
265 |
+
}
|
266 |
+
.dropdown-menu button:hover {
|
267 |
+
background-color: rgba(255, 255, 255, 0.05);
|
268 |
+
}
|
269 |
+
@media (max-width: 768px) {
|
270 |
+
.chat-header h1 {
|
271 |
+
font-size: 1.1rem;
|
272 |
+
}
|
273 |
+
|
274 |
+
.message {
|
275 |
+
max-width: 90%;
|
276 |
+
font-size: 0.85rem;
|
277 |
+
}
|
278 |
+
|
279 |
+
.central-prompt h2 {
|
280 |
+
font-size: 1.1rem;
|
281 |
+
}
|
282 |
+
.code-block {
|
283 |
+
font-size: 0.8rem;
|
284 |
+
}
|
285 |
+
#send-button, #chat-send-button {
|
286 |
+
padding: 0.35rem 0.6rem;
|
287 |
+
font-size: 0.8rem;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
@media (max-width: 480px) {
|
291 |
+
.chat-header h1 {
|
292 |
+
font-size: 1rem;
|
293 |
+
}
|
294 |
+
.chat-header .model-info {
|
295 |
+
font-size: 0.7rem;
|
296 |
+
}
|
297 |
+
.message {
|
298 |
+
max-width: 95%;
|
299 |
+
font-size: 0.8rem;
|
300 |
+
padding: 0.6rem;
|
301 |
+
}
|
302 |
+
.central-prompt h2 {
|
303 |
+
font-size: 1rem;
|
304 |
+
}
|
305 |
+
.logo {
|
306 |
+
width: 50px;
|
307 |
+
height: 50px;
|
308 |
+
}
|
309 |
+
#user-input, #chat-user-input {
|
310 |
+
font-size: 0.85rem;
|
311 |
+
padding: 0.4rem 2.5rem 0.4rem 0.6rem;
|
312 |
+
}
|
313 |
+
#send-button, #chat-send-button {
|
314 |
+
padding: 0.3rem 0.5rem;
|
315 |
+
font-size: 0.75rem;
|
316 |
+
}
|
317 |
+
.code-block {
|
318 |
+
font-size: 0.75rem;
|
319 |
+
padding: 0.6rem;
|
320 |
+
}
|
321 |
+
}
|
322 |
+
</style>
|
323 |
+
</head>
|
324 |
+
<body>
|
325 |
+
<div class="chat-container">
|
326 |
+
<div class="chat-header">
|
327 |
+
<h1>Echo AI</h1>
|
328 |
+
<span class="model-info">Powered by Echo-1.5</span>
|
329 |
+
<div class="menu-icon" id="menu-icon">⋮</div>
|
330 |
+
<div class="dropdown-menu" id="dropdown-menu">
|
331 |
+
<button id="clear-chat">Clear Chat</button>
|
332 |
+
<button id="export-chat">Export Chat</button>
|
333 |
+
<button id="settings">Settings</button>
|
334 |
+
</div>
|
335 |
+
</div>
|
336 |
+
<div id="central-prompt" class="central-prompt">
|
337 |
+
<svg class="logo" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
338 |
+
<defs>
|
339 |
+
<linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
340 |
+
<stop offset="0%" style="stop-color:#6366f1;stop-opacity:1" />
|
341 |
+
<stop offset="100%" style="stop-color:#4f46e5;stop-opacity:1" />
|
342 |
+
</linearGradient>
|
343 |
+
</defs>
|
344 |
+
<circle cx="50" cy="50" r="45" fill="url(#grad)" />
|
345 |
+
<path d="M50 20C33.43 20 20 33.43 20 50s13.43 30 30 30 30-13.43 30-30S66.57 20 50 20zm0 55c-13.79 0-25-11.21-25-25s11.21-25 25-25 25 11.21 25 25-11.21 25-25 25z" fill="#ffffff"/>
|
346 |
+
<circle cx="40" cy="40" r="5" fill="#ffffff" />
|
347 |
+
<circle cx="60" cy="40" r="5" fill="#ffffff" />
|
348 |
+
<path d="M65 60c0 8.28-6.72 15-15 15s-15-6.72-15-15" stroke="#ffffff" stroke-width="3" fill="none"/>
|
349 |
+
</svg>
|
350 |
+
<h2>Welcome to Echo AI. How may we assist you today?</h2>
|
351 |
+
<div class="input-area">
|
352 |
+
<div class="input-wrapper">
|
353 |
+
<textarea id="user-input" placeholder="Type your message here..." rows="1"></textarea>
|
354 |
+
<button id="send-button">Send</button>
|
355 |
+
</div>
|
356 |
+
</div>
|
357 |
+
</div>
|
358 |
+
<div class="chat-messages" id="chat-messages" style="display: none;"></div>
|
359 |
+
<div class="input-area" id="chat-input-area" style="display: none;">
|
360 |
+
<div class="input-wrapper">
|
361 |
+
<textarea id="chat-user-input" placeholder="Type your message here..." rows="1"></textarea>
|
362 |
+
<button id="chat-send-button">Send</button>
|
363 |
+
</div>
|
364 |
+
</div>
|
365 |
+
</div>
|
366 |
|
367 |
+
<script>
|
368 |
+
const chatMessages = document.getElementById('chat-messages');
|
369 |
+
const userInput = document.getElementById('user-input');
|
370 |
+
const sendButton = document.getElementById('send-button');
|
371 |
+
const centralPrompt = document.getElementById('central-prompt');
|
372 |
+
const clearChatButton = document.getElementById('clear-chat');
|
373 |
+
const exportChatButton = document.getElementById('export-chat');
|
374 |
+
const settingsButton = document.getElementById('settings');
|
375 |
+
const menuIcon = document.getElementById('menu-icon');
|
376 |
+
const dropdownMenu = document.getElementById('dropdown-menu');
|
377 |
+
const chatInputArea = document.getElementById('chat-input-area');
|
378 |
+
const chatUserInput = document.getElementById('chat-user-input');
|
379 |
+
const chatSendButton = document.getElementById('chat-send-button');
|
380 |
+
let conversationHistory = [];
|
381 |
+
function addMessage(content, isUser = false) {
|
382 |
+
const messageDiv = document.createElement('div');
|
383 |
+
messageDiv.classList.add('message');
|
384 |
+
messageDiv.classList.add(isUser ? 'user-message' : 'bot-message');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
+
// Process content for code blocks and HTML rendering
|
387 |
+
const processedContent = processContent(content);
|
388 |
+
messageDiv.innerHTML = processedContent;
|
389 |
|
390 |
+
chatMessages.appendChild(messageDiv);
|
391 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
392 |
+
return messageDiv;
|
393 |
+
}
|
394 |
+
function processContent(content) {
|
395 |
+
// Process code blocks
|
396 |
+
content = content.replace(/```(\w+)?\n?([\s\S]*?)```/g, function(match, language, code) {
|
397 |
+
return `<pre class="code-block"><code class="${language || ''}">${escapeHtml(code.trim())}</code></pre>`;
|
398 |
+
});
|
399 |
|
400 |
+
// Process inline code
|
401 |
+
content = content.replace(/`([^`]+)`/g, '<code>$1</code>');
|
402 |
+
|
403 |
+
// Replace newlines with <br> tags
|
404 |
+
content = content.replace(/\n/g, '<br>');
|
405 |
+
|
406 |
+
return content;
|
407 |
+
}
|
408 |
+
function escapeHtml(unsafe) {
|
409 |
+
return unsafe
|
410 |
+
.replace(/&/g, "&")
|
411 |
+
.replace(/</g, "<")
|
412 |
+
.replace(/>/g, ">")
|
413 |
+
.replace(/"/g, """)
|
414 |
+
.replace(/'/g, "'");
|
415 |
+
}
|
416 |
+
function addTypingIndicator() {
|
417 |
+
const indicator = document.createElement('div');
|
418 |
+
indicator.classList.add('typing-indicator');
|
419 |
+
indicator.innerHTML = '<span></span><span></span><span></span>';
|
420 |
+
chatMessages.appendChild(indicator);
|
421 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
422 |
+
return indicator;
|
423 |
+
}
|
424 |
+
function removeTypingIndicator(indicator) {
|
425 |
+
chatMessages.removeChild(indicator);
|
426 |
+
}
|
427 |
+
async function sendMessage(input) {
|
428 |
+
const message = input.value.trim();
|
429 |
+
if (message) {
|
430 |
+
addMessage(message, true);
|
431 |
+
conversationHistory.push({ role: "user", content: message });
|
432 |
+
input.value = '';
|
433 |
+
adjustTextareaHeight(input);
|
434 |
+
switchToChatMode();
|
435 |
+
getAIResponse(message);
|
436 |
+
}
|
437 |
+
}
|
438 |
+
async function getAIResponse(message) {
|
439 |
+
const typingIndicator = addTypingIndicator();
|
440 |
+
const messageDiv = addMessage('', false);
|
441 |
+
|
442 |
+
try {
|
443 |
+
const response = await fetch('https://gefiwek187-ecfrgrgeggegergui.hf.space/chat', { // Use the relative path to your Flask route
|
444 |
+
method: 'POST',
|
445 |
+
headers: {
|
446 |
+
'Content-Type': 'application/json',
|
447 |
+
},
|
448 |
+
body: JSON.stringify({
|
449 |
+
user_input: message
|
450 |
+
})
|
451 |
+
});
|
452 |
+
if (!response.ok) {
|
453 |
+
const errorText = await response.text();
|
454 |
+
throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`);
|
455 |
+
}
|
456 |
+
const data = await response.json();
|
457 |
+
if (data.error) {
|
458 |
+
throw new Error(data.error);
|
459 |
+
}
|
460 |
+
messageDiv.innerHTML = processContent(data.response);
|
461 |
+
conversationHistory.push({ role: "assistant", content: data.response });
|
462 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
463 |
+
} catch (error) {
|
464 |
+
console.error('Error fetching AI response:', error);
|
465 |
+
messageDiv.textContent = `Sorry, an error occurred while fetching the response: ${error.message}`;
|
466 |
+
} finally {
|
467 |
+
removeTypingIndicator(typingIndicator);
|
468 |
+
}
|
469 |
+
}
|
470 |
+
function switchToChatMode() {
|
471 |
+
centralPrompt.style.display = 'none';
|
472 |
+
chatMessages.style.display = 'flex';
|
473 |
+
chatInputArea.style.display = 'flex';
|
474 |
+
}
|
475 |
+
sendButton.addEventListener('click', () => {
|
476 |
+
sendMessage(userInput);
|
477 |
+
});
|
478 |
+
chatSendButton.addEventListener('click', () => {
|
479 |
+
sendMessage(chatUserInput);
|
480 |
+
});
|
481 |
+
userInput.addEventListener('keydown', (e) => {
|
482 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
483 |
+
e.preventDefault();
|
484 |
+
sendMessage(userInput);
|
485 |
+
}
|
486 |
+
});
|
487 |
+
chatUserInput.addEventListener('keydown', (e) => {
|
488 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
489 |
+
e.preventDefault();
|
490 |
+
sendMessage(chatUserInput);
|
491 |
+
}
|
492 |
+
});
|
493 |
+
function adjustTextareaHeight(textarea) {
|
494 |
+
textarea.style.height = 'auto';
|
495 |
+
textarea.style.height = (textarea.scrollHeight) + 'px';
|
496 |
+
}
|
497 |
+
userInput.addEventListener('input', function() {
|
498 |
+
adjustTextareaHeight(this);
|
499 |
+
});
|
500 |
+
chatUserInput.addEventListener('input', function() {
|
501 |
+
adjustTextareaHeight(this);
|
502 |
+
});
|
503 |
+
menuIcon.addEventListener('click', () => {
|
504 |
+
dropdownMenu.classList.toggle('show');
|
505 |
+
});
|
506 |
+
clearChatButton.addEventListener('click', () => {
|
507 |
+
chatMessages.innerHTML = '';
|
508 |
+
centralPrompt.style.display = 'flex';
|
509 |
+
chatMessages.style.display = 'none';
|
510 |
+
chatInputArea.style.display = 'none';
|
511 |
+
dropdownMenu.classList.remove('show');
|
512 |
+
conversationHistory = []; // Clear the conversation history
|
513 |
+
});
|
514 |
+
exportChatButton.addEventListener('click', () => {
|
515 |
+
const chatContent = Array.from(chatMessages.children)
|
516 |
+
.map(msg => `${msg.classList.contains('user-message') ? 'User' : 'Echo AI'}: ${msg.textContent}`)
|
517 |
+
.join('\n\n');
|
518 |
+
const blob = new Blob([chatContent], { type: 'text/plain' });
|
519 |
+
const a = document.createElement('a');
|
520 |
+
a.href = URL.createObjectURL(blob);
|
521 |
+
a.download = 'echo-ai-chat-export.txt';
|
522 |
+
document.body.appendChild(a);
|
523 |
+
a.click();
|
524 |
+
document.body.removeChild(a);
|
525 |
+
dropdownMenu.classList.remove('show');
|
526 |
+
});
|
527 |
+
settingsButton.addEventListener('click', () => {
|
528 |
+
alert('Settings functionality to be implemented in future updates.');
|
529 |
+
dropdownMenu.classList.remove('show');
|
530 |
+
});
|
531 |
+
document.addEventListener('click', (event) => {
|
532 |
+
if (!menuIcon.contains(event.target) && !dropdownMenu.contains(event.target)) {
|
533 |
+
dropdownMenu.classList.remove('show');
|
534 |
+
}
|
535 |
+
});
|
536 |
+
// Function to handle window resize
|
537 |
+
function handleResize() {
|
538 |
+
const vh = window.innerHeight * 0.01;
|
539 |
+
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
540 |
+
}
|
541 |
+
// Initial call and event listener for resize
|
542 |
+
handleResize();
|
543 |
+
window.addEventListener('resize', handleResize);
|
544 |
+
</script>
|
545 |
+
</body></html>
|