Spaces:
Running
Running
Upload 3 files
Browse files- index.html +17 -19
- script.js +40 -0
- styles.css +36 -0
index.html
CHANGED
@@ -1,19 +1,17 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
</body>
|
19 |
-
</html>
|
|
|
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 |
+
<link rel="stylesheet" href="styles.css">
|
7 |
+
<title>Chatbot Llama 3.2</title>
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="chat-container">
|
11 |
+
<div class="chat-box" id="chat-box"></div>
|
12 |
+
<input type="text" id="user-input" placeholder="Digite sua mensagem...">
|
13 |
+
<button onclick="sendMessage()">Enviar</button>
|
14 |
+
</div>
|
15 |
+
<script src="script.js"></script>
|
16 |
+
</body>
|
17 |
+
</html>
|
|
|
|
script.js
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
async function sendMessage() {
|
2 |
+
const userInput = document.getElementById("user-input").value;
|
3 |
+
if (!userInput) return;
|
4 |
+
|
5 |
+
addMessageToChatBox("Usuário: " + userInput);
|
6 |
+
document.getElementById("user-input").value = "";
|
7 |
+
|
8 |
+
try {
|
9 |
+
const response = await fetch('https://fabiosantos-api-chatbot.hf.space/ask', {
|
10 |
+
method: 'POST',
|
11 |
+
headers: {
|
12 |
+
'Content-Type': 'application/json'
|
13 |
+
},
|
14 |
+
body: JSON.stringify({ "text": userInput })
|
15 |
+
});
|
16 |
+
|
17 |
+
if (!response.ok) {
|
18 |
+
throw new Error("Erro na resposta da API");
|
19 |
+
}
|
20 |
+
|
21 |
+
const data = await response.json();
|
22 |
+
if (data && data.response) {
|
23 |
+
addMessageToChatBox("Chatbot: " + data.response);
|
24 |
+
} else {
|
25 |
+
addMessageToChatBox("Chatbot: Resposta não encontrada.");
|
26 |
+
}
|
27 |
+
} catch (error) {
|
28 |
+
console.error("Erro:", error);
|
29 |
+
addMessageToChatBox("Chatbot: Desculpe, ocorreu um erro ao processar sua solicitação.");
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
function addMessageToChatBox(message) {
|
34 |
+
const chatBox = document.getElementById("chat-box");
|
35 |
+
const messageElement = document.createElement("div");
|
36 |
+
messageElement.textContent = message;
|
37 |
+
chatBox.appendChild(messageElement);
|
38 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
39 |
+
}
|
40 |
+
|
styles.css
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
font-family: Arial, sans-serif;
|
3 |
+
background-color: #f0f0f0;
|
4 |
+
display: flex;
|
5 |
+
justify-content: center;
|
6 |
+
align-items: center;
|
7 |
+
height: 100vh;
|
8 |
+
margin: 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
.chat-container {
|
12 |
+
width: 400px;
|
13 |
+
max-width: 100%;
|
14 |
+
background: #ffffff;
|
15 |
+
padding: 20px;
|
16 |
+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
17 |
+
border-radius: 10px;
|
18 |
+
}
|
19 |
+
|
20 |
+
.chat-box {
|
21 |
+
height: 300px;
|
22 |
+
overflow-y: auto;
|
23 |
+
border: 1px solid #ddd;
|
24 |
+
padding: 10px;
|
25 |
+
margin-bottom: 10px;
|
26 |
+
}
|
27 |
+
|
28 |
+
#user-input {
|
29 |
+
width: calc(100% - 80px);
|
30 |
+
padding: 10px;
|
31 |
+
}
|
32 |
+
|
33 |
+
button {
|
34 |
+
width: 60px;
|
35 |
+
padding: 10px;
|
36 |
+
}
|