Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>AI ChatBot</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f4f4f4; | |
} | |
#chat-container { | |
width: 80%; | |
margin: auto; | |
margin-top: 50px; | |
padding: 20px; | |
border: 1px solid #ccc; | |
background-color: #fff; | |
position: relative; | |
overflow: auto; | |
height: 400px; | |
} | |
.user, .bot { | |
padding: 10px; | |
margin: 10px; | |
border-radius: 5px; | |
} | |
.user { | |
background-color: #e0e0e0; | |
text-align: right; | |
} | |
.bot { | |
background-color: #d1f5d3; | |
} | |
#input-container { | |
margin-top: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="chat-container"></div> | |
<div id="input-container"> | |
<input type="text" id="user-input" style="width:80%"> | |
<button onclick="sendMessage()">Send</button> | |
</div> | |
<script> | |
const endpoint = 'https://huggingface.co/spaces/dmar1313/uncensored/chat'; | |
function appendMessage(who, text) { | |
const div = document.createElement('div'); | |
div.className = who; | |
div.textContent = text; | |
document.getElementById('chat-container').appendChild(div); | |
} | |
function sendMessage() { | |
const input = document.getElementById('user-input'); | |
const text = input.value; | |
input.value = ''; | |
// Append user message to chat | |
appendMessage('user', text); | |
// Make a request to your AI model to get a response | |
fetch(endpoint, { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ prompt: text }) | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
// Append AI response to chat | |
appendMessage('bot', data.response); | |
}) | |
.catch(error => console.error('Error:', error)); | |
} | |
</script> | |
</body> | |
</html> | |