Ashrafb commited on
Commit
1a3a2da
1 Parent(s): 7a6996a

Create index.html

Browse files
Files changed (1) hide show
  1. static/index.html +185 -0
static/index.html ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <link rel="stylesheet" href="style.css">
8
+ <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" />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com">
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap" rel="stylesheet">
12
+ <title>Chatbot</title>
13
+ <style>
14
+ *{
15
+ padding: 0;
16
+ margin: 0;
17
+ font-family: 'Poppins', sans-serif;
18
+ box-sizing: border-box;
19
+ }
20
+
21
+ body{
22
+ width: 100%;
23
+ height: 100vh;
24
+ background-color: #33343f;
25
+ }
26
+
27
+ .chat{
28
+ display: flex;
29
+ gap: 20px;
30
+ padding: 25px;
31
+ color: #fff;
32
+ font-size: 15px;
33
+ font-weight: 300;
34
+ }
35
+
36
+ .chat img{
37
+ width: 35px;
38
+ height: 35px;
39
+ }
40
+
41
+ .response{
42
+ background-color: #494b59;
43
+ }
44
+
45
+ .messagebar{
46
+ position: fixed;
47
+ bottom: 0;
48
+ height: 5rem;
49
+ width: 100%;
50
+ display: flex;
51
+ align-items: center;
52
+ justify-content: center;
53
+ border-top: 1px solid #494b59;
54
+ background-color: #33343f;
55
+ }
56
+
57
+ .messagebar .bar-wrapper{
58
+ background-color: #494b59;
59
+ border-radius: 5px;
60
+ width: 60vw;
61
+ padding: 10px;
62
+ display: flex;
63
+ align-items: center;
64
+ justify-content: space-between;
65
+ }
66
+
67
+ .bar-wrapper input{
68
+ width: 100%;
69
+ padding: 5px;
70
+ border: none;
71
+ outline: none;
72
+ font-size: 14px;
73
+ background: none;
74
+ color: #ccc;
75
+ }
76
+
77
+ .bar-wrapper input::placeholder{
78
+ color: #ccc;
79
+ }
80
+
81
+ .messagebar button{
82
+ display: flex;
83
+ align-items: center;
84
+ justify-content: center;
85
+ background: none;
86
+ border: none;
87
+ color: #fff;
88
+ cursor: pointer;
89
+ }
90
+
91
+ .message-box{
92
+ height: calc(100vh - 5rem);
93
+ overflow-y: auto;
94
+ }
95
+ </style>
96
+ </head>
97
+ <body>
98
+ <div class="chatbox-wrapper">
99
+ <div class="message-box">
100
+ <div class="chat response">
101
+ <img src="img/chatbot.jpg">
102
+ <span>Hello there! <br>
103
+ How can I help you today.
104
+ </span>
105
+ </div>
106
+ </div>
107
+ <div class="messagebar">
108
+ <div class="bar-wrapper">
109
+ <input type="text" placeholder="Enter your message...">
110
+ <button>
111
+ <span class="material-symbols-rounded">
112
+ send
113
+ </span>
114
+ </button>
115
+ </div>
116
+ </div>
117
+ </div>
118
+
119
+ <script>
120
+ const messageBar = document.querySelector(".bar-wrapper input");
121
+ const sendBtn = document.querySelector(".bar-wrapper button");
122
+ const messageBox = document.querySelector(".message-box");
123
+
124
+ sendBtn.onclick = async function () {
125
+ if (messageBar.value.length > 0) {
126
+ const UserTypedMessage = messageBar.value;
127
+ messageBar.value = "";
128
+
129
+ let message =
130
+ `<div class="chat message">
131
+ <img src="img/user.jpg">
132
+ <span>
133
+ ${UserTypedMessage}
134
+ </span>
135
+ </div>`;
136
+
137
+ let response =
138
+ `<div class="chat response">
139
+ <img src="img/chatbot.jpg">
140
+ <span class="new">...
141
+ </span>
142
+ </div>`;
143
+
144
+ messageBox.insertAdjacentHTML("beforeend", message);
145
+ messageBox.insertAdjacentHTML("beforeend", response);
146
+
147
+ const responseElement = document.querySelector(".response .new");
148
+
149
+ const requestOptions = {
150
+ method: "POST",
151
+ headers: {
152
+ "Content-Type": "application/x-www-form-urlencoded"
153
+ },
154
+ body: new URLSearchParams({
155
+ prompt: UserTypedMessage,
156
+ history: "[]", // Assuming no history for now
157
+ })
158
+ };
159
+
160
+ try {
161
+ const res = await fetch("/generate/", requestOptions);
162
+ const reader = res.body.getReader();
163
+ const decoder = new TextDecoder();
164
+ let partialResponse = "";
165
+
166
+ while (true) {
167
+ const { value, done } = await reader.read();
168
+ if (done) break;
169
+ const chunk = decoder.decode(value);
170
+ if (chunk.includes("[DONE]")) break;
171
+ partialResponse += chunk;
172
+ responseElement.innerText = partialResponse;
173
+ }
174
+
175
+ responseElement.classList.remove("new");
176
+ } catch (error) {
177
+ console.error("Error:", error);
178
+ responseElement.innerText = "Oops! An error occurred. Please try again.";
179
+ responseElement.classList.remove("new");
180
+ }
181
+ }
182
+ };
183
+ </script>
184
+ </body>
185
+ </html>