anshul-chatbot / index.html
Anshultomar2005's picture
Update index.html
d4f4a6d verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anshul Chatbot</title>
<style>
body {
font-family: Arial, sans-serif;
background: #111;
color: #eee;
margin: 0;
padding: 20px;
}
h2 {
text-align: center;
color: #4cafef;
}
#chatbox {
width: 100%;
max-width: 600px;
margin: 20px auto;
background: #222;
padding: 15px;
border-radius: 10px;
height: 400px;
overflow-y: auto;
}
.msg {
margin: 8px 0;
line-height: 1.4;
}
.user {
color: #4cafef;
}
.bot {
color: #90ee90;
}
#input-area {
text-align: center;
margin-top: 10px;
}
input {
width: 70%;
padding: 10px;
border-radius: 5px;
border: none;
outline: none;
}
button {
padding: 10px 15px;
margin-left: 5px;
border: none;
border-radius: 5px;
background: #4cafef;
color: #fff;
cursor: pointer;
}
button:hover {
background: #3b8edb;
}
</style>
</head>
<body>
<h2>🤖 Anshul Chatbot</h2>
<div id="chatbox"></div>
<div id="input-area">
<input id="msg" placeholder="Type your message..." />
<button onclick="sendMessage()">Send</button>
</div>
<script>
const MODEL_URL = "/static-proxy?url=https%3A%2F%2Fapi-inference.huggingface.co%2Fmodels%2Ffacebook%2Fblenderbot-400M-distill%26quot%3B%3C%2Fspan%3E%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END -->
async function sendMessage() {
const input = document.getElementById("msg");
const chatbox = document.getElementById("chatbox");
const userMsg = input.value.trim();
if (!userMsg) return;
// User message
chatbox.innerHTML += `<div class="msg user"><b>You:</b> ${userMsg}</div>`;
input.value = "";
chatbox.scrollTop = chatbox.scrollHeight;
try {
const res = await fetch(MODEL_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ inputs: userMsg })
});
const data = await res.json();
const reply = data[0]?.generated_text || "⚠️ Sorry, no reply.";
// Bot reply
chatbox.innerHTML += `<div class="msg bot"><b>Bot:</b> ${reply}</div>`;
chatbox.scrollTop = chatbox.scrollHeight;
} catch (error) {
chatbox.innerHTML += `<div class="msg bot"><b>Bot:</b> ❌ Error connecting to model.</div>`;
}
}
</script>
</body>
</html>