-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAIPage.html
More file actions
178 lines (152 loc) · 5.44 KB
/
AIPage.html
File metadata and controls
178 lines (152 loc) · 5.44 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>chatGPT API</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
/* page-loading */
#loading {
width: 100%;
height: 100%;
top: 0;
left: 0;
position: fixed;
display: block;
opacity: 0.6;
background: #e4e4e4;
z-index: 99;
text-align: center;
}
#loading>img {
position: absolute;
top: 40%;
left: 45%;
z-index: 100;
}
#loading>p {
position: absolute;
top: 57%;
left: 43%;
z-index: 101;
}
/* Result box */
#result-box {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
max-height: 200px;
overflow-y: auto;
}
#chat-box {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
max-height: 300px;
overflow-y: auto;
white-space: pre-line;
}
.user-message {
background-color: #d3e0f8;
padding: 8px;
margin: 5px;
border-radius: 5px;
display: inline-block;
}
.assistant-message {
background-color: #f0f0f0;
padding: 8px;
margin: 5px;
border-radius: 5px;
display: inline-block;
}
</style>
<link rel="stylesheet" href="Style.css">
</head>
<body>
<header>
<h1>Make Your Beauty</h1>
<div class="button-container">
<a href="AIPage.html" class="navigation-button">AI Recommend</a>
<a href="Order.html" class="navigation-button">Order</a>
<a href="shareThings.html" class="navigation-button">Community</a>
<a href="mypage.html" class="navigation-button">MyPage</a>
</div>
</header>
<section class="main-section">
<h1><img src="images/Robot.png" width="25"> 화장품 추천해드립니다! <img src="images/Robot.png" width="25"></h1>
<label for="cosmeticType">추천받고 싶은 화장품 종류는</label>
<input type="text" id="cosmeticType" required />
<br>
<label for="favoriteColor">내가 선호하는 컬러는</label>
<input type="text" id="favoriteColor" required />
<br>
<label for="dislikedColor">내가 비선호하는 컬러는</label>
<input type="text" id="dislikedColor" required />
<br>
<label for="favoriteTexture">내가 좋아하는 텍스쳐는</label>
<input type="text" id="favoriteTexture" required />
<button onclick="chatGPT()">입력</button>
<div id="chat-box"></div>
<div id="loading">
<img src="https://studentrights.sen.go.kr/images/common/loading.gif">
</div>
</section>
<script>
$(document).ready(function () {
$('#loading').hide();
});
function chatGPT() {
const api_key = ""; // <- API KEY 입력
const cosmeticType = document.getElementById('cosmeticType').value;
const favoriteColor = document.getElementById('favoriteColor').value;
const dislikedColor = document.getElementById('dislikedColor').value;
const favoriteTexture = document.getElementById('favoriteTexture').value;
$('#loading').show();
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{
role: 'user',
content: `화장품을 추천받고 싶어. 추천받고 싶은 화장품 종류는 ${cosmeticType} 야.
내가 선호하는 컬러는 ${favoriteColor}고, 비선호하는 컬러는 ${dislikedColor}야.
${favoriteTexture} 같은 텍스쳐였으면 좋겠어. 몇 개 추천해줘 `
},
];
const data = {
model: 'gpt-3.5-turbo',
temperature: 0.5,
n: 1,
messages: messages,
};
$.ajax({
url: "https://api.openai.com/v1/chat/completions",
method: 'POST',
headers: {
Authorization: "Bearer " + api_key,
'Content-Type': 'application/json',
},
data: JSON.stringify(data),
}).then(function (response) {
$('#loading').hide();
console.log(response);
let chatBox = document.getElementById('chat-box');
// Display user message
let userMessage = document.createElement('div');
userMessage.className = 'user-message';
userMessage.innerHTML = cosmeticType + ', ' + favoriteColor + ', ' + dislikedColor + ', ' + favoriteTexture;
chatBox.appendChild(userMessage);
// Display assistant message
let assistantMessage = document.createElement('div');
assistantMessage.className = 'assistant-message';
assistantMessage.innerHTML = response.choices[0].message.content;
chatBox.appendChild(assistantMessage);
// Clear input fields
document.getElementById('cosmeticType').value = '';
document.getElementById('favoriteColor').value = '';
document.getElementById('dislikedColor').value = '';
document.getElementById('favoriteTexture').value = '';
});
}
</script>
</body>
</html>