File size: 12,386 Bytes
ac08b84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ChatNBA</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        ::-webkit-scrollbar {
            width: 10px;
        }
        /* 對於滾動條的滑塊 */
        ::-webkit-scrollbar-thumb {
            background: #e0e0e0;
            border-radius: 20px; /* 橢圓的滑塊 */
        }
        /* 滾動條的滑塊滑過時的顏色 */
        ::-webkit-scrollbar-thumb:hover {
            background: #afafaf;
        }
        @keyframes dotPulse {
            0% { content: "." }
            33% { content: ".." }
            66% { content: "..." }
            100% { content: "...." }
        }
        .loading:after {
            animation: dotPulse 1s infinite;
            content: "";
        }
        .animate-fade-up {
            animation: fadeInUp .5s both;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translate3d(0, 100%, 0);
            }
            to {
                opacity: 1;
                transform: none;
            }
        }
        body {
            background-color: #ffffff;
            color: rgb(28, 32, 59);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            padding: 0;
        }
        .container {
            width: 100%; /* Adjust this for your preference */
            max-width: 1000px;
        }
        #chat {
            width: 100%;
            height: 400px;
            overflow: auto;
            margin: auto;
            position: relative;
        }
        #input {
            width: 90%; /* Adjust this for your preference */
            margin: 20px auto;
            box-shadow: 0px 3px 15px rgba(0,0,0,0.2); /* shadow for input */
        }
        .chat-entry {
            text-align: left;
            padding: 10px;
            border-radius: 15px;
        }
        .chat-entry img {
            height: 50px;
            width: 50px;
            object-fit: cover;
        }
        .btn-secondary {
            height: 40px;
        }
        .chat-entry-user {
            background-color: #fafeff;
        }
        .chat-entry-bot {
            background-color: #f8f7ff;
        }
        .chat-entry-user, .chat-entry-bot {
            display: flex;
            flex-direction: row;
            align-items: stretch;
            margin-bottom: 10px;
        }
        .chat-entry-user > div, .chat-entry-bot > div {
            margin-left: 10px;
            word-break: break-word;
        }
        h1 {
            text-align: center;
        }
        p {
            text-align: center;
        }
        h6 {
            color: #bbbbbb
        }
        h4{
            color:#555555
        }
        #intro-message {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        .loading {
            color: #aaaaaa;
        }
        .loading div:after {
            content: ' .';
            animation: dots 1s steps(5, end) infinite;
        }
        @keyframes dots {
            0%, 20% {
                color: rgba(0,0,0,0);
                text-shadow:
                    .25em 0 0 rgba(0,0,0,0),
                    .5em 0 0 rgba(0,0,0,0);}
            40% {
                color: white;
                text-shadow:
                    .25em 0 0 rgba(0,0,0,0),
                    .5em 0 0 rgba(0,0,0,0);}
            60% {
                text-shadow:
                    .25em 0 0 white,
                    .5em 0 0 rgba(0,0,0,0);}
            100% {
                text-shadow:
                    .25em 0 0 white,
                    .5em 0 0 white;}}
        @media (max-width: 600px) {
            #chat {
                height: 350px;
            }
        }
        .switch {
            position: relative;
            display: inline-block;
            width: 40px;
            height: 20px;
        }
        .switch input {
            opacity: 0;
            width: 0;
            height: 0;
        }
        .slider {
            position: absolute;
            cursor: pointer;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: #ccc;
            transition: .4s;
        }
        .slider:before {
            position: absolute;
            content: "";
            height: 16px;
            width: 16px;
            left: 2px;
            bottom: 2px;
            background-color: white;
            transition: .4s;
        }
        input:checked + .slider {
            background-color: #b4f0eb;
        }
        input:focus + .slider {
            box-shadow: 0 0 1px #b4f0eb;
        }
        input:checked + .slider:before {
            transform: translateX(20px);
        }
        .slider.round {
            border-radius: 34px;
        }
        .slider.round:before {
            border-radius: 50%;
        }
    </style>
   <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <!-- 引入完整的jQuery版本 -->
   <script>
        function submit() {
            var input = document.getElementById('input').value;
            document.getElementById('input').value = '';
            document.getElementById('intro-message').style.display = 'none';   
            var chat = document.getElementById('chat');
            var userEntry = document.createElement('div');
            userEntry.className = "chat-entry chat-entry-user animate-fade-up";;
    
            var userImg = document.createElement('img');
            userImg.src = "/static/icon/U.png";
    
            var userInput = document.createElement('div');
            userInput.textContent = input;
    
            userEntry.appendChild(userImg);
            userEntry.appendChild(userInput);
            chat.appendChild(userEntry);
            chat.scrollTop = chat.scrollHeight;
    
            // 創建bot回應的元素並添加到chat
            var botEntry = document.createElement('div');
            botEntry.className = "chat-entry chat-entry-bot loading";
            var botImg = document.createElement('img');
            botImg.src = "/static/icon/N.png";
            var botResponse = document.createElement('div');
            botResponse.textContent = "學長姐們努力查資料中";
    
            botEntry.appendChild(botImg);
            botEntry.appendChild(botResponse);
            chat.appendChild(botEntry);
    
            // 設定不同的訊息並每10秒輪換
            var messages = ["學長姐們正在用力查資料,請稍等片刻", "別逼我們啊~~我們快好了~~~QQQQQ","先別說這個了,你聽過楊老師嗎","NBA不是美國的NBA唷~這是奈米生醫材料應用實驗室的英文縮寫唷!"];
            var index = 0;
            function updateMessage() {
                botResponse.textContent = messages[index];
                index = (index + 1) % messages.length; // 更新索引,如果超過陣列長度,就重置為0
            }
    
            // 每10秒更新一次訊息
            var timer = setInterval(updateMessage, 10000);
            
            //新的呼叫方法(包含翻譯)
            $.ajax({
                url: '/get_response',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    user_input: input,
                    should_translate: $('#translationCheck').prop('checked'),
                    target_lang: 'zh-tw'
                }),
                success: function(response) {
                    clearTimeout(timer); // 收到回應後,取消定時器
                    botResponse.textContent = response.response;
                    botEntry.classList.remove('loading');
                    chat.scrollTop = chat.scrollHeight;
                }
            });
            // // 呼叫後端取得回應
            // fetch('/get_response', {
            //     method: 'POST',
            //     headers: {
            //         'Content-Type': 'application/json',
            //     },
            //     body: JSON.stringify({ user_input: input }),
            // })
            // .then(response => response.json())
            // .then(data => {
            //     clearTimeout(timer); // 收到回應後,取消定時器
            //     botResponse.textContent = data.response;
            //     botEntry.classList.remove('loading');
            //     chat.scrollTop = chat.scrollHeight;
            // });
        }
    </script>
    
    <!-- <script>
        function submit() {
            var input = document.getElementById('input').value;
            document.getElementById('input').value = '';
            var chat = document.getElementById('chat');
            var userEntry = document.createElement('div');
            userEntry.className = "chat-entry chat-entry-user animate-fade-up";
            var userImg = document.createElement('img');
            userImg.src = "/static/icon/U.png";
            var userInput = document.createElement('div');
            userInput.textContent = input;
            userEntry.appendChild(userImg);
            userEntry.appendChild(userInput);
            chat.appendChild(userEntry);
            setTimeout(function() {
                var botImg = document.createElement('img');
                botImg.src = "/static/icon/N.png";
                var botEntry = document.createElement('div');
                botEntry.className = "chat-entry chat-entry-bot loading";
                var botResponse = document.createElement('div');
                botResponse.textContent = "學長姐們努力查資料中";
                botEntry.appendChild(botImg);
                botEntry.appendChild(botResponse);
                chat.appendChild(botEntry);
                chat.scrollTop = chat.scrollHeight;
                fetch('/get_response', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ user_input: input }),
                })
                .then(response => response.json())
                .then(data => {
                    botResponse.textContent = data.response;
                    botEntry.classList.remove('loading');
                    chat.scrollTop = chat.scrollHeight;
                });
            }, 500); // 延遲500毫秒後再顯示 loading
        }
    </script> -->
