Ashrafb commited on
Commit
af2ea51
1 Parent(s): fcbd553

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +139 -118
static/index.html CHANGED
@@ -1,133 +1,154 @@
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>ChatGPT Interface</title>
7
- <style>
8
- body {
9
- font-family: Arial, sans-serif;
10
- display: flex;
11
- flex-direction: column;
12
- height: 100vh;
13
- margin: 0;
14
- background-color: #f7f7f8;
15
- }
16
- #chatbox {
17
- flex-grow: 1;
18
- padding: 20px;
19
- overflow-y: auto;
20
- border-bottom: 1px solid #ccc;
21
- background-color: #ffffff;
22
- }
23
- .message {
24
- margin: 10px 0;
25
- display: flex;
26
- }
27
- .user .message-content {
28
- background-color: #d1e7dd;
29
- align-self: flex-end;
30
- }
31
- .assistant .message-content {
32
- background-color: #f8d7da;
33
- align-self: flex-start;
34
- }
35
- .message-content {
36
- padding: 10px;
37
- border-radius: 10px;
38
- max-width: 80%;
39
- }
40
- #inputArea {
41
- display: flex;
42
- padding: 10px;
43
- border-top: 1px solid #ccc;
44
- background-color: #fff;
45
- }
46
- #inputArea input, #inputArea button {
47
- padding: 10px;
48
- font-size: 16px;
49
- }
50
- #inputArea input {
51
- flex-grow: 1;
52
- margin-right: 10px;
53
- }
54
- #config {
55
- display: none;
56
- padding: 10px;
57
- border-top: 1px solid #ccc;
58
- background-color: #fff;
59
- }
60
- #config input {
61
- width: 100%;
62
- padding: 10px;
63
- margin: 5px 0;
64
- }
65
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  </head>
67
  <body>
68
- <div id="chatbox"></div>
69
- <div id="inputArea">
70
- <input type="text" id="message" placeholder="Type a message">
71
- <button onclick="sendMessage()">Send</button>
 
 
72
  </div>
73
- <div id="config">
74
- <label for="systemMessage">System message:</label>
75
- <input type="text" id="systemMessage" value="You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.">
76
- <label for="maxTokens">Max new tokens:</label>
77
- <input type="number" id="maxTokens" value="2000" min="1" max="2048" step="1">
78
- <label for="temperature">Temperature:</label>
79
- <input type="number" id="temperature" value="0.7" min="0.1" max="4.0" step="0.1">
80
- <label for="topP">Top-p (nucleus sampling):</label>
81
- <input type="number" id="topP" value="0.95" min="0.1" max="1.0" step="0.05">
82
  </div>
 
 
 
 
 
83
 
84
- <script>
85
- let history = [];
 
 
86
 
87
- function appendMessage(role, content) {
88
- const chatbox = document.getElementById('chatbox');
89
- const messageDiv = document.createElement('div');
90
- messageDiv.classList.add(role, 'message');
91
- const contentDiv = document.createElement('div');
92
- contentDiv.classList.add('message-content');
93
- contentDiv.textContent = content;
94
- messageDiv.appendChild(contentDiv);
95
- chatbox.appendChild(messageDiv);
96
- chatbox.scrollTop = chatbox.scrollHeight;
97
- }
98
 
99
- async function sendMessage() {
100
- const messageInput = document.getElementById('message');
101
- const message = messageInput.value;
102
- const systemMessage = document.getElementById('systemMessage').value;
103
- const maxTokens = parseInt(document.getElementById('maxTokens').value);
104
- const temperature = parseFloat(document.getElementById('temperature').value);
105
- const topP = parseFloat(document.getElementById('topP').value);
106
 
107
- appendMessage('user', message);
108
- history.push([message, null]);
109
 
110
- const response = await fetch('/chat', {
111
- method: 'POST',
112
- headers: {
113
- 'Content-Type': 'application/json'
114
- },
115
- body: JSON.stringify({
116
- message: message,
117
- history: history,
118
- system_message: systemMessage,
119
- max_tokens: maxTokens,
120
- temperature: temperature,
121
- top_p: topP
122
- })
123
- });
124
 
125
- const data = await response.json();
126
- appendMessage('assistant', data.response);
127
- history[history.length - 1][1] = data.response;
128
-
129
- messageInput.value = '';
130
- }
131
- </script>
 
 
 
 
 
 
 
 
 
132
  </body>
