Spaces:
Sleeping
Sleeping
Create index.html
Browse files- index.html +56 -0
index.html
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html lang="en">
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<title>Chatbot</title>
|
| 7 |
+
<style>
|
| 8 |
+
body { font-family: sans-serif; background: #f4f4f4; padding: 20px; }
|
| 9 |
+
#chat-box { background: white; border-radius: 8px; padding: 15px; height: 400px; overflow-y: auto; border: 1px solid #ccc; }
|
| 10 |
+
.msg { margin-bottom: 10px; }
|
| 11 |
+
.user { color: blue; }
|
| 12 |
+
.bot { color: green; }
|
| 13 |
+
</style>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<h2>Chat with TinyLLaMA</h2>
|
| 17 |
+
<div id="chat-box"></div>
|
| 18 |
+
<input type="text" id="user-input" placeholder="Type a message..." style="width: 80%;">
|
| 19 |
+
<button onclick="sendMessage()">Send</button>
|
| 20 |
+
|
| 21 |
+
<script>
|
| 22 |
+
const sessionId = Math.random().toString(36).substring(2);
|
| 23 |
+
const model = "TinyLLaMA (1.1B)";
|
| 24 |
+
|
| 25 |
+
async function sendMessage() {
|
| 26 |
+
const input = document.getElementById("user-input");
|
| 27 |
+
const message = input.value;
|
| 28 |
+
if (!message.trim()) return;
|
| 29 |
+
|
| 30 |
+
appendMessage("You", message);
|
| 31 |
+
input.value = "";
|
| 32 |
+
|
| 33 |
+
const response = await fetch("https://huggingface.co/spaces/tumwesigeibra/CHAT-BOT/api/predict/", {
|
| 34 |
+
method: "POST",
|
| 35 |
+
headers: { "Content-Type": "application/json" },
|
| 36 |
+
body: JSON.stringify({
|
| 37 |
+
data: [message, model, sessionId]
|
| 38 |
+
})
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
const result = await response.json();
|
| 42 |
+
const botResponse = result.data[0];
|
| 43 |
+
appendMessage("Bot", botResponse);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function appendMessage(sender, text) {
|
| 47 |
+
const chatBox = document.getElementById("chat-box");
|
| 48 |
+
const div = document.createElement("div");
|
| 49 |
+
div.className = "msg " + (sender === "You" ? "user" : "bot");
|
| 50 |
+
div.innerHTML = `<strong>${sender}:</strong> ${text}`;
|
| 51 |
+
chatBox.appendChild(div);
|
| 52 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 53 |
+
}
|
| 54 |
+
</script>
|
| 55 |
+
</body>
|
| 56 |
+
</html>
|