</head>
<body>
    <div class="container">
        <div class="row justify-content-center">  <!-- Added a row with centered content -->
            <div class="col-lg-10 col-md-12 col-14">  <!--Adjusted column sizes for different screen sizes-->

    <div class="container">
        <h1>ChatNBA</h1>
        <h4><p>
        </p></h4>
        <div id="chat">
            <div id="intro-message">Wellcome to the ChatNBA! <br> Please enter your question below.👇<br> Then chat with your seniors 👨‍🎓👩‍🎓(and their thesis📖)! <br> Have fun!🚀<br>English question only, hahahahha~🖖<br><br>
                ❔What you can ask:<br>
        
                🧫cell culture<br>
                🧬DNAs/RNAs/Proteins<br>
                🧪Experiments<br>
                🔬sensors<br><br>


            </div>
        </div>
        <div class="input-group">
            <input id="input" type="text" class="form-control" placeholder="Send a question." onkeydown="if(event.key==='Enter')submit()">
        </div>
        <!-- <label class="switch">
            <input type="checkbox" id="translationCheck">
            <span class="slider round"></span>
          </label> Translate to Chinese, please~ -->
    </div>
    <h6><p>The ChatNBA model is still in training (like you) and may generate wrong response to your question. <br> ©Copyright 2023 Lab of Nano-Biomaterials Applications. All rights reserved. <br>ChatNBA(preview) ver. 0.0.1 <br> Designed by Hao-Han Pang, PhD</p></h6>
</div>
</div>
</div>
</body>
</html>