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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Modern AI Chat</title>
|
7 |
+
<style>
|
8 |
+
/* Import Fonts */
|
9 |
+
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600&family=Poppins:wght@400;600&display=swap');
|
10 |
+
|
11 |
+
/* Highlight Title Styling for AI Response */
|
12 |
+
.highlight-title {
|
13 |
+
font-size: 1.2rem; /* Larger font size */
|
14 |
+
font-weight: 700; /* Extra bold */
|
15 |
+
color: #000; /* Black text */
|
16 |
+
display: inline-block; /* Ensure inline styling behaves properly */
|
17 |
+
margin: 5px 0; /* Add some spacing if needed */
|
18 |
+
}
|
19 |
+
/* Code Block Styling */
|
20 |
+
.code-block {
|
21 |
+
position: relative;
|
22 |
+
margin: 10px 0;
|
23 |
+
background: #f5f5f5;
|
24 |
+
border-radius: 5px;
|
25 |
+
padding: 10px;
|
26 |
+
overflow-x: auto;
|
27 |
+
}
|
28 |
+
|
29 |
+
.code-block pre {
|
30 |
+
margin: 0;
|
31 |
+
font-family: 'Courier New', Courier, monospace;
|
32 |
+
font-size: 0.9rem;
|
33 |
+
}
|
34 |
+
|
35 |
+
/* Copy Button Styling */
|
36 |
+
.copy-btn {
|
37 |
+
position: absolute;
|
38 |
+
top: 10px;
|
39 |
+
right: 10px;
|
40 |
+
padding: 5px 10px;
|
41 |
+
font-size: 0.8rem;
|
42 |
+
font-family: 'Poppins', sans-serif;
|
43 |
+
background: #6200ea;
|
44 |
+
color: #fff;
|
45 |
+
border: none;
|
46 |
+
border-radius: 5px;
|
47 |
+
cursor: pointer;
|
48 |
+
transition: background 0.3s ease;
|
49 |
+
}
|
50 |
+
|
51 |
+
.copy-btn:hover {
|
52 |
+
background: #3700b3;
|
53 |
+
}
|
54 |
+
|
55 |
+
.copy-btn:active {
|
56 |
+
background: #311b92;
|
57 |
+
}
|
58 |
+
pre {
|
59 |
+
background: #f5f5f5;
|
60 |
+
padding: 10px;
|
61 |
+
border-radius: 5px;
|
62 |
+
font-family: 'Courier New', Courier, monospace;
|
63 |
+
font-size: 0.9rem;
|
64 |
+
overflow-x: auto; /* Enable horizontal scrolling for long code */
|
65 |
+
}
|
66 |
+
|
67 |
+
code {
|
68 |
+
background: #f5f5f5;
|
69 |
+
padding: 2px 4px;
|
70 |
+
border-radius: 3px;
|
71 |
+
font-family: 'Courier New', Courier, monospace;
|
72 |
+
font-size: 0.9rem;
|
73 |
+
}
|
74 |
+
/* Other styles for chat system */
|
75 |
+
body {
|
76 |
+
margin: 0;
|
77 |
+
padding: 0;
|
78 |
+
font-family: 'Poppins', sans-serif;
|
79 |
+
background: linear-gradient(135deg, #6E45E2, #88D3CE);
|
80 |
+
min-height: 100vh;
|
81 |
+
display: flex;
|
82 |
+
align-items: center;
|
83 |
+
justify-content: center;
|
84 |
+
overflow: hidden;
|
85 |
+
}
|
86 |
+
/* Animation Background */
|
87 |
+
body::before {
|
88 |
+
content: '';
|
89 |
+
position: absolute;
|
90 |
+
top: -50%;
|
91 |
+
left: -50%;
|
92 |
+
width: 200%;
|
93 |
+
height: 200%;
|
94 |
+
background: radial-gradient(circle, rgba(98, 0, 234, 0.6), transparent);
|
95 |
+
animation: backgroundAnimation 6s infinite linear alternate;
|
96 |
+
z-index: 0;
|
97 |
+
}
|
98 |
+
|
99 |
+
@keyframes backgroundAnimation {
|
100 |
+
to {
|
101 |
+
transform: rotate(360deg);
|
102 |
+
}
|
103 |
+
}
|
104 |
+
|
105 |
+
.chat-container {
|
106 |
+
position: relative;
|
107 |
+
z-index: 1;
|
108 |
+
width: 100%;
|
109 |
+
max-width: 500px;
|
110 |
+
margin: 0 auto;
|
111 |
+
background: #ffffff;
|
112 |
+
border-radius: 15px;
|
113 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
|
114 |
+
display: flex;
|
115 |
+
flex-direction: column;
|
116 |
+
overflow: hidden;
|
117 |
+
}
|
118 |
+
@keyframes fadeIn {
|
119 |
+
from {
|
120 |
+
opacity: 0;
|
121 |
+
transform: translateY(30px);
|
122 |
+
}
|
123 |
+
to {
|
124 |
+
opacity: 1;
|
125 |
+
transform: translateY(0);
|
126 |
+
}
|
127 |
+
}
|
128 |
+
|
129 |
+
/* Header */
|
130 |
+
.chat-header {
|
131 |
+
background: linear-gradient(135deg, #6200ea, #3700b3);
|
132 |
+
color: #fff;
|
133 |
+
padding: 20px;
|
134 |
+
text-align: center;
|
135 |
+
font-size: 1.5rem;
|
136 |
+
font-weight: bold;
|
137 |
+
font-family: 'Cairo', sans-serif;
|
138 |
+
}
|
139 |
+
|
140 |
+
/* Chat Box */
|
141 |
+
.chat-box {
|
142 |
+
flex: 1;
|
143 |
+
padding: 20px;
|
144 |
+
overflow-y: auto; /* Enable vertical scrolling */
|
145 |
+
max-height: 400px; /* Restrict the height to make the scrolling work */
|
146 |
+
border-bottom: 1px solid #ddd;
|
147 |
+
display: flex;
|
148 |
+
flex-direction: column;
|
149 |
+
}
|
150 |
+
|
151 |
+
.chat-box .message {
|
152 |
+
margin-bottom: 15px;
|
153 |
+
font-size: 1rem;
|
154 |
+
padding: 10px 15px;
|
155 |
+
border-radius: 20px;
|
156 |
+
max-width: 75%;
|
157 |
+
animation: slideIn 0.3s ease-in-out;
|
158 |
+
word-wrap: break-word;
|
159 |
+
font-family: 'Cairo', 'Poppins', sans-serif;
|
160 |
+
}
|
161 |
+
|
162 |
+
@keyframes slideIn {
|
163 |
+
from {
|
164 |
+
transform: translateY(10px);
|
165 |
+
opacity: 0;
|
166 |
+
}
|
167 |
+
to {
|
168 |
+
transform: translateY(0);
|
169 |
+
opacity: 1;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
.chat-box .message.user {
|
174 |
+
margin-left: auto;
|
175 |
+
background: #e3f2fd;
|
176 |
+
color: #0D47A1;
|
177 |
+
text-align: right;
|
178 |
+
}
|
179 |
+
|
180 |
+
.chat-box .message.ai {
|
181 |
+
margin-right: auto;
|
182 |
+
background: #e8f5e9;
|
183 |
+
color: #1B5E20;
|
184 |
+
text-align: left;
|
185 |
+
}
|
186 |
+
|
187 |
+
/* Typing Animation */
|
188 |
+
.typing-animation {
|
189 |
+
display: flex;
|
190 |
+
margin: 10px 0;
|
191 |
+
justify-content: left;
|
192 |
+
align-items: center;
|
193 |
+
}
|
194 |
+
|
195 |
+
.typing-animation span {
|
196 |
+
display: inline-block;
|
197 |
+
width: 8px;
|
198 |
+
height: 8px;
|
199 |
+
margin: 0 3px;
|
200 |
+
background: #1B5E20;
|
201 |
+
border-radius: 50%;
|
202 |
+
animation: typing 1.3s infinite;
|
203 |
+
}
|
204 |
+
|
205 |
+
.typing-animation span:nth-child(2) {
|
206 |
+
animation-delay: 0.2s;
|
207 |
+
}
|
208 |
+
|
209 |
+
.typing-animation span:nth-child(3) {
|
210 |
+
animation-delay: 0.4s;
|
211 |
+
}
|
212 |
+
|
213 |
+
@keyframes typing {
|
214 |
+
0%, 80% {
|
215 |
+
transform: scale(0);
|
216 |
+
}
|
217 |
+
40% {
|
218 |
+
transform: scale(1);
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
/* Chat Input */
|
223 |
+
.chat-input {
|
224 |
+
display: flex;
|
225 |
+
align-items: center;
|
226 |
+
padding: 15px;
|
227 |
+
background: #f9f9f9;
|
228 |
+
border-top: 1px solid #ddd;
|
229 |
+
}
|
230 |
+
|
231 |
+
.chat-input input {
|
232 |
+
flex: 1;
|
233 |
+
padding: 15px;
|
234 |
+
border: 1px solid #ddd;
|
235 |
+
border-radius: 30px;
|
236 |
+
margin-right: 10px;
|
237 |
+
font-size: 1rem;
|
238 |
+
font-family: 'Poppins', 'Cairo', sans-serif;
|
239 |
+
outline: none;
|
240 |
+
transition: all 0.3s ease;
|
241 |
+
}
|
242 |
+
|
243 |
+
.chat-input input:focus {
|
244 |
+
border-color: #6200ea;
|
245 |
+
box-shadow: 0 0 5px rgba(98, 0, 234, 0.5);
|
246 |
+
}
|
247 |
+
|
248 |
+
.chat-input button {
|
249 |
+
padding: 12px 18px;
|
250 |
+
background: linear-gradient(135deg, #6200ea, #3700b3);
|
251 |
+
border: none;
|
252 |
+
color: white;
|
253 |
+
border-radius: 20px;
|
254 |
+
cursor: pointer;
|
255 |
+
font-weight: bold;
|
256 |
+
font-size: 1rem;
|
257 |
+
font-family: 'Poppins', 'Cairo', sans-serif;
|
258 |
+
transition: all 0.3s ease;
|
259 |
+
}
|
260 |
+
|
261 |
+
.chat-input button:hover {
|
262 |
+
background: #5e35b1;
|
263 |
+
box-shadow: 0 5px 15px rgba(98, 0, 234, 0.4);
|
264 |
+
}
|
265 |
+
</style>
|
266 |
+
</head>
|
267 |
+
<body>
|
268 |
+
<div class="chat-container">
|
269 |
+
<div class="chat-header">
|
270 |
+
AI Chat with Omar's Smart Model
|
271 |
+
</div>
|
272 |
+
<div class="chat-box" id="chat-box">
|
273 |
+
<!-- Chat messages will populate here -->
|
274 |
+
</div>
|
275 |
+
<div class="chat-input">
|
276 |
+
<input type="text" id="user-input" placeholder="Type a message..." autocomplete="off">
|
277 |
+
<button id="send-btn">Send</button>
|
278 |
+
<button id="voice-btn">๐ค</button>
|
279 |
+
</div>
|
280 |
+
</div>
|
281 |
+
<script>
|
282 |
+
const apiUrl = "https://dooratre-test-flask-space.hf.space/chat";
|
283 |
+
|
284 |
+
const chatBox = document.getElementById("chat-box");
|
285 |
+
const userInput = document.getElementById("user-input");
|
286 |
+
const sendBtn = document.getElementById("send-btn");
|
287 |
+
|
288 |
+
// Initialize conversation history
|
289 |
+
let conversationHistory = [
|
290 |
+
{ "role": "system", "content": "you are AI model created and developed By MR Omar Nuwara In CORVO AI Company you are model name ALEX-9 you can chat and help user you are best model for now\n\n you will chat Omar's Freind Hussein Shkikel He is Libyan So chat with Libyan arabic accent ๐๐๐ make it fun with smart libyan brain ๐ Hussein now in the work he is working in ุงูุงุณุชุฎุจุงุฑุงุช๐๐" }
|
291 |
+
];
|
292 |
+
|
293 |
+
function formatResponse(content) {
|
294 |
+
// Replace multi-line code blocks with copy buttons
|
295 |
+
content = content.replace(/```(.*?)\n([\s\S]*?)```/g, (match, lang, code) => {
|
296 |
+
return `
|
297 |
+
<div class="code-block">
|
298 |
+
<button class="copy-btn" onclick="copyToClipboard(this)">Copy</button>
|
299 |
+
<pre><code>${code.trim()}</code></pre>
|
300 |
+
</div>
|
301 |
+
`;
|
302 |
+
});
|
303 |
+
|
304 |
+
// Replace inline code using ` for single-line code
|
305 |
+
content = content.replace(/`(.*?)`/g, '<code>$1</code>');
|
306 |
+
|
307 |
+
// Replace \n with <br> for line breaks (outside code blocks)
|
308 |
+
content = content.replace(/\n/g, '<br>');
|
309 |
+
|
310 |
+
// Replace **{title}** with <strong class="highlight-title">{title}</strong> for bold styled text
|
311 |
+
content = content.replace(/\*\*(.*?)\*\*/g, '<strong class="highlight-title">$1</strong>');
|
312 |
+
|
313 |
+
return content;
|
314 |
+
}
|
315 |
+
function copyToClipboard(button) {
|
316 |
+
// Find the <code> block by traversing the DOM
|
317 |
+
const codeBlock = button.parentNode.querySelector("code"); // Get the <code> block inside the same parent
|
318 |
+
const codeText = codeBlock.innerText; // Retrieve the text content of the <code> block
|
319 |
+
|
320 |
+
// Copy the text to the clipboard using the Clipboard API
|
321 |
+
navigator.clipboard.writeText(codeText).then(() => {
|
322 |
+
// Temporarily show "Copied!" message on the button
|
323 |
+
button.textContent = "Copied!";
|
324 |
+
setTimeout(() => {
|
325 |
+
button.textContent = "Copy"; // Reset button text after 2 seconds
|
326 |
+
}, 2000);
|
327 |
+
}).catch(err => {
|
328 |
+
console.error("Failed to copy the code:", err);
|
329 |
+
alert("Failed to copy the code. Please try again!");
|
330 |
+
});
|
331 |
+
}
|
332 |
+
// Function to add a message to the chat box
|
333 |
+
function addMessage(role, content) {
|
334 |
+
const messageDiv = document.createElement("div");
|
335 |
+
messageDiv.classList.add("message", role);
|
336 |
+
|
337 |
+
// Format content for AI messages
|
338 |
+
if (role === "ai") {
|
339 |
+
content = formatResponse(content);
|
340 |
+
}
|
341 |
+
|
342 |
+
messageDiv.innerHTML = content; // Use innerHTML to render formatted text
|
343 |
+
chatBox.appendChild(messageDiv);
|
344 |
+
|
345 |
+
// Ensure smooth scroll to the bottom
|
346 |
+
setTimeout(() => {
|
347 |
+
chatBox.scrollTop = chatBox.scrollHeight; // Auto-scroll to the bottom after rendering
|
348 |
+
}, 100);
|
349 |
+
}
|
350 |
+
|
351 |
+
// Function to show typing animation
|
352 |
+
function showTyping() {
|
353 |
+
const typingDiv = document.createElement("div");
|
354 |
+
typingDiv.classList.add("typing-animation");
|
355 |
+
typingDiv.innerHTML = `
|
356 |
+
<span></span>
|
357 |
+
<span></span>
|
358 |
+
<span></span>
|
359 |
+
`;
|
360 |
+
chatBox.appendChild(typingDiv);
|
361 |
+
|
362 |
+
// Ensure smooth scroll to include typing animation
|
363 |
+
setTimeout(() => {
|
364 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
365 |
+
}, 100);
|
366 |
+
|
367 |
+
return typingDiv; // Return the typing div to remove it later
|
368 |
+
}
|
369 |
+
|
370 |
+
// Function to play TTS for AI response
|
371 |
+
function playTTS(text) {
|
372 |
+
var tts_xhr = new XMLHttpRequest();
|
373 |
+
tts_xhr.open("POST", "https://api.braininc.net/be/vectordb/tts", true);
|
374 |
+
tts_xhr.setRequestHeader("Authorization", "token 72ec00483379076f580eb8126f29da802a5140c3");
|
375 |
+
tts_xhr.setRequestHeader("Content-Type", "application/json");
|
376 |
+
tts_xhr.responseType = 'blob';
|
377 |
+
|
378 |
+
tts_xhr.onreadystatechange = function() {
|
379 |
+
if (tts_xhr.readyState === 4 && tts_xhr.status === 200) {
|
380 |
+
var blob = tts_xhr.response;
|
381 |
+
var audio_url = URL.createObjectURL(blob);
|
382 |
+
|
383 |
+
// Create an audio element and play the audio
|
384 |
+
var audio = new Audio(audio_url);
|
385 |
+
audio.play();
|
386 |
+
}
|
387 |
+
};
|
388 |
+
|
389 |
+
var tts_payload = {
|
390 |
+
"pubsub_topic": "/studios/516104/wsuid_new-edge-67_nodeid_editor-66/customApi/1719909878183",
|
391 |
+
"text": text
|
392 |
+
};
|
393 |
+
|
394 |
+
tts_xhr.send(JSON.stringify(tts_payload));
|
395 |
+
}
|
396 |
+
|
397 |
+
// Function to send a message
|
398 |
+
async function sendMessage() {
|
399 |
+
const userMessage = userInput.value.trim();
|
400 |
+
if (!userMessage) return;
|
401 |
+
|
402 |
+
// Add user's message to the chat UI
|
403 |
+
addMessage("user", userMessage);
|
404 |
+
|
405 |
+
// Append user message to conversation history
|
406 |
+
conversationHistory.push({ "role": "user", "content": userMessage });
|
407 |
+
|
408 |
+
// Show typing animation
|
409 |
+
const typingDiv = showTyping();
|
410 |
+
|
411 |
+
// Prepare data for the API
|
412 |
+
const data = { message: conversationHistory };
|
413 |
+
|
414 |
+
try {
|
415 |
+
// Send message to AI using fetch
|
416 |
+
const response = await fetch(apiUrl, {
|
417 |
+
method: "POST",
|
418 |
+
headers: {
|
419 |
+
"Content-Type": "application/json"
|
420 |
+
},
|
421 |
+
body: JSON.stringify(data)
|
422 |
+
});
|
423 |
+
|
424 |
+
if (response.ok) {
|
425 |
+
const aiResponse = await response.text();
|
426 |
+
|
427 |
+
// Remove typing animation
|
428 |
+
chatBox.removeChild(typingDiv);
|
429 |
+
|
430 |
+
// Add AI's response to the chat UI (with line breaks and bold formatting handled)
|
431 |
+
addMessage("ai", aiResponse);
|
432 |
+
|
433 |
+
// Append AI response to conversation history
|
434 |
+
conversationHistory.push({ "role": "assistant", "content": aiResponse });
|
435 |
+
|
436 |
+
// Play TTS for AI's response
|
437 |
+
playTTS(aiResponse);
|
438 |
+
} else {
|
439 |
+
throw new Error(`Error: ${response.status}`);
|
440 |
+
}
|
441 |
+
} catch (error) {
|
442 |
+
console.error("Error:", error);
|
443 |
+
chatBox.removeChild(typingDiv); // Remove typing animation
|
444 |
+
addMessage("ai", "AI: Sorry, something went wrong!");
|
445 |
+
}
|
446 |
+
|
447 |
+
// Clear input field
|
448 |
+
userInput.value = "";
|
449 |
+
}
|
450 |
+
|
451 |
+
// Attach event listeners
|
452 |
+
sendBtn.addEventListener("click", sendMessage);
|
453 |
+
userInput.addEventListener("keypress", (e) => {
|
454 |
+
if (e.key === "Enter") sendMessage();
|
455 |
+
});
|
456 |
+
|
457 |
+
// Initialize Speech Recognition
|
458 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
459 |
+
const recognition = new SpeechRecognition();
|
460 |
+
recognition.lang = 'ar-LY'; // Set language to Arabic (Libya)
|
461 |
+
|
462 |
+
recognition.onstart = function() {
|
463 |
+
console.log('Voice recognition started. Speak now.');
|
464 |
+
};
|
465 |
+
|
466 |
+
recognition.onresult = function(event) {
|
467 |
+
const transcript = event.results[0][0].transcript; // Get the recognized text
|
468 |
+
userInput.value = transcript; // Set the input field to the recognized text
|
469 |
+
sendMessage(); // Send the message
|
470 |
+
};
|
471 |
+
|
472 |
+
recognition.onerror = function(event) {
|
473 |
+
console.error('Error occurred in recognition: ' + event.error);
|
474 |
+
};
|
475 |
+
|
476 |
+
// Attach event listener for the voice button
|
477 |
+
document.getElementById("voice-btn").addEventListener("click", () => {
|
478 |
+
recognition.start(); // Start voice recognition
|
479 |
+
});
|
480 |
+
</script>
|
481 |
+
</body>
|
482 |
+
</html>
|