-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
193 lines (168 loc) · 5.2 KB
/
Copy pathindex.html
File metadata and controls
193 lines (168 loc) · 5.2 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Chat UI Screen</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
font-size: 14px;
}
#jongwon_baek {
width: 500px;
height: 500px;
}
.chat-container {
max-width: 500px;
margin: 0 auto;
padding: 20px;
}
.chat-box {
background-color: #f2f2f2;
padding: 10px;
border-radius: 10px;
margin-bottom: 20px;
overflow-y: scroll;
height: 300px;
}
.chat-message {
background-color: #fff;
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
}
.chat-message p {
margin: 0;
padding: 0;
}
.chat-input {
display: flex;
margin-top: 20px;
}
.chat-input input {
flex: 1;
padding: 10px;
border: none;
border-radius: 5px;
margin-right: 10px;
}
.chat-input button {
background-color: #4caf50;
color: #fff;
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
}
.chat-input button:hover {
background-color: #3e8e41;
}
.assistant {
color: blue;
}
.intro-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.intro-container img {
width: 50%;
min-width: 300px;
}
#loader {
font-size: 25px;
text-align: center;
}
</style>
</head>
<body>
<div id="intro" class="intro-container">
<h1>백종원 선생님에게 물어보는 최상의 레시피</h1>
<img id="jongwon_baek" src="./백종원.jpg" alt="jongwon baek" />
<label for="cooking_skills">요리실력</label>
<select id="cooking_skills" name="cooking_skills">
<option value="fool">왕초보(거의 해본적 없음)</option>
<option value="notBad">초보(취미로 하는 수준)</option>
<option value="good">중수(요리로 돈을 버는 수준)</option>
<option value="veryGood">고수(쉐프급)</option>
</select>
<button onclick="start()">백선생님께 레시피 묻기</button>
</div>
<div id="chat" class="chat-container" style="display: none">
<div class="chat-box">
<div class="chat-message">
<p class="assistant">레시피에 대해서 물어봐 주세요!</p>
</div>
</div>
<div id="loader" class="loader" style="display: none">
<i class="fa fa-spinner fa-spin"></i>
</div>
<div class="chat-input">
<input type="text" placeholder="여기에 메세지를 입력해주세요..." />
<button id="btn" onclick="spinner()">Send</button>
</div>
</div>
<script>
const chatBox = document.querySelector(".chat-box");
let userMessages = [];
let assistantMessages = [];
let myDateTime = "";
function spinner() {
document.getElementById("loader").style.display = "block";
}
function start() {
const cooking_skills = document.getElementById("cooking_skills").value;
myDateTime = cooking_skills;
// document.getElementById("intro").style.display = "none";
document.getElementById("chat").style.display = "block";
}
const sendMessage = async () => {
const chatInput = document.querySelector(".chat-input input");
const chatMessage = document.createElement("div");
chatMessage.classList.add("chat-message");
chatMessage.innerHTML = `
<p>${chatInput.value}</p>
`;
chatBox.appendChild(chatMessage);
//userMessage 메세지 추가
userMessages.push(chatInput.value);
chatInput.value = "";
const response = await fetch("http://localhost:3000/fortuneTell", {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
body: JSON.stringify({
myDateTime: myDateTime,
userMessages: userMessages,
assistantMessages: assistantMessages,
}),
});
const data = await response.json();
document.getElementById("loader").style.display = "none";
//assistantMessage 메세지 추가
assistantMessages.push(data.assistant);
const astrologerMessage = document.createElement("div");
astrologerMessage.classList.add("chat-message");
astrologerMessage.innerHTML = `
<p class='assistant'>${data.assistant}</p>
`;
chatBox.appendChild(astrologerMessage);
};
document
.querySelector(".chat-input button")
.addEventListener("click", sendMessage);
</script>
</body>
</html>