Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 101 additions & 92 deletions public/css/bot.css
Original file line number Diff line number Diff line change
@@ -1,136 +1,145 @@
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}

.msger {
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
max-width: 600px;
margin: 0 auto;
padding: 10px;
background-color: #fff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
max-width: 600px;
margin: 0 auto;
padding: 10px;
background-color: #fff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
border-radius: 10px;
}

.msger-header {
text-align: center;
margin-bottom: 20px;
text-align: center;
margin-bottom: 20px;
}

.msger-header-title p {
font-size: 24px;
font-weight: bold;
margin: 0;
font-size: 24px;
font-weight: bold;
margin: 0;
}

.msger-chat {
flex-grow: 1;
overflow-y: auto;
padding: 10px;
flex-grow: 1;
overflow-y: auto;
padding: 10px;
}

.msg {
display: flex;
align-items: center;
justify-content: flex-end;
margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: flex-end;
margin-bottom: 10px;
}

.msg-img {
width: 40px;
height: 40px;
background-size: cover;
border-radius: 50%;
margin-right: 10px;
width: 40px;
height: 40px;
background-size: cover;
border-radius: 50%;
margin-right: 10px;
}
.msg-user {
background-color: white;
margin-block: 8px;
padding: 4px;

box-shadow: rgba(50, 50, 93, 0.25) 0px 50px 100px -20px,
rgba(0, 0, 0, 0.3) 0px 30px 60px -30px;
}

.msg-bubble, .message-reply {
background-color: #eeb283;
border-radius: 10px;
padding: 10px;
color: #fff;
max-width: 70%;
.msg-bubble,
.message-reply {
background-color: #eeb283;
border-radius: 10px;
padding: 10px;
color: #fff;
max-width: 70%;
}

.msg-info {
display: flex;
justify-content: space-between;
display: flex;
justify-content: space-between;
}

.msg-info-name {
font-weight: bold;
font-weight: bold;
}

.msger-inputarea {
display: flex;
gap: 27px;
width: 100%;
align-items: center;
padding: 10px;
background-color: #fff;
border-top: 1px solid #ddd;
border-radius: 0 0 10px 10px;
display: flex;
gap: 27px;
width: 100%;
align-items: center;
padding: 10px;
background-color: #fff;
border-top: 1px solid #ddd;
border-radius: 0 0 10px 10px;
}


.msger-input {
flex-grow: 1;
padding: 10px;
border: none;
border-radius: 5px;
flex-grow: 1;
padding: 10px;
border: none;
border-radius: 5px;
}

.msger-send-btn {
background-color: #eeb283;
color: #fff;
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
background-color: #eeb283;
color: #fff;
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}

.msger-send-btn:hover {
background-color:#f59349;
}
.btn{
background-color: #eeb283;
border-radius: 1rem;
padding: 10px 20px;
margin: 10px;
font-size: 2rem;
}
#back-btn{
display: flex;
justify-content: flex-start;
align-items: center;
width: 100%;
gap: 11rem;
background-color: #f59349;
}
.btn {
background-color: #eeb283;
border-radius: 1rem;
padding: 10px 20px;
margin: 10px;
font-size: 2rem;
}
#back-btn {
display: flex;
justify-content: flex-start;
align-items: center;
width: 100%;
gap: 11rem;
}

@media (min-width: 250px) and (max-width: 372px) {
.msger{
width: 100%;
height: 100%;
}
.msger-inputarea{
gap: px;
}
label{
display: none;
}
#back-btn{
gap: 8rem;
}
.msger {
width: 100%;
height: 100%;
}
.msger-inputarea {
gap: px;
}
label {
display: none;
}
#back-btn {
gap: 8rem;
}
}
@media (min-width: 372px) and (max-width: 600px) {
#back-btn{
gap: 15rem;
}
#back-btn {
gap: 15rem;
}
}
102 changes: 60 additions & 42 deletions public/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,60 @@
const chatForm = document.getElementById('chat-form');
const messageInput = document.getElementById('message-input');
const chatLog = document.getElementById('chat-log');

chatForm.addEventListener('submit', (event) => {
event.preventDefault();
const message = messageInput.value;

const messageEl = document.createElement('div');
messageEl.className = 'message';
messageEl.textContent = `You: ${message}`;
messageEl.style.background = ' background-color: #007BFF;'
chatLog.appendChild(messageEl);

fetch('/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message }),
})
.then((res) => res.json())
.then((data) => {
const reply = data.reply;
const replyEl = document.createElement('div');
replyEl.className = 'reply';
replyEl.textContent = `Chatbot: ${reply}`;
chatLog.appendChild(replyEl);
chatLog.scrollTop = chatLog.scrollHeight;
});

messageInput.value = '';
});
function goBack() {
window.history.back();
}

function startChat() {
location.reload();
}


const chatForm = document.querySelector("#chat-form");
const messageInput = document.getElementById("message-input");
const chatLog = document.getElementById("chat-log");

chatForm.addEventListener("submit", async (event) => {
event.preventDefault();
const message = messageInput.value;

const messageEl = document.createElement("div");
messageEl.className = "message msg-user";
messageEl.textContent = message;
chatLog.appendChild(messageEl);

const response = await fetch("https://codex-a2ni.onrender.com/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: message }),
});

if (response.ok) {
try {
const data = await response.json();
const parsedData = data.bot.trim();

const replyEl = document.createElement("div");
replyEl.className = "msg left-msg";
const botReply = `
<div class="msg-img" style="background-image: url(bot.png)"></div>
<div class="msg-bubble">
<div class="msg-info">
<div class="msg-info-name">BOT</div>
<div class="msg-info-time">00:00</div>
</div>
<div class="msg-text">
${parsedData}
</div>
</div>
`;
replyEl.innerHTML = botReply;
chatLog.appendChild(replyEl);

chatLog.scrollTop = chatLog.scrollHeight;
messageInput.value = "";
} catch (error) {
console.error("Error fetching bot response:", error);
}
} else {
console.error("Request failed:", response.status);
}
});

function goBack() {
window.history.back();
}

function startChat() {
location.reload();
}