prince / index.html
Kasonga's picture
Chatbot qui utilise openai - Initial Deployment
0313a03 verified
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chatbot IA</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message-animation {
animation: fadeIn 0.3s ease-out forwards;
}
.typing-indicator span {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #4b5563;
margin: 0 2px;
}
.typing-indicator span:nth-child(1) {
animation: bounce 1s infinite;
}
.typing-indicator span:nth-child(2) {
animation: bounce 1s infinite 0.2s;
}
.typing-indicator span:nth-child(3) {
animation: bounce 1s infinite 0.4s;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-5px); }
}
.chat-container {
height: calc(100vh - 120px);
}
@media (max-width: 640px) {
.chat-container {
height: calc(100vh - 100px);
}
}
</style>
</head>
<body class="bg-gray-100 font-sans">
<div class="max-w-4xl mx-auto p-4">
<!-- Header -->
<header class="bg-gradient-to-r from-blue-600 to-indigo-700 text-white rounded-xl shadow-lg mb-6 p-6 flex items-center justify-between">
<div class="flex items-center space-x-4">
<div class="bg-white/20 p-3 rounded-full">
<i class="fas fa-robot text-2xl"></i>
</div>
<div>
<h1 class="text-2xl font-bold">Assistant IA</h1>
<p class="text-sm opacity-80">Basé sur OpenAI</p>
</div>
</div>
<div class="hidden md:flex items-center space-x-2 bg-white/10 px-4 py-2 rounded-full">
<span class="h-2 w-2 bg-green-400 rounded-full animate-pulse"></span>
<span class="text-sm">En ligne</span>
</div>
</header>
<!-- Chat container -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- Chat messages -->
<div class="chat-container overflow-y-auto p-4 space-y-4" id="chat-messages">
<!-- Welcome message -->
<div class="flex items-start space-x-3 message-animation">
<div class="bg-blue-100 p-3 rounded-full">
<i class="fas fa-robot text-blue-600"></i>
</div>
<div class="bg-blue-50 rounded-xl p-4 max-w-[80%]">
<p class="text-gray-800">Bonjour ! Je suis votre assistant IA. Comment puis-je vous aider aujourd'hui ?</p>
<p class="text-xs text-gray-500 mt-2">Basé sur OpenAI</p>
</div>
</div>
</div>
<!-- Input area -->
<div class="border-t border-gray-200 p-4 bg-gray-50">
<div class="flex items-center space-x-2">
<div class="flex-1 relative">
<textarea
id="user-input"
rows="1"
placeholder="Tapez votre message ici..."
class="w-full border border-gray-300 rounded-xl py-3 px-4 pr-12 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"
style="min-height: 50px; max-height: 150px;"
></textarea>
<button id="send-button" class="absolute right-3 bottom-3 text-blue-600 hover:text-blue-700">
<i class="fas fa-paper-plane text-xl"></i>
</button>
</div>
<button id="voice-button" class="bg-blue-600 text-white p-3 rounded-full hover:bg-blue-700 transition">
<i class="fas fa-microphone"></i>
</button>
</div>
<p class="text-xs text-gray-500 mt-2 text-center">L'IA peut faire des erreurs. Vérifiez les informations importantes.</p>
</div>
</div>
<!-- Features grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 mt-6">
<div class="bg-white p-4 rounded-xl shadow hover:shadow-md transition cursor-pointer">
<div class="bg-blue-100 w-10 h-10 rounded-full flex items-center justify-center mb-3">
<i class="fas fa-lightbulb text-blue-600"></i>
</div>
<h3 class="font-semibold">Idées créatives</h3>
<p class="text-sm text-gray-600 mt-1">Générez des idées innovantes pour vos projets</p>
</div>
<div class="bg-white p-4 rounded-xl shadow hover:shadow-md transition cursor-pointer">
<div class="bg-purple-100 w-10 h-10 rounded-full flex items-center justify-center mb-3">
<i class="fas fa-code text-purple-600"></i>
</div>
<h3 class="font-semibold">Aide au code</h3>
<p class="text-sm text-gray-600 mt-1">Obtenez de l'aide pour résoudre vos problèmes de programmation</p>
</div>
<div class="bg-white p-4 rounded-xl shadow hover:shadow-md transition cursor-pointer">
<div class="bg-green-100 w-10 h-10 rounded-full flex items-center justify-center mb-3">
<i class="fas fa-language text-green-600"></i>
</div>
<h3 class="font-semibold">Traduction</h3>
<p class="text-sm text-gray-600 mt-1">Traduisez du texte entre plusieurs langues</p>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const sendButton = document.getElementById('send-button');
const voiceButton = document.getElementById('voice-button');
let isTyping = false;
let recognition;
// Auto-resize textarea
userInput.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
// Send message on Enter (but allow Shift+Enter for new line)
userInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// Send message on button click
sendButton.addEventListener('click', sendMessage);
// Voice recognition setup
voiceButton.addEventListener('click', toggleVoiceRecognition);
function toggleVoiceRecognition() {
if (!recognition) {
recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
recognition.lang = 'fr-FR';
recognition.interimResults = false;
recognition.onstart = function() {
voiceButton.innerHTML = '<i class="fas fa-microphone-slash"></i>';
voiceButton.classList.remove('bg-blue-600');
voiceButton.classList.add('bg-red-500');
addBotMessage("Je vous écoute...", true);
};
recognition.onresult = function(event) {
const transcript = event.results[0][0].transcript;
userInput.value = transcript;
recognition.stop();
};
recognition.onend = function() {
voiceButton.innerHTML = '<i class="fas fa-microphone"></i>';
voiceButton.classList.remove('bg-red-500');
voiceButton.classList.add('bg-blue-600');
// Remove the listening message
const messages = document.querySelectorAll('.message-animation');
if (messages.length > 0) {
const lastMessage = messages[messages.length - 1];
if (lastMessage.querySelector('p').textContent === "Je vous écoute...") {
lastMessage.remove();
}
}
if (userInput.value.trim() !== '') {
sendMessage();
}
};
recognition.onerror = function(event) {
console.error('Erreur de reconnaissance vocale:', event.error);
recognition.stop();
};
}
if (voiceButton.classList.contains('bg-blue-600')) {
recognition.start();
} else {
recognition.stop();
}
}
function sendMessage() {
const message = userInput.value.trim();
if (message === '' || isTyping) return;
// Add user message to chat
addUserMessage(message);
userInput.value = '';
userInput.style.height = 'auto';
// Show typing indicator
showTypingIndicator();
// Simulate API call to OpenAI (in a real app, you'd call your backend)
setTimeout(() => {
// Remove typing indicator
hideTypingIndicator();
// Simulate different response types
const responseType = Math.floor(Math.random() * 3);
let response;
if (responseType === 0) {
response = `Voici une réponse à votre message: "${message}". L'IA peut vous aider avec une variété de tâches, y compris la rédaction, la programmation, la génération d'idées et plus encore.`;
} else if (responseType === 1) {
response = `J'ai analysé votre demande concernant "${message}". Voici quelques suggestions que vous pourriez trouver utiles: 1) Première suggestion, 2) Deuxième option, 3) Alternative supplémentaire.`;
} else {
response = `Merci pour votre message! "${message}" est un sujet intéressant. Voici ce que je peux vous dire à ce sujet: L'IA transforme de nombreux aspects de notre vie quotidienne et professionnelle.`;
}
// Add bot response
addBotMessage(response);
}, 1500 + Math.random() * 2000); // Random delay between 1.5-3.5 seconds
}
function addUserMessage(message) {
const messageElement = document.createElement('div');
messageElement.className = 'flex items-start justify-end space-x-3 message-animation';
messageElement.innerHTML = `
<div class="bg-blue-600 text-white rounded-xl p-4 max-w-[80%]">
<p>${message}</p>
</div>
<div class="bg-gray-200 p-3 rounded-full">
<i class="fas fa-user text-gray-600"></i>
</div>
`;
chatMessages.appendChild(messageElement);
scrollToBottom();
}
function addBotMessage(message, isSystem = false) {
const messageElement = document.createElement('div');
messageElement.className = 'flex items-start space-x-3 message-animation';
if (isSystem) {
messageElement.innerHTML = `
<div class="bg-gray-100 p-3 rounded-full">
<i class="fas fa-info-circle text-gray-600"></i>
</div>
<div class="bg-gray-100 rounded-xl p-4 max-w-[80%]">
<p class="text-gray-800">${message}</p>
</div>
`;
} else {
messageElement.innerHTML = `
<div class="bg-blue-100 p-3 rounded-full">
<i class="fas fa-robot text-blue-600"></i>
</div>
<div class="bg-blue-50 rounded-xl p-4 max-w-[80%]">
<p class="text-gray-800">${message}</p>
<p class="text-xs text-gray-500 mt-2">Basé sur OpenAI</p>
</div>
`;
}
chatMessages.appendChild(messageElement);
scrollToBottom();
}
function showTypingIndicator() {
isTyping = true;
const typingElement = document.createElement('div');
typingElement.className = 'flex items-start space-x-3 message-animation';
typingElement.innerHTML = `
<div class="bg-blue-100 p-3 rounded-full">
<i class="fas fa-robot text-blue-600"></i>
</div>
<div class="bg-blue-50 rounded-xl p-4 max-w-[80%]">
<div class="typing-indicator flex space-x-1">
<span></span>
<span></span>
<span></span>
</div>
</div>
`;
chatMessages.appendChild(typingElement);
scrollToBottom();
}
function hideTypingIndicator() {
isTyping = false;
const typingIndicators = document.querySelectorAll('.typing-indicator');
if (typingIndicators.length > 0) {
typingIndicators[typingIndicators.length - 1].parentElement.parentElement.parentElement.remove();
}
}
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Example quick questions
const quickQuestions = [
"Qu'est-ce que l'IA générative?",
"Peux-tu m'aider à coder une calculatrice en JavaScript?",
"Donne-moi des idées pour un roman de science-fiction",
"Explique-moi le théorème de Pythagore"
];
// Add quick question buttons (optional)
const quickQuestionsContainer = document.createElement('div');
quickQuestionsContainer.className = 'flex flex-wrap gap-2 mt-4 justify-center';
quickQuestions.forEach(question => {
const button = document.createElement('button');
button.className = 'bg-white text-sm text-gray-700 border border-gray-300 rounded-full px-4 py-2 hover:bg-gray-100 transition';
button.textContent = question;
button.addEventListener('click', () => {
userInput.value = question;
userInput.focus();
});
quickQuestionsContainer.appendChild(button);
});
document.querySelector('.bg-gray-50').insertBefore(quickQuestionsContainer, document.querySelector('.bg-gray-50 p'));
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Kasonga/prince" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>