// تحميل سجل المحادثة من Local Storage
function loadConversationHistory() {
const history = localStorage.getItem('conversationHistory');
if (history) {
conversationHistory = JSON.parse(history);
displayConversationHistory();
}
}
// حفظ سجل المحادثة إلى Local Storage
function saveConversationHistory() {
localStorage.setItem('conversationHistory', JSON.stringify(conversationHistory));
}
// عرض سجل المحادثة
function displayConversationHistory() {
historyContainer.innerHTML = '';
conversationHistory.forEach(item => {
const messageDiv = document.createElement('div');
messageDiv.className = 'mb-4';
code
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
// إرسال الرسالة إلى الخادم والحصول على الرد
async function sendMessage(message) {
try {
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: message })
});
code
const result = await response.json();
addMessageToHistory('ai', result.response);
// تشغيل الرد باستخدام تحويل النص إلى كلام
await playAudio(result.response);
} catch (error) {
console.error('خطأ في إرسال الرسالة:', error);
}
}
// إضافة الرسائل إلى السجل
function addMessageToHistory(sender, message) {
if (sender === 'user') {
conversationHistory.push({ user: message, ai: '' });
} else if (sender === 'ai') {
conversationHistory[conversationHistory.length - 1].ai = message;
}
displayConversationHistory();
saveConversationHistory();
}
// تحويل النص إلى كلام وتشغيله
async function playAudio(text) {
try {
const response = await fetch('/text-to-speech', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
});
// تحميل سجل المحادثة عند تحميل الصفحة
loadConversationHistory();
improve this code make it more modern and remove circle visualizer visualize with audio more modern, add face on book have eyes and mouth and have emotions get current emotion from chat api make it move with animations :
emotions :
happy
peaceful
sad
thinking
trust
and also make it move his mouth when talk
add chat show with button under the website and also use daisyui
,modern ui, make it simple and work
use
Certainly! I'll help you modernize your AI chatbot interface by incorporating a dynamic animated face that reflects emotions, utilizing Tailwind CSS and DaisyUI for a sleek design. Here's a comprehensive guide with the updated index.html and script.js files.
1. Updated index.html
This version enhances the UI with a responsive, animated face that reacts to the chatbot's emotions. It also includes a chat toggle button at the bottom and leverages DaisyUI components for a modern look.
Structure: The face comprises two eyes and a mouth, each positioned absolutely within the face container.
Animations:
Blinking Eyes: The eyes blink every 5 seconds.
Mouth Movement: The mouth animates when the AI is speaking.
Emotions: The face changes its appearance based on the current emotion (happy, peaceful, sad, thinking, trust).
Modern UI with DaisyUI:
Utilizes DaisyUI's button styles (btn, btn-success, btn-error, etc.) for consistent and responsive buttons.
Includes a chat toggle button fixed at the bottom-right corner to show/hide the chat history.
Chat Section:
A collapsible chat section that can be toggled with the chat button.
Displays the conversation history separately from the main interaction area.
2. Updated script.js
This script manages speech recognition, sending messages to the server, handling responses (including emotions), updating the conversation history, and controlling the animated face based on emotions.
javascript
Key Enhancements:
Emotion Handling:
updateFaceEmotion(emotion): Updates the face's appearance based on the current emotion received from the AI response.
Emotions Supported: happy, peaceful, sad, thinking, trust.
Animated Mouth:
Talking Animation: The mouth animates when the AI is speaking or listening.
State Management: Adds/removes the talking class to control mouth animations.
Chat Toggle Section:
Separating Chat History: The chat history is displayed in a separate, toggleable section accessible via a button.
Synchronization: Both the main conversation area and the chat section reflect the conversation history.
Error Handling:
Enhanced error handling for speech recognition and fetch requests to ensure robustness.
Responsive Design:
Ensures that the interface remains user-friendly across different device sizes.
3. Server-Side Considerations
To fully support the enhanced frontend, ensure that your server-side endpoints (/chat and /text-to-speech) are updated to handle and return the emotion associated with each AI response.
Example Response for /chat:
json
{
"response": "مرحبا! كيف يمكنني مساعدتك اليوم؟",
"emotion": "happy"
}
Ensure that your server-side logic analyzes the user's message and determines the appropriate emotion for the AI's response.
4. Additional Enhancements
Accessibility:
Keyboard Navigation: Ensure that all interactive elements are accessible via keyboard.
ARIA Labels: Add ARIA labels to buttons and interactive elements for screen readers.
Responsive Animations:
Fine-tune animations for smoother transitions and better performance on various devices.
Enhanced Emotions:
Expand the range of emotions and corresponding facial expressions for more nuanced interactions.
5. Final Thoughts
By implementing these updates, your AI chatbot interface will not only look more modern but also provide a more engaging and interactive user experience. The animated face that reflects emotions adds a personal touch, making interactions feel more natural and intuitive.
Feel free to further customize the styles and functionalities to better suit your project's requirements!