-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
254 lines (227 loc) · 8.58 KB
/
index.html
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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>레시피 추천해주는 챗요리</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 {
background-color: #f7f7f7;
font-family: 'Roboto', sans-serif;
}
.chat-container {
max-width: 600px;
margin: 0 auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
background-color: #fff;
}
.chat-header {
padding: 20px;
border-bottom: 1px solid #e6e6e6;
background-color: #f2f2f2;
text-align: center;
}
.chat-header h1 {
margin: 0;
font-size: 24px;
color: #333;
}
.chat-messages {
padding: 20px;
max-height: 400px;
overflow-y: auto;
}
.message {
margin-bottom: 10px;
}
.message .from {
font-weight: bold;
margin-bottom: 5px;
}
.message .text {
margin: 0;
}
.chat-input {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
border-top: 1px solid #e6e6e6;
}
.chat-input input[type="text"] {
flex-grow: 1;
margin-right: 10px;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
}
.chat-input button {
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: #333;
color: #fff;
font-size: 16px;
cursor: pointer;
}
.intro-container{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.intro-container img {
width: 50%;
min-width: 300px;
}
#loading {
font-size: 25px;
text-align: center;
}
.kakao-ad{
display:flex;
justify-content: center;
align-items: center;
margin-top: 20px;
min-width: 350px;
min-height: 200px;
}
</style>
</head>
<body>
<div id="intro" class="intro-container">
<h1>식사하셨나요?</h1>
<img src="cooker.png" alt="chatcooker">
<label for="calories">원하는 칼로리 선택</label>
<select name="calories" id="calories">
<option value="">상관없음.</option>
<option value="1000">1000 calories</option>
<option value="2000">2000 calories</option>
<option value="3000">3000 calories</option>
<option value="4000">4000 calories</option>
<option value="5000">5000 calories</option>
<option value="6000">6000 calories</option>
<option value="7000">7000 calories</option>
<option value="8000">8000 calories</option>
<option value="9000">9000 calories</option>
<option value="10000">10000 calories</option>
<option value="11000">11000 calories</option>
<option value="12000">12000 calories</option>
<option value="13000">13000 calories</option>
<option value="14000">14000 calories</option>
<option value="15000">15000 calories</option>
<option value="16000">16000 calories</option>
<option value="17000">17000 calories</option>
<option value="18000">18000 calories</option>
<option value="19000">19000 calories</option>
<option value="20000">20000 calories</option>
</select>
<label for="diet-select">다이어트 여부</label>
<select id="diet-select">
<option value="diet">다이어트중</option>
<option value="non-diet">마음 껏 먹기중</option>
</select>
<button onclick="start()">오늘의 식단 보기</button>
</div>
<div id="chat" class="chat-container" style="display: none;">
<div class="chat-header">
<h1>챗요리 - 레시피 추천 챗봇</h1>
</div>
<div class="chat-messages" id="chat-messages">
</div>
<div id="loading" style="display:none;">
<i class="fas fa-spinner fa-spin"></i>
</div>
<div class="chat-input">
<input type="text" id="input-message" placeholder="메시지를 입력하세요">
<button onclick="sendMessage()">보내기</button>
</div>
</div>
<div class ="kakao-ad">
<ins class="kakao_ad_area" style="display:none;"
data-ad-unit = "DAN-YbOmygHZMrNnvxS5"
data-ad-width = "320"
data-ad-height = "100">
</ins>
<script type="text/javascript" src="//t1.daumcdn.net/kas/static/ba.min.js" async></script>
</div>
<script>
let userMessage = [];
let assistantMessage = [];
let myCalories = '';
let myDiet='';
const chatMessages = document.getElementById("chat-messages");
const inputMessage = document.getElementById("input-message");
function start(){
const calories = document.getElementById('calories').value;
const diet = document.getElementById('diet-select').value;
if(diet===''){
alert('다이어트 유무를 입력해주세요');
return;
}
myCalories=calories;
myDiet=diet;
document.getElementById("intro").style.display="none";
document.getElementById("chat").style.display="block";
}
async function getRecipe() {
try {
const message = inputMessage.value;
const response = await fetch('https://hqteky8wy2.execute-api.ap-northeast-2.amazonaws.com/auspicious/recipeTell', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
myCalories:myCalories,
myDiet:myDiet,
userMessage: userMessage,
assistantMessage: assistantMessage
})
});
const data = await response.json();
document.getElementById('loading').style.display="none";
assistantMessage.push(data.assistant);
const messageHtml = `
<div class="message">
<p class="from">챗요리</p>
<p class="text">${data.assistant} \n <br>추가로 링크를 눌러 작은 정성을 배풀어 주시면 더욱 맛있는 음식을 드실 수 있게 노력하겠습니다. => <a href='https://toss.me/신나게신바람'>복체 보내기</a></p>
</div>
`;
chatMessages.insertAdjacentHTML("beforeend", messageHtml);
chatMessages.scrollTop = chatMessages.scrollHeight;
} catch (error) {
console.error(error);
}
}
function sendMessage() {
document.getElementById('loading').style.display="block";
const message = inputMessage.value;
if (!message) return;
const newMessage = `
<div class="message">
<p class="from">사용자</p>
<p class="text">${message}</p>
</div>
`;
chatMessages.insertAdjacentHTML("beforeend", newMessage);
chatMessages.scrollTop = chatMessages.scrollHeight;
//user message 추가
userMessage.push(message);
inputMessage.value = "";
// Get response from server and display
getRecipe();
}
// Press Enter key to send message
inputMessage.addEventListener("keyup", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("submit-button").click();
}
});
</script>
</body>
</html>