133
  </html>
 
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>Document</title>
13
+ <style>
14
+ * {
15
+ padding: 0;
16
+ margin: 0;
17
+ font-family: 'Poppins', sans-serif;
18
+ box-sizing: border-box;
19
+ }
20
+ body {
21
+ width: 100%;
22
+ height: 100vh;
23
+ background-color: #33343f;
24
+ }
25
+ .chat {
26
+ display: flex;
27
+ gap: 20px;
28
+ padding: 25px;
29
+ color: #fff;
30
+ font-size: 15px;
31
+ font-weight: 300;
32
+ }
33
+ .chat img {
34
+ width: 35px;
35
+ height: 35px;
36
+ }
37
+ .response {
38
+ background-color: #494b59;
39
+ }
40
+ .messagebar {
41
+ position: fixed;
42
+ bottom: 0;
43
+ height: 5rem;
44
+ width: 100%;
45
+ display: flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ border-top: 1px solid #494b59;
49
+ background-color: #33343f;
50
+ }
51
+ .messagebar .bar-wrapper {
52
+ background-color: #494b59;
53
+ border-radius: 5px;
54
+ width: 60vw;
55
+ padding: 10px;
56
+ display: flex;
57
+ align-items: center;
58
+ justify-content: space-between;
59
+ }
60
+ .bar-wrapper input {
61
+ width: 100%;
62
+ padding: 5px;
63
+ border: none;
64
+ outline: none;
65
+ font-size: 14px;
66
+ background: none;
67
+ color: #ccc;
68
+ }
69
+ .bar-wrapper input::placeholder {
70
+ color: #ccc;
71
+ }
72
+ .messagebar button {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ background: none;
77
+ border: none;
78
+ color: #fff;
79
+ cursor: pointer;
80
+ }
81
+ .message-box {
82
+ height: calc(100vh - 5rem);
83
+ overflow-y: auto;
84
+ }
85
+ </style>
86
  </head>
87
  <body>
88
+ <div class="chatbox-wrapper">
89
+ <div class="message-box">
90
+ <div class="chat response">
91
+ <img src="img/chatbot.jpg">
92
+ <span>Hello there! <br> How can I help you today.</span>
93
+ </div>
94
  </div>
95
+ <div class="messagebar">
96
+ <div class="bar-wrapper">
97
+ <input type="text" placeholder="Enter your message...">
98
+ <button>
99
+ <span class="material-symbols-rounded">send</span>
100
+ </button>
101
+ </div>
 
 
102
  </div>
103
+ </div>
104
+ <script>
105
+ const messageBar = document.querySelector(".bar-wrapper input");
106
+ const sendBtn = document.querySelector(".bar-wrapper button");
107
+ const messageBox = document.querySelector(".message-box");
108
 
109
+ sendBtn.onclick = async function () {
110
+ if (messageBar.value.length > 0) {
111
+ const UserTypedMessage = messageBar.value;
112
+ messageBar.value = "";
113
 
114
+ let message = `<div class="chat message"><img src="img/user.jpg"><span>${UserTypedMessage}</span></div>`;
115
+ let response = `<div class="chat response"><img src="img/chatbot.jpg"><span class="new">...</span></div>`;
 
 
 
 
 
 
 
 
 
116
 
117
+ messageBox.insertAdjacentHTML("beforeend", message);
 
 
 
 
 
 
118
 
119
+ setTimeout(async () => {
120
+ messageBox.insertAdjacentHTML("beforeend", response);
121
 
122
+ const requestOptions = {
123
+ method: "POST",
124
+ headers: {
125
+ "Content-Type": "application/x-www-form-urlencoded"
126
+ },
127
+ body: new URLSearchParams({
128
+ prompt: UserTypedMessage,
129
+ history: "[]",
130
+ temperature: "0.9",
131
+ max_new_tokens: "512",
132
+ top_p: "0.95",
133
+ repetition_penalty: "1.0"
134
+ })
135
+ };
136
 
137
+ try {
138
+ const res = await fetch("/generate/", requestOptions);
139
+ const data = await res.json();
140
+ const ChatBotResponse = document.querySelector(".response .new");
141
+ ChatBotResponse.innerText = data.response;
142
+ ChatBotResponse.classList.remove("new");
143
+ } catch (error) {
144
+ console.error("Error:", error);
145
+ const ChatBotResponse = document.querySelector(".response .new");
146
+ ChatBotResponse.innerText = "Oops! An error occurred. Please try again.";
147
+ ChatBotResponse.classList.remove("new");
148
+ }
149
+ }, 100);
150
+ }
151
+ };
152
+ </script>
153
  </body>
154
  </html>