File size: 4,510 Bytes
c83615c af2ea51 c83615c af2ea51 c83615c af2ea51 e499013 af2ea51 eb121bf af2ea51 99fffb4 af2ea51 99fffb4 af2ea51 e499013 af2ea51 99fffb4 af2ea51 99fffb4 af2ea51 c83615c 99fffb4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap" rel="stylesheet">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
font-family: 'Poppins', sans-serif;
box-sizing: border-box;
}
body {
width: 100%;
height: 100vh;
background-color: #33343f;
}
.chat {
display: flex;
gap: 20px;
padding: 25px;
color: #fff;
font-size: 15px;
font-weight: 300;
}
.chat img {
width: 35px;
height: 35px;
}
.response {
background-color: #494b59;
}
.messagebar {
position: fixed;
bottom: 0;
height: 5rem;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
border-top: 1px solid #494b59;
background-color: #33343f;
}
.messagebar .bar-wrapper {
background-color: #494b59;
border-radius: 5px;
width: 60vw;
padding: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
.bar-wrapper input {
width: 100%;
padding: 5px;
border: none;
outline: none;
font-size: 14px;
background: none;
color: #ccc;
}
.bar-wrapper input::placeholder {
color: #ccc;
}
.messagebar button {
display: flex;
align-items: center;
justify-content: center;
background: none;
border: none;
color: #fff;
cursor: pointer;
}
.message-box {
height: calc(100vh - 5rem);
overflow-y: auto;
}
</style>
</head>
<body>
<div class="chatbox-wrapper">
<div class="message-box">
<div class="chat response">
<img src="img/chatbot.jpg">
<span>Hello there! <br> How can I help you today.</span>
</div>
</div>
<div class="messagebar">
<div class="bar-wrapper">
<input type="text" placeholder="Enter your message...">
<button>
<span class="material-symbols-rounded">send</span>
</button>
</div>
</div>
</div>
<script>
const messageBar = document.querySelector(".bar-wrapper input");
const sendBtn = document.querySelector(".bar-wrapper button");
const messageBox = document.querySelector(".message-box");
sendBtn.onclick = async function () {
if (messageBar.value.length > 0) {
const UserTypedMessage = messageBar.value;
messageBar.value = "";
let message = `<div class="chat message"><img src="img/user.jpg"><span>${UserTypedMessage}</span></div>`;
let response = `<div class="chat response"><img src="img/chatbot.jpg"><span class="new">...</span></div>`;
messageBox.insertAdjacentHTML("beforeend", message);
setTimeout(async () => {
messageBox.insertAdjacentHTML("beforeend", response);
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: new URLSearchParams({
prompt: UserTypedMessage,
history: "[]",
temperature: "0.9",
max_new_tokens: "512",
top_p: "0.95",
repetition_penalty: "1.0"
})
};
try {
const res = await fetch("/generate/", requestOptions);
const data = await res.json();
const ChatBotResponse = document.querySelector(".response .new");
ChatBotResponse.innerText = data.response;
ChatBotResponse.classList.remove("new");
} catch (error) {
console.error("Error:", error);
const ChatBotResponse = document.querySelector(".response .new");
ChatBotResponse.innerText = "Oops! An error occurred. Please try again.";
ChatBotResponse.classList.remove("new");
}
}, 100);
}
};
</script>
</body>
</html>
|