File size: 4,213 Bytes
9f775c6
 
 
 
 
 
 
 
 
eb4b18f
 
9f775c6
 
eb4b18f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9f775c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb4b18f
9f775c6
 
 
 
 
 
eb4b18f
 
 
e30dd41
 
 
 
 
 
 
 
 
 
eb4b18f
 
 
 
 
e30dd41
 
 
eb4b18f
 
 
 
e30dd41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb4b18f
 
e30dd41
 
 
 
 
2cbdc00
e30dd41
 
 
 
3fb2ff1
eb4b18f
 
 
9f775c6
eb4b18f
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!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: "[]",  // Assuming no history for now
          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.innerHTML = data.response;
        ChatBotResponse.classList.remove("new");
      } catch (error) {
        console.error("Error:", error);
        const ChatBotResponse = document.querySelector(".response .new");
        ChatBotResponse.innerHTML = "Oops! An error occurred. Please try again.";
        ChatBotResponse.classList.remove("new");
      }
    }, 100);
  }
};




</script>
</body>
</html>