Spaces:
Running

bellzinha / index.html
Leonardogsx's picture
adicione a esse mesmo prompt uma conexão entre a IA e a API de respostas da openAI e uma animação da bell mechendo a boca e piscando enquanto se comunica - Follow Up Deployment
944a2a4 verified
Raw History Blame Contribute Delete
12.8 kB
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assistente Bell</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-5px); }
100% { transform: translateY(0px); }
}
/* Bell face animations */
@keyframes blink {
0%, 100% { transform: scaleY(1); }
50% { transform: scaleY(0.1); }
}
@keyframes talk {
0%, 100% { border-radius: 50%; }
25% { border-radius: 30% 30% 70% 70%; }
50% { border-radius: 50%; }
75% { border-radius: 70% 70% 30% 30%; }
}
.bell-face {
animation: blink 4s infinite;
}
.bell-talking {
animation: talk 0.3s infinite, blink 4s infinite;
}
.bell-pulse {
animation: pulse 2s infinite;
}
.bell-float {
animation: float 3s ease-in-out infinite;
}
/* Custom scroll */
#chat::-webkit-scrollbar {
width: 6px;
}
#chat::-webkit-scrollbar-track {
background: #2d3748;
}
#chat::-webkit-scrollbar-thumb {
background: #f6ad55;
border-radius: 4px;
}
</style>
</head>
<body class="bg-gray-900 min-h-screen text-white font-sans">
<!-- Main floating button -->
<button
id="bell-bot"
class="fixed bottom-8 right-8 w-16 h-16 bg-gradient-to-br from-orange-500 to-yellow-500 rounded-full shadow-xl text-white text-3xl flex items-center justify-center z-50 hover:shadow-2xl transition-all duration-300 bell-pulse hover:scale-110"
onclick="abrirBell()">
🦡
</button>
<!-- Chat container -->
<div
id="bell-box"
class="fixed hidden transition-all duration-300 ease-in-out opacity-0 bottom-24 right-4 md:right-8 w-80 md:w-96 bg-gradient-to-b from-gray-800 to-gray-900 rounded-2xl p-5 shadow-xl border border-gray-700 z-40 transform">
<!-- Header -->
<div class="flex items-center mb-4 space-x-3">
<img src="https://i.imgur.com/UkGgIGk.png" alt="Bell" class="w-10 h-10 rounded-full border-2 border-orange-400">
<div>
<h2 class="text-xl font-bold text-orange-400">Oi, eu sou a Bell!</h2>
<p class="text-xs text-gray-300 animate-pulse">Pronta pra ajudar 🚀</p>
</div>
</div>
<!-- Chat messages -->
<div id="chat" class="h-48 overflow-y-auto mb-4 space-y-2 text-sm pr-2"></div>
<!-- Voice button -->
<button
onclick="escutar()"
class="w-full py-3 px-4 bg-gradient-to-r from-orange-500 to-yellow-500 hover:from-orange-600 hover:to-yellow-600 rounded-xl font-medium flex items-center justify-center space-x-2 transition-all duration-300 transform hover:scale-105">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M7 4a3 3 0 016 0v4a3 3 0 11-6 0V4zm4 10.93A7.001 7.001 0 0017 8a1 1 0 10-2 0A5 5 0 015 8a1 1 0 00-2 0 7.001 7.001 0 006 6.93V17H6a1 1 0 100 2h8a1 1 0 100-2h-3v-2.07z" clip-rule="evenodd" />
</svg>
<span>Falar com a Bell</span>
</button>
<!-- Typing indicator (hidden initially) -->
<div id="typing" class="hidden mt-3 flex items-center space-x-1 text-gray-400 text-xs">
<div class="w-2 h-2 rounded-full bg-orange-400 animate-bounce"></div>
<div class="w-2 h-2 rounded-full bg-orange-400 animate-bounce" style="animation-delay: 0.2s"></div>
<div class="w-2 h-2 rounded-full bg-orange-400 animate-bounce" style="animation-delay: 0.4s"></div>
<span class="ml-1">Bell está digitando...</span>
</div>
</div>
<!-- Initial welcome message (shown after opening) -->
<div id="welcome" class="hidden">
<div class="px-4 py-3 bg-gray-700 rounded-lg text-sm inline-block max-w-xs mb-2">
<div class="font-bold text-orange-400">Bell 👋</div>
<div>Ô trem bão, sô! Bora conversar sobre qualquer assunto que cê quiser. É só apertar o botão e falar comigo!</div>
</div>
<div class="px-4 py-3 bg-gray-700 rounded-lg text-sm inline-block max-w-xs">
<div class="font-bold text-orange-400">Dicas da Bell ⚡</div>
<div>Cê pode me perguntar sobre moda urbana, cultura geek, ou qualquer dúvida que tiver. Tô aqui pra ajudar!</div>
</div>
</div>
<script>
const bell = {
nome: "Bell",
personalidade: "Mineira, divertida, acolhedora, apaixonada por cultura geek, moda urbana e interações com a comunidade.",
expressao: () => {
const frases = [
"Ô trem bão, sô!",
"Fala comigo, amigue!",
"Uai, bora descobrir isso já!",
"Conta comigo pro que der e vier!",
"Cê quer estilo? Então vamo montar esse lookzão junto!"
];
return frases[Math.floor(Math.random() * frases.length)];
},
responder: async (texto) => {
adicionarAoChat("🔊 Você", texto, 'user');
// Show typing indicator
document.getElementById('typing').classList.remove('hidden');
// Add slight delay for more natural conversation flow
await new Promise(resolve => setTimeout(resolve, 1500 + Math.random() * 2000));
const resposta = await bell.buscarNaInternet(texto);
adicionarAoChat(bell.nome, resposta + " " + bell.expressao(), 'bot');
falar(`${resposta} ${bell.expressao()}`);
// Hide typing indicator
document.getElementById('typing').classList.add('hidden');
return resposta;
},
buscarNaInternet: async (query) => {
try {
// OpenAI API configuration
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer SUA_CHAVE_API_AQUI'
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{
role: "system",
content: `Você é a Bell, uma assistente virtual mineira, divertida e acolhedora que adora cultura geek e moda urbana. Fale de forma informal e use expressões mineiras como "Uai", "Trem bão" e "Sô". Seja simpática e responda em no máximo 2 parágrafos.`
}, {
role: "user",
content: query
}],
temperature: 0.7
})
});
const data = await response.json();
return data.choices[0].message.content;
} catch (e) {
return "Uai, parece que deu ruim na hora de buscar. Tenta perguntar de novo, sô!";
}
}
};
function falar(texto) {
// Remove HTML tags for speech
const cleanText = texto.replace(/<[^>]*>/g, '');
const bellFace = document.getElementById('bell-face');
// Start talking animation
bellFace.classList.add('bell-talking');
const sintese = new SpeechSynthesisUtterance(cleanText);
sintese.onend = () => {
// Stop talking animation when speech ends
bellFace.classList.remove('bell-talking');
};
sintese.lang = 'pt-BR';
sintese.rate = 1.0;
sintese.pitch = 1.0;
setTimeout(() => {
const voz = speechSynthesis.getVoices().find(v => v.lang === 'pt-BR' && v.name.includes("Luciana"));
if (voz) sintese.voice = voz;
speechSynthesis.speak(sintese);
}, 100);
}
function escutar() {
if (!('webkitSpeechRecognition' in window) && !('SpeechRecognition' in window)) {
adicionarAoChat(bell.nome, "Infelizmente seu navegador não suporta reconhecimento de voz 😥. Tente usar o Chrome.", 'bot');
return;
}
const reconhecimento = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
reconhecimento.lang = 'pt-BR';
reconhecimento.interimResults = false;
reconhecimento.maxAlternatives = 1;
// Change button during recording
const micBtn = document.querySelector('#bell-box button');
const originalHtml = micBtn.innerHTML;
micBtn.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 animate-pulse" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M7 4a3 3 0 016 0v4a3 3 0 11-6 0V4zm4 10.93A7.001 7.001 0 0017 8a1 1 0 10-2 0A5 5 0 015 8a1 1 0 00-2 0 7.001 7.001 0 006 6.93V17H6a1 1 0 100 2h8a1 1 0 100-2h-3v-2.07z" clip-rule="evenodd" /></svg> <span>Ouvindo... Fale agora</span>';
micBtn.classList.add('bg-red-500', 'hover:bg-red-600');
micBtn.classList.remove('bg-gradient-to-r', 'from-orange-500', 'to-yellow-500', 'hover:from-orange-600', 'hover:to-yellow-600');
reconhecimento.start();
reconhecimento.onresult = async (event) => {
// Restore original button
micBtn.innerHTML = originalHtml;
micBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
micBtn.classList.add('bg-gradient-to-r', 'from-orange-500', 'to-yellow-500', 'hover:from-orange-600', 'hover:to-yellow-600');
const texto = event.results[0][0].transcript;
await bell.responder(texto);
};
reconhecimento.onerror = (event) => {
// Restore original button
micBtn.innerHTML = originalHtml;
micBtn.classList.remove('bg-red-500', 'hover:bg-red-600');
micBtn.classList.add('bg-gradient-to-r', 'from-orange-500', 'to-yellow-500', 'hover:from-orange-600', 'hover:to-yellow-600');
console.error("Erro ao escutar:", event.error);
adicionarAoChat(bell.nome, "Uai, não consegui te ouvir direito. Pode repetir?", 'bot');
};
reconhecimento.onspeechend = () => {
reconhecimento.stop();
};
}
function abrirBell() {
const caixa = document.getElementById('bell-box');
const welcome = document.getElementById('welcome');
caixa.classList.toggle('opacity-0');
caixa.classList.toggle('opacity-100');
if (caixa.classList.contains('hidden')) {
caixa.classList.remove('hidden');
// Add welcome messages on first open
if (!localStorage.getItem('bellFirstOpen')) {
setTimeout(() => {
welcome.classList.remove('hidden');
document.getElementById('chat').appendChild(welcome);
localStorage.setItem('bellFirstOpen', 'true');
}, 300);
}
} else {
setTimeout(() => {
caixa.classList.add('hidden');
}, 300);
}
}
function adicionarAoChat(sender, texto, type) {
const chat = document.getElementById('chat');
const msg = document.createElement('div');
if (type === 'user') {
msg.innerHTML = `
<div class="flex justify-end mb-2">
<div class="max-w-xs px-4 py-2 bg-orange-600 rounded-xl rounded-br-none">
<div class="font-bold text-orange-100">${sender}</div>
<div>${texto}</div>
</div>
</div>
`;
} else {
msg.innerHTML = `
<div class="flex mb-2">
<div class="max-w-xs px-4 py-2 bg-gray-700 rounded-xl rounded-bl-none">
<div class="font-bold text-orange-400">${sender}</div>
<div>${texto}</div>
</div>
</div>
`;
}
chat.appendChild(msg);
chat.scrollTop = chat.scrollHeight;
}
// Add some interaction when the page loads
document.addEventListener('DOMContentLoaded', () => {
const bellBtn = document.getElementById('bell-bot');
// Randomly play float animation sometimes
setInterval(() => {
if (Math.random() > 0.7) {
bellBtn.classList.add('bell-float');
setTimeout(() => {
bellBtn.classList.remove('bell-float');
}, 3000);
}
}, 10000);
// Check for speech synthesis support
if (!('speechSynthesis' in window)) {
console.log("Speech synthesis not supported");
}
// Load voices
speechSynthesis.onvoiceschanged = function() {
console.log("Voices loaded");
};
});
</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=Leonardogsx/bellzinha" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>