codebuddy-interface / index.html
manoperna's picture
The message bubbles should be uniform in size - Initial Deployment
0cb0196 verified
Raw History Blame Contribute Delete
12.2 kB
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>CodeBuddy - Seu Brother Programador</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
<style>
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
padding: 0;
max-width: 100%;
margin: auto;
color: #212529;
display: flex;
flex-direction: column;
height: 100vh;
}
header {
background: white;
padding: 0.1rem 0.5rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
position: sticky;
top: 0;
z-index: 100;
}
.header-content {
display: flex;
align-items: center;
justify-content: space-between;
}
.profile-section {
display: flex;
gap: 0.8rem;
}
.profile-btn, .settings-btn {
background: #4361ee;
color: white;
border: none;
width: 30px;
height: 30px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
font-size: 0.8rem;
}
.profile-btn:hover, .settings-btn:hover {
background: #3f37c9;
transform: scale(1.1);
}
.title-section {
text-align: center;
flex-grow: 1;
}
h1 {
font-size: 1.5rem;
font-weight: 700;
background: linear-gradient(to right, #4361ee, #f72585);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
margin: 0;
}
#chat {
flex: 1;
overflow-y: auto;
background: #fff;
padding: 0.5rem 1rem;
margin: 0;
height: calc(100vh - 150px);
transition: all 0.3s ease;
margin-bottom: 80px; /* Space for input box */
}
#chat:hover {
box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
.message {
max-width: 80%;
padding: 0.8rem 1rem;
margin-bottom: 0.8rem;
border-radius: 1.15rem;
line-height: 1.4;
word-wrap: break-word;
white-space: pre-wrap;
opacity: 0;
transform: translateY(10px);
animation: fadeIn 0.3s ease forwards;
position: relative;
min-width: 0;
width: fit-content;
}
@keyframes fadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
.message:hover {
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.user {
background: #4361ee;
color: white;
margin-left: auto;
margin-right: 1rem;
border-radius: 1.15rem 1.15rem 0 1.15rem;
box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.assistant {
background: #f1f1f1;
color: #212529;
margin-right: auto;
margin-left: 1rem;
border-radius: 1.15rem 1.15rem 1.15rem 0;
box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}
textarea {
flex: 1;
min-height: 50px;
max-height: 10px;
padding: 0.5rem 1rem;
border-radius: 25px;
border: 1px solid #ccc;
resize: none;
font-size: 0.9rem;
margin-right: 0.5rem;
box-sizing: border-box;
font-family: inherit;
background-color: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(5px);
}
button#send {
width: 50px;
height: 50px;
padding: 0;
background: #4361ee;
color: white;
border: none;
border-radius: 50%;
cursor: pointer;
transition: background 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
}
button:hover {
background: #3f37c9;
}
.input-container {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 1rem;
background: white;
display: flex;
align-items: center;
box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}
#loading {
font-style: italic;
margin-bottom: 0.5rem;
text-align: center;
display: none;
color: #212529;
}
pre {
position: relative;
background: #2d2d2d;
color: #f8f8f2;
padding: 1rem;
border-radius: 10px;
overflow-x: auto;
white-space: pre-wrap;
margin: 0.4rem 0;
font-family: monospace, monospace;
}
pre button.copy-btn {
position: absolute;
top: 5px;
right: 5px;
padding: 0.3rem 0.6rem;
font-size: 0.75rem;
cursor: pointer;
border: none;
border-radius: 5px;
background: #4361ee;
color: white;
transition: background 0.3s ease;
}
pre button.copy-btn:hover {
background: #3f37c9;
}
</style>
</head>
<body>
<header>
<div class="header-content">
<div class="profile-section">
<button class="profile-btn"><i class="fas fa-user"></i></button>
<button class="settings-btn"><i class="fas fa-cog"></i></button>
</div>
<div class="title-section">
<h1>CodeBuddy AI</h1>
</div>
</div>
</header>
<div id="chat">
<div class="message assistant">E aí, brother! Bora aprender uns códigos juntos? Manda sua dúvida aí embaixo! 👆</div>
</div>
<div class="input-container">
<textarea id="input" placeholder="Digite sua dúvida de programação aqui..."></textarea>
<button id="send"><i class="fas fa-paper-plane"></i></button>
</div>
<div id="loading">CodeBuddy tá pensando... 🤔</div>
<script>
const chat = document.getElementById('chat');
const input = document.getElementById('input');
const send = document.getElementById('send');
const loading = document.getElementById('loading');
let mensagens = [
{
role: "assistant",
content: "E aí, brother! Bora aprender uns códigos juntos? Manda sua dúvida aí embaixo! 👆"
}
];
function criarBlocoCodigo(codeContent) {
const pre = document.createElement('pre');
pre.textContent = codeContent;
const btnCopy = document.createElement('button');
btnCopy.classList.add('copy-btn');
btnCopy.textContent = 'Copiar código';
btnCopy.addEventListener('click', () => {
navigator.clipboard.writeText(codeContent);
btnCopy.textContent = 'Copiado!';
setTimeout(() => btnCopy.textContent = 'Copiar código', 2000);
});
pre.appendChild(btnCopy);
return pre;
}
function adicionarMensagem(role, texto) {
const div = document.createElement('div');
div.classList.add('message', role);
if (role === 'assistant') {
// For assistant messages, show typing animation
let i = 0;
div.textContent = '';
chat.appendChild(div);
const typeWriter = () => {
if (i < texto.length) {
div.textContent += texto.charAt(i);
i++;
chat.scrollTop = chat.scrollHeight;
setTimeout(typeWriter, 20); // Adjust typing speed here
}
};
typeWriter();
} else {
// User messages appear instantly
const codeRegex = /```([\s\S]*?)```/g;
if (codeRegex.test(texto)) {
let lastIndex = 0;
const fragment = document.createDocumentFragment();
texto.replace(codeRegex, (match, codeContent, offset) => {
const beforeText = texto.substring(lastIndex, offset);
if (beforeText.trim()) {
const p = document.createElement('p');
p.textContent = beforeText;
fragment.appendChild(p);
}
const blocoCodigo = criarBlocoCodigo(codeContent.trim());
fragment.appendChild(blocoCodigo);
lastIndex = offset + match.length;
});
const afterText = texto.substring(lastIndex);
if (afterText.trim()) {
const p = document.createElement('p');
p.textContent = afterText;
fragment.appendChild(p);
}
div.appendChild(fragment);
} else {
div.textContent = texto;
}
chat.appendChild(div);
chat.scrollTop = chat.scrollHeight;
}
}
async function enviar() {
const pergunta = input.value.trim();
if (!pergunta) return;
adicionarMensagem('user', pergunta);
mensagens.push({ role: 'user', content: pergunta });
input.value = '';
loading.style.display = 'block';
try {
const res = await fetch('/perguntar', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ mensagens })
});
const data = await res.json();
loading.style.display = 'none';
adicionarMensagem('assistant', data.resposta);
mensagens.push({ role: 'assistant', content: data.resposta });
} catch (error) {
loading.style.display = 'none';
adicionarMensagem('assistant', 'Deu ruim aqui, tenta de novo mais tarde! 😓');
console.error('Erro:', error);
}
}
send.addEventListener('click', enviar);
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
enviar();
}
});
</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=manoperna/codebuddy-interface" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>