-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
322 lines (300 loc) · 11.6 KB
/
index.html
File metadata and controls
322 lines (300 loc) · 11.6 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HanbatBot</title>
<style>
@keyframes slide-in {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f2f2f2;
transition: background-color 0.3s ease, color 0.3s ease; /* 다크 모드 전환 애니메이션 */
}
body.dark-mode {
background-color: #121212;
color: #ffffff;
}
.chat-container {
width: 600px;
height: 710px;
display: flex;
flex-direction: column;
border-radius: 20px;
box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
overflow: hidden;
background-color: #ebebeb;
transition: background-color 0.3s ease;
}
body.dark-mode .chat-container {
background-color: #1e1e1e;
}
.chat-header {
background-color: #000000;
color: rgb(255, 255, 255);
text-align: center;
padding: 15px;
font-size: 1.1em;
display: flex;
justify-content: space-between;
align-items: center;
}
body.dark-mode .chat-header {
background-color: #333333;
}
.chat-messages {
flex-grow: 1;
padding: 15px;
overflow-y: auto;
border-top: 1px solid #ffffff;
border-bottom: 1px solid #e0e0e0;
text-align: left;
display: flex;
flex-direction: column-reverse;
transition: background-color 0.3s ease;
/* 배경 이미지 추가 */
background-image: url('picture.jpg');
background-size: cover;
background-position: center;
position: relative;
}
body.dark-mode .chat-messages {
background-color: #2c2c2c;
border-color: #444444;
/* 배경 이미지 추가 */
background-image: url('picture_dark.jpg');
background-size: cover;
background-position: center;
position: relative;
}
.message {
margin: 10px 0;
padding: 10px 15px;
max-width: 70%;
word-wrap: break-word;
border-radius: 15px;
position: relative;
font-size: 0.95em;
border: 2px solid #ccc;
animation: slide-in 0.3s ease-in-out;
}
.user-message {
background-color: #e8f4fc;
align-self: flex-end;
color: #000000;
border-radius: 15px 15px 0 15px;
border: 2px solid #1e90ff;
}
body.dark-mode .user-message {
background-color: #375a7f;
color: #ffffff;
}
.bot-message {
background-color: #f9f9f9;
align-self: flex-start;
color: #000000;
border-radius: 15px 15px 15px 0;
border: 2px solid #ff8c00;
}
body.dark-mode .bot-message {
background-color: #444444;
color: #ffffff;
}
.chat-input {
display: flex;
padding: 15px;
border-top: 3px solid #000000;
background-color: #fafafa;
transition: background-color 0.3s ease;
}
body.dark-mode .chat-input {
background-color: #333333;
border-color: #444444;
}
.chat-input input {
flex-grow: 1;
padding: 15px;
border: 1px solid #000000;
border-radius: 8px;
font-size: 1em;
}
body.dark-mode .chat-input input {
background-color: #2c2c2c;
color: #ffffff;
}
.chat-input button {
background-color: #000000;
color: rgb(255, 255, 255);
border: none;
padding: 10px;
margin-left: 8px;
cursor: pointer;
border-radius: 8px;
font-size: 1.5em;
}
body.dark-mode .chat-input button {
background-color: #555555;
}
.stop-button:hover {
background-color: #ff3333; /* 마우스 올렸을 때 색상 변화 */
}
.loading-spinner {
display: flex;
justify-content: center;
align-items: center;
width: 20px;
height: 20px;
border: 3px solid rgba(0, 0, 0, 0.2);
border-top: 3px solid #000;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<b>국립한밭대학교</b>
<button id="theme-toggle"></button></button>
</div>
<div class="chat-messages" id="chat-messages">
<!-- 메시지 내용은 스크립트에서 추가 -->
</div>
<div class="chat-input">
<input type="text" id="chat-input" placeholder="메시지 ChatBPT" />
<button>↑</button>
<button class="stop-button" id="stop-button">STOP</button>
</div>
</div>
<script>
let typingInterrupted = false;
let isTyping = false;
let currentBotMessage = null;
document.getElementById("stop-button").addEventListener("click", () => {
typingInterrupted = true;
const chatMessages = document.getElementById("chat-messages");
const interruptionMessage = document.createElement("div");
interruptionMessage.classList.add("message", "bot-message");
interruptionMessage.textContent = "말을 끊어...? 두고 봐요...";
chatMessages.prepend(interruptionMessage);
});
// 테마 전환 기능
document.addEventListener("DOMContentLoaded", () => {
const body = document.body;
const themeToggle = document.getElementById("theme-toggle");
// 로컬 스토리지에서 테마 상태 로드
const savedTheme = localStorage.getItem("theme");
if (savedTheme === "dark") {
body.classList.add("dark-mode");
themeToggle.textContent = "☀️";
}
themeToggle.addEventListener("click", () => {
const isDarkMode = body.classList.toggle("dark-mode");
themeToggle.textContent = isDarkMode ? "☀️" : "🌙";
localStorage.setItem("theme", isDarkMode ? "dark" : "light");
});
});
document.getElementById("chat-input").addEventListener("keypress", function (e) {
if (e.key === "Enter") {
document.querySelector(".chat-input button").click();
}
});
// 타이핑 효과 함수 (HTML 태그와 텍스트 처리)
function typeMessage(element, message, speed) {
const tempDiv = document.createElement("div");
tempDiv.innerHTML = message; // 메시지를 HTML로 파싱
const nodes = Array.from(tempDiv.childNodes); // 텍스트와 태그를 분리
let index = 0;
function type() {
if (typingInterrupted) {
return;
}
if (index < nodes.length) {
const node = nodes[index];
if (node.nodeType === Node.TEXT_NODE) {
// 텍스트 노드 처리
const text = node.textContent;
let textIndex = 0;
function typeText() {
if (typingInterrupted) {
return;
}
if (textIndex < text.length) {
element.innerHTML += text.charAt(textIndex);
textIndex++;
setTimeout(typeText, speed);
} else {
index++;
type();
}
}
typeText();
} else {
// 태그 노드 처리 (HTML 태그는 즉시 추가)
element.appendChild(node.cloneNode(true));
index++;
type();
}
}
}
type();
}
document.querySelector(".chat-input button").addEventListener("click", async () => {
const inputField = document.getElementById("chat-input");
const messageText = inputField.value.trim();
if (messageText !== "") {
const chatMessages = document.getElementById("chat-messages");
// 사용자 메시지 출력
const userMessage = document.createElement("div");
userMessage.classList.add("message", "user-message");
userMessage.textContent = `${messageText}`;
chatMessages.prepend(userMessage);
inputField.value = "";
// 로딩 스피너 추가
const loadingMessage = document.createElement("div");
loadingMessage.classList.add("message", "bot-message");
const spinner = document.createElement("div");
spinner.classList.add("loading-spinner");
loadingMessage.appendChild(spinner);
chatMessages.prepend(loadingMessage);
// 챗봇의 응답을 받아오기
const response = await fetch('http://127.0.0.1:5000/message', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ message: messageText }),
});
const data = await response.json();
// 로딩 스피너 제거
chatMessages.removeChild(loadingMessage);
// 챗봇 메시지를 생성
const botMessage = document.createElement("div");
botMessage.classList.add("message", "bot-message");
// 타이핑 효과 시작
chatMessages.prepend(botMessage);
typingInterrupted = false; // 새 메시지를 입력하면 중단 상태 초기화
isTyping = true; // 타이핑 시작 상태로 설정
currentBotMessage = botMessage; // 현재 타이핑 중인 메시지 저장
typeMessage(botMessage, data.response, 50); // 타이핑 속도 설정
}
});
</script>
</body>
</html>