CSNET commited on
Commit
8bbd13a
·
verified ·
1 Parent(s): 7e36967

ช่วยทำเว็บแอพ พี่สามารถถ่ายรูปตัวเอง โดยใช้การเปิดกล้องเท่านั้น และอัพโหลดรูปเข้าไปที่ ChatGPT ผ่าน API key เพื่อที่จะแปลงรูปตัวเอง ให้เป็นรูปคนที่หุ่นดี fit & firm ได้ ทั้งเพศหญิง และเพศชาย โดยที่หน้าไม่เปลี่ยน แต่เปลี่ยนหุ่น และชุดเป็นชุดฟิตเนส เน้นถึงกล้ามท้อง และสัดส่วนที่เหมาะสมกับคนออกกำลังกายเป็นอย่างดี

Browse files

ตัวอย่าง prompt สำหรับเรียก chatgpt เพื่อแปลงรูป Transform the body to a healthy, athletic "%%LEVEL%%" physique while preserving the original face identity.
Keep natural skin tone consistency, realistic muscle definition (focus on abs and overall proportion),
and replace outfit with tasteful modern fitness wear appropriate for "%%GENDER%%".
Avoid nudity; keep the style photorealistic and respectful.

Files changed (6) hide show
  1. README.md +8 -5
  2. components/header.js +50 -0
  3. components/navbar.js +104 -0
  4. index.html +240 -19
  5. script.js +275 -0
  6. style.css +97 -19
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Fittransform Pro
3
- emoji: 💻
4
- colorFrom: indigo
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: FitTransform Pro 💪
3
+ colorFrom: purple
4
+ colorTo: pink
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
components/header.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomHeader extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ header {
7
+ background: linear-gradient(135deg, #10b981 0%, #059669 50%, #f97316 100%);
8
+ color: white;
9
+ padding: 1rem 0;
10
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
11
+ }
12
+ .container {
13
+ max-width: 1200px;
14
+ margin: 0 auto;
15
+ padding: 0 1rem;
16
+ display: flex;
17
+ justify-content: space-between;
18
+ align-items: center;
19
+ }
20
+ .logo {
21
+ display: flex;
22
+ align-items: center;
23
+ font-size: 1.5rem;
24
+ font-weight: bold;
25
+ text-decoration: none;
26
+ color: white;
27
+ }
28
+ .logo:hover {
29
+ transform: scale(1.05);
30
+ }
31
+ .logo-icon {
32
+ margin-right: 0.5rem;
33
+ font-size: 2rem;
34
+ }
35
+ </style>
36
+ <header>
37
+ <div class="container">
38
+ <a href="#" class="logo">
39
+ <span class="logo-icon">💪</span>
40
+ FitTransform Pro
41
+ </a>
42
+ <div>
43
+ <span style="font-size: 0.9rem; opacity: 0.9;">AI Body Transformation</span>
44
+ </div>
45
+ </div>
46
+ </header>
47
+ `;
48
+ }
49
+ }
50
+ customElements.define('custom-header', CustomHeader);
components/navbar.js ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomNavbar extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ nav {
7
+ background: white;
8
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
9
+ position: sticky;
10
+ top: 0;
11
+ z-index: 100;
12
+ }
13
+ .nav-container {
14
+ max-width: 1200px;
15
+ margin: 0 auto;
16
+ padding: 0 1rem;
17
+ }
18
+ .nav-links {
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ gap: 2rem;
23
+ padding: 1rem 0;
24
+ flex-wrap: wrap;
25
+ }
26
+ .nav-link {
27
+ display: flex;
28
+ align-items: center;
29
+ padding: 0.5rem 1rem;
30
+ border-radius: 0.5rem;
31
+ text-decoration: none;
32
+ color: #4b5563;
33
+ font-weight: 500;
34
+ transition: all 0.3s ease;
35
+ }
36
+ .nav-link:hover {
37
+ background: linear-gradient(135deg, #10b981 0%, #f97316 100%);
38
+ color: white;
39
+ transform: translateY(-2px);
40
+ }
41
+ .nav-link.active {
42
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
43
+ color: white;
44
+ }
45
+ @media (max-width: 640px) {
46
+ .nav-links {
47
+ gap: 1rem;
48
+ }
49
+ .nav-link {
50
+ padding: 0.4rem 0.8rem;
51
+ font-size: 0.9rem;
52
+ }
53
+ }
54
+ </style>
55
+ <nav>
56
+ <div class="nav-container">
57
+ <div class="nav-links">
58
+ <a href="#capture" class="nav-link active">
59
+ <i data-feather="camera" style="width: 18px; height: 18px; margin-right: 5px;"></i>
60
+ ถ่ายรูป
61
+ </a>
62
+ <a href="#transform" class="nav-link">
63
+ <i data-feather="zap" style="width: 18px; height: 18px; margin-right: 5px;"></i>
64
+ แปลงรูป
65
+ </a>
66
+ <a href="#compare" class="nav-link">
67
+ <i data-feather="layers" style="width: 18px; height: 18px; margin-right: 5px;"></i>
68
+ เปรียบเทียบ
69
+ </a>
70
+ <a href="#download" class="nav-link">
71
+ <i data-feather="download" style="width: 18px; height: 18px; margin-right: 5px;"></i>
72
+ ดาวน์โหลด
73
+ </a>
74
+ </div>
75
+ </div>
76
+ </nav>
77
+ `;
78
+
79
+ // Add smooth scroll behavior
80
+ this.shadowRoot.querySelectorAll('.nav-link').forEach(link => {
81
+ link.addEventListener('click', (e) => {
82
+ e.preventDefault();
83
+ const targetId = link.getAttribute('href').substring(1);
84
+ const targetElement = document.querySelector(`[id*="${targetId.toLowerCase()}"]`);
85
+
86
+ if (targetElement) {
87
+ // Remove active class from all links
88
+ this.shadowRoot.querySelectorAll('.nav-link').forEach(l => l.classList.remove('active'));
89
+ // Add active class to clicked link
90
+ link.classList.add('active');
91
+
92
+ // Smooth scroll to element
93
+ targetElement.scrollIntoView({ behavior: 'smooth', block: 'center' });
94
+ }
95
+ });
96
+ });
97
+
98
+ // Re-initialize feather icons
99
+ if (typeof feather !== 'undefined') {
100
+ feather.replace();
101
+ }
102
+ }
103
+ }
104
+ customElements.define('custom-navbar', CustomNavbar);
index.html CHANGED
@@ -1,19 +1,240 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="th">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>FitTransform Pro - แปลงรูปเป็นหุ่นฟิตแอนด์เฟิร์ม</title>
7
+ <link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>💪</text></svg>">
8
+ <link rel="stylesheet" href="style.css">
9
+ <script src="https://cdn.tailwindcss.com"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
11
+ <script src="https://unpkg.com/feather-icons"></script>
12
+ <script>
13
+ tailwind.config = {
14
+ theme: {
15
+ extend: {
16
+ colors: {
17
+ primary: {
18
+ 50: '#ecfdf5',
19
+ 100: '#d1fae5',
20
+ 200: '#a7f3d0',
21
+ 300: '#6ee7b7',
22
+ 400: '#34d399',
23
+ 500: '#10b981',
24
+ 600: '#059669',
25
+ 700: '#047857',
26
+ 800: '#065f46',
27
+ 900: '#064e3b',
28
+ },
29
+ secondary: {
30
+ 50: '#fff7ed',
31
+ 100: '#ffedd5',
32
+ 200: '#fed7aa',
33
+ 300: '#fdba74',
34
+ 400: '#fb923c',
35
+ 500: '#f97316',
36
+ 600: '#ea580c',
37
+ 700: '#c2410c',
38
+ 800: '#9a3412',
39
+ 900: '#7c2d12',
40
+ }
41
+ }
42
+ }
43
+ }
44
+ }
45
+ </script>
46
+ </head>
47
+ <body class="bg-gradient-to-br from-gray-50 to-gray-100 min-h-screen">
48
+ <custom-header></custom-header>
49
+ <custom-navbar></custom-navbar>
50
+
51
+ <main class="container mx-auto px-4 py-8 max-w-6xl">
52
+ <!-- Hero Section -->
53
+ <section class="text-center mb-12">
54
+ <h1 class="text-4xl md:text-5xl font-bold bg-gradient-to-r from-primary-600 to-secondary-600 bg-clip-text text-transparent mb-4">
55
+ แปลงรูปเป็นหุ่นฟิตแอนด์เฟิร์ม
56
+ </h1>
57
+ <p class="text-gray-600 text-lg">ถ่ายรูปและแปลงร่างกายของคุณให้ดูแข็งแกร่ง สมส่วน พร้อมชุดฟิตเนสสุดเท่</p>
58
+ </section>
59
+
60
+ <!-- Main Content -->
61
+ <div class="grid lg:grid-cols-2 gap-8">
62
+ <!-- Camera Section -->
63
+ <section class="bg-white rounded-2xl shadow-xl p-6">
64
+ <h2 class="text-2xl font-semibold text-gray-800 mb-6 flex items-center">
65
+ <i data-feather="camera" class="mr-2 text-primary-600"></i>
66
+ ถ่ายรูปของคุณ
67
+ </h2>
68
+
69
+ <div class="space-y-4">
70
+ <!-- Video Preview -->
71
+ <div class="relative bg-gray-100 rounded-lg overflow-hidden" style="aspect-ratio: 4/5;">
72
+ <video id="video" class="w-full h-full object-cover hidden" autoplay></video>
73
+ <canvas id="canvas" class="w-full h-full object-cover hidden"></canvas>
74
+ <div id="placeholder" class="w-full h-full flex flex-col items-center justify-center text-gray-400">
75
+ <i data-feather="camera" class="w-16 h-16 mb-4"></i>
76
+ <p class="text-center px-4">คลิก "เปิดกล้อง" เพื่อเริ่มต้น</p>
77
+ </div>
78
+ </div>
79
+
80
+ <!-- Camera Controls -->
81
+ <div class="flex gap-3">
82
+ <button id="startCamera" class="flex-1 bg-primary-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-primary-700 transition-all transform hover:scale-105 shadow-lg">
83
+ <i data-feather="camera" class="inline mr-2 w-5 h-5"></i>
84
+ เปิดกล้อง
85
+ </button>
86
+ <button id="capturePhoto" class="flex-1 bg-secondary-600 text-white px-6 py-3 rounded-lg font-semibold hover:bg-secondary-700 transition-all transform hover:scale-105 shadow-lg disabled:opacity-50 disabled:cursor-not-allowed" disabled>
87
+ <i data-feather="aperture" class="inline mr-2 w-5 h-5"></i>
88
+ ถ่ายรูป
89
+ </button>
90
+ </div>
91
+ </div>
92
+
93
+ <!-- Settings -->
94
+ <div class="mt-6 space-y-4">
95
+ <div>
96
+ <label class="block text-sm font-medium text-gray-700 mb-2">เพศ</label>
97
+ <div class="grid grid-cols-2 gap-3">
98
+ <button class="gender-btn px-4 py-3 rounded-lg border-2 border-gray-300 hover:border-primary-500 transition-all" data-gender="male">
99
+ <i data-feather="user" class="inline mr-2"></i>
100
+ ชาย
101
+ </button>
102
+ <button class="gender-btn px-4 py-3 rounded-lg border-2 border-gray-300 hover:border-primary-500 transition-all" data-gender="female">
103
+ <i data-feather="user" class="inline mr-2"></i>
104
+ หญิง
105
+ </button>
106
+ </div>
107
+ </div>
108
+
109
+ <div>
110
+ <label class="block text-sm font-medium text-gray-700 mb-2">ระดับความฟิต</label>
111
+ <select id="fitnessLevel" class="w-full px-4 py-3 rounded-lg border-2 border-gray-300 focus:border-primary-500 transition-all">
112
+ <option value="beginner">เริ่มต้น (กำหนดการเริ่มต้น)</option>
113
+ <option value="intermediate" selected>ปานกลาง (กล้ามเนื้อชัดเจน)</option>
114
+ <option value="advanced">ขั้นสูง (นักกีฬามืออาชีพ)</option>
115
+ <option value="extreme">สุดขั้ว (บอดี้บิลเดอร์)</option>
116
+ </select>
117
+ </div>
118
+
119
+ <div>
120
+ <label class="block text-sm font-medium text-gray-700 mb-2">API Key (OpenAI)</label>
121
+ <input type="password" id="apiKey" placeholder="ใส่ API Key ของคุณ" class="w-full px-4 py-3 rounded-lg border-2 border-gray-300 focus:border-primary-500 transition-all">
122
+ <p class="text-xs text-gray-500 mt-1">API Key ของคุณจะถูกเก็บไว้ในเครื่องเท่านั้น</p>
123
+ </div>
124
+ </div>
125
+ </section>
126
+
127
+ <!-- Result Section -->
128
+ <section class="bg-white rounded-2xl shadow-xl p-6">
129
+ <h2 class="text-2xl font-semibold text-gray-800 mb-6 flex items-center">
130
+ <i data-feather="image" class="mr-2 text-secondary-600"></i>
131
+ ผลลัพธ์
132
+ </h2>
133
+
134
+ <!-- Before/After Comparison -->
135
+ <div class="space-y-4">
136
+ <div class="relative bg-gray-100 rounded-lg overflow-hidden" style="aspect-ratio: 4/5;">
137
+ <img id="originalImage" class="w-full h-full object-cover hidden" alt="Original">
138
+ <img id="transformedImage" class="w-full h-full object-cover hidden" alt="Transformed">
139
+ <div id="resultPlaceholder" class="w-full h-full flex flex-col items-center justify-center text-gray-400">
140
+ <i data-feather="image" class="w-16 h-16 mb-4"></i>
141
+ <p class="text-center px-4">รูปภาพที่แปลงแล้วจะปรากฏที่นี่</p>
142
+ </div>
143
+ </div>
144
+
145
+ <!-- Comparison Slider -->
146
+ <div id="comparisonContainer" class="hidden relative bg-gray-100 rounded-lg overflow-hidden" style="aspect-ratio: 4/5;">
147
+ <div class="absolute inset-0">
148
+ <img id="compareOriginal" class="absolute inset-0 w-full h-full object-cover">
149
+ <div id="compareTransformedWrapper" class="absolute inset-0 overflow-hidden" style="width: 50%;">
150
+ <img id="compareTransformed" class="absolute inset-0 w-full h-full object-cover" style="min-width: 200%;">
151
+ </div>
152
+ </div>
153
+ <div id="slider" class="absolute top-0 bottom-0 w-1 bg-white cursor-ew-resize" style="left: 50%;">
154
+ <div class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 bg-white rounded-full p-2 shadow-lg">
155
+ <i data-feather="chevron-left-right" class="w-5 h-5"></i>
156
+ </div>
157
+ </div>
158
+ </div>
159
+
160
+ <!-- Action Buttons -->
161
+ <div class="flex gap-3">
162
+ <button id="transformBtn" class="flex-1 bg-gradient-to-r from-primary-600 to-secondary-600 text-white px-6 py-3 rounded-lg font-semibold hover:shadow-lg transition-all transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed" disabled>
163
+ <i data-feather="zap" class="inline mr-2 w-5 h-5"></i>
164
+ แปลงรูป
165
+ </button>
166
+ <button id="downloadBtn" class="flex-1 bg-gray-700 text-white px-6 py-3 rounded-lg font-semibold hover:bg-gray-800 transition-all transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed hidden">
167
+ <i data-feather="download" class="inline mr-2 w-5 h-5"></i>
168
+ ดาวน์โหลด
169
+ </button>
170
+ </div>
171
+
172
+ <!-- Loading Indicator -->
173
+ <div id="loadingIndicator" class="hidden">
174
+ <div class="flex items-center justify-center py-8">
175
+ <div class="animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600"></div>
176
+ <span class="ml-3 text-gray-600">กำลังแปลงรูป...</span>
177
+ </div>
178
+ </div>
179
+
180
+ <!-- Success Message -->
181
+ <div id="successMessage" class="hidden bg-green-50 border-2 border-green-200 rounded-lg p-4">
182
+ <div class="flex items-center">
183
+ <i data-feather="check-circle" class="text-green-600 mr-3"></i>
184
+ <p class="text-green-800">แปลงรูปสำเร็จ! คุณสามารถดาวน์โหลดภาพได้</p>
185
+ </div>
186
+ </div>
187
+
188
+ <!-- Error Message -->
189
+ <div id="errorMessage" class="hidden bg-red-50 border-2 border-red-200 rounded-lg p-4">
190
+ <div class="flex items-center">
191
+ <i data-feather="alert-circle" class="text-red-600 mr-3"></i>
192
+ <p class="text-red-800" id="errorText">เกิดข้อผิดพลาด กรุณาลองใหม่</p>
193
+ </div>
194
+ </div>
195
+ </div>
196
+ </section>
197
+ </div>
198
+
199
+ <!-- Features Section -->
200
+ <section class="mt-16 grid md:grid-cols-3 gap-6">
201
+ <div class="bg-white rounded-xl p-6 text-center shadow-lg hover:shadow-xl transition-shadow">
202
+ <div class="w-16 h-16 bg-primary-100 rounded-full flex items-center justify-center mx-auto mb-4">
203
+ <i data-feather="shield" class="text-primary-600 w-8 h-8"></i>
204
+ </div>
205
+ <h3 class="font-semibold text-lg mb-2">ป้องกันใบหน้า</h3>
206
+ <p class="text-gray-600 text-sm">รักษาความเป็นตัวตนของใบหน้าไว้ แปลงเฉพาะร่างกาย</p>
207
+ </div>
208
+ <div class="bg-white rounded-xl p-6 text-center shadow-lg hover:shadow-xl transition-shadow">
209
+ <div class="w-16 h-16 bg-secondary-100 rounded-full flex items-center justify-center mx-auto mb-4">
210
+ <i data-feather="trending-up" class="text-secondary-600 w-8 h-8"></i>
211
+ </div>
212
+ <h3 class="font-semibold text-lg mb-2">หลากหลายระดับ</h3>
213
+ <p class="text-gray-600 text-sm">เลือกระดับความฟิตตั้งแต่เริ่มต้นถึงขั้นสูง</p>
214
+ </div>
215
+ <div class="bg-white rounded-xl p-6 text-center shadow-lg hover:shadow-xl transition-shadow">
216
+ <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
217
+ <i data-feather="lock" class="text-purple-600 w-8 h-8"></i>
218
+ </div>
219
+ <h3 class="font-semibold text-lg mb-2">ความเป็นส่วนตัว</h3>
220
+ <p class="text-gray-600 text-sm">API Key ถูกเก็บไว้ในเครื่อง ไม่มีการส่งข้อมูลไปที่อื่น</p>
221
+ </div>
222
+ </section>
223
+ </main>
224
+
225
+ <!-- Footer -->
226
+ <footer class="mt-16 bg-gray-900 text-white py-8">
227
+ <div class="container mx-auto px-4 text-center">
228
+ <p class="mb-2">FitTransform Pro 💪 - แปลงรูปเป็นหุ่นฟิตแอน��์เฟิร์ม</p>
229
+ <p class="text-gray-400 text-sm">ใช้เทคโนโลยี AI จาก OpenAI | สนับสนุนทั้งเพศชายและหญิง</p>
230
+ </div>
231
+ </footer>
232
+
233
+ <!-- Scripts -->
234
+ <script src="components/header.js"></script>
235
+ <script src="components/navbar.js"></script>
236
+ <script src="script.js"></script>
237
+ <script>feather.replace();</script>
238
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
239
+ </body>
240
+ </html>
script.js ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let stream = null;
2
+ let selectedGender = null;
3
+ let capturedImageData = null;
4
+
5
+ // DOM Elements
6
+ const video = document.getElementById('video');
7
+ const canvas = document.getElementById('canvas');
8
+ const placeholder = document.getElementById('placeholder');
9
+ const startCameraBtn = document.getElementById('startCamera');
10
+ const capturePhotoBtn = document.getElementById('capturePhoto');
11
+ const transformBtn = document.getElementById('transformBtn');
12
+ const downloadBtn = document.getElementById('downloadBtn');
13
+ const originalImage = document.getElementById('originalImage');
14
+ const transformedImage = document.getElementById('transformedImage');
15
+ const resultPlaceholder = document.getElementById('resultPlaceholder');
16
+ const loadingIndicator = document.getElementById('loadingIndicator');
17
+ const successMessage = document.getElementById('successMessage');
18
+ const errorMessage = document.getElementById('errorMessage');
19
+ const errorText = document.getElementById('errorText');
20
+ const comparisonContainer = document.getElementById('comparisonContainer');
21
+ const apiKeyInput = document.getElementById('apiKey');
22
+ const fitnessLevel = document.getElementById('fitnessLevel');
23
+
24
+ // Gender selection
25
+ document.querySelectorAll('.gender-btn').forEach(btn => {
26
+ btn.addEventListener('click', function() {
27
+ document.querySelectorAll('.gender-btn').forEach(b => b.classList.remove('active'));
28
+ this.classList.add('active');
29
+ selectedGender = this.dataset.gender;
30
+ checkTransformReady();
31
+ });
32
+ });
33
+
34
+ // Start Camera
35
+ startCameraBtn.addEventListener('click', async () => {
36
+ try {
37
+ stream = await navigator.mediaDevices.getUserMedia({
38
+ video: {
39
+ facingMode: 'user',
40
+ width: { ideal: 1280 },
41
+ height: { ideal: 1600 }
42
+ }
43
+ });
44
+ video.srcObject = stream;
45
+ video.classList.remove('hidden');
46
+ placeholder.classList.add('hidden');
47
+ capturePhotoBtn.disabled = false;
48
+ startCameraBtn.innerHTML = '<i data-feather="camera-off" class="inline mr-2 w-5 h-5"></i>ปิดกล้อง';
49
+ startCameraBtn.onclick = stopCamera;
50
+ video.parentElement.classList.add('camera-active');
51
+ feather.replace();
52
+ } catch (err) {
53
+ showError('ไม่สามารถเข้าถึงกล้องได้: ' + err.message);
54
+ }
55
+ });
56
+
57
+ // Stop Camera
58
+ function stopCamera() {
59
+ if (stream) {
60
+ stream.getTracks().forEach(track => track.stop());
61
+ stream = null;
62
+ }
63
+ video.classList.add('hidden');
64
+ placeholder.classList.remove('hidden');
65
+ capturePhotoBtn.disabled = true;
66
+ startCameraBtn.innerHTML = '<i data-feather="camera" class="inline mr-2 w-5 h-5"></i>เปิดกล้อง';
67
+ startCameraBtn.onclick = () => startCameraBtn.click();
68
+ video.parentElement.classList.remove('camera-active');
69
+ feather.replace();
70
+ }
71
+
72
+ // Capture Photo
73
+ capturePhotoBtn.addEventListener('click', () => {
74
+ canvas.width = video.videoWidth;
75
+ canvas.height = video.videoHeight;
76
+ const ctx = canvas.getContext('2d');
77
+ ctx.drawImage(video, 0, 0);
78
+
79
+ capturedImageData = canvas.toDataURL('image/jpeg', 0.95);
80
+ originalImage.src = capturedImageData;
81
+ originalImage.classList.remove('hidden');
82
+ resultPlaceholder.classList.add('hidden');
83
+
84
+ stopCamera();
85
+ checkTransformReady();
86
+
87
+ // Show capture animation
88
+ canvas.style.display = 'block';
89
+ setTimeout(() => {
90
+ canvas.style.display = 'none';
91
+ }, 500);
92
+ });
93
+
94
+ // Check if ready to transform
95
+ function checkTransformReady() {
96
+ if (capturedImageData && selectedGender && apiKeyInput.value.trim()) {
97
+ transformBtn.disabled = false;
98
+ } else {
99
+ transformBtn.disabled = true;
100
+ }
101
+ }
102
+
103
+ apiKeyInput.addEventListener('input', checkTransformReady);
104
+
105
+ // Transform Image
106
+ transformBtn.addEventListener('click', async () => {
107
+ if (!capturedImageData || !selectedGender || !apiKeyInput.value.trim()) {
108
+ showError('กรุณากรอกข้อมูลให้ครบถ้วน');
109
+ return;
110
+ }
111
+
112
+ loadingIndicator.classList.remove('hidden');
113
+ successMessage.classList.add('hidden');
114
+ errorMessage.classList.add('hidden');
115
+ transformBtn.disabled = true;
116
+
117
+ try {
118
+ // Convert data URL to Blob
119
+ const response = await fetch(capturedImageData);
120
+ const blob = await response.blob();
121
+
122
+ // Create FormData for API request
123
+ const formData = new FormData();
124
+ formData.append('image', blob, 'photo.jpg');
125
+
126
+ // Create prompt based on selections
127
+ const prompt = `Transform the body to a healthy, athletic "${fitnessLevel.value}" physique while preserving the original face identity. Keep natural skin tone consistency, realistic muscle definition (focus on abs and overall proportion), and replace outfit with tasteful modern fitness wear appropriate for "${selectedGender}". Avoid nudity; keep the style photorealistic and respectful.`;
128
+
129
+ // Call OpenAI API (using DALL-E 3 for image editing)
130
+ const apiResponse = await fetch('https://api.openai.com/v1/images/edits', {
131
+ method: 'POST',
132
+ headers: {
133
+ 'Authorization': `Bearer ${apiKeyInput.value.trim()}`,
134
+ },
135
+ body: formData
136
+ });
137
+
138
+ if (!apiResponse.ok) {
139
+ const errorData = await apiResponse.json();
140
+ throw new Error(errorData.error?.message || 'API request failed');
141
+ }
142
+
143
+ const result = await apiResponse.json();
144
+
145
+ // Load transformed image
146
+ const img = new Image();
147
+ img.onload = () => {
148
+ transformedImage.src = result.data[0].url;
149
+ transformedImage.classList.remove('hidden');
150
+ originalImage.classList.add('hidden');
151
+ downloadBtn.classList.remove('hidden');
152
+ successMessage.classList.remove('hidden');
153
+ downloadBtn.dataset.url = result.data[0].url;
154
+
155
+ // Setup comparison view
156
+ setupComparison();
157
+ };
158
+ img.src = result.data[0].url;
159
+
160
+ } catch (error) {
161
+ showError('การแปลงรูปล้มเหลว: ' + error.message);
162
+ } finally {
163
+ loadingIndicator.classList.add('hidden');
164
+ transformBtn.disabled = false;
165
+ checkTransformReady();
166
+ }
167
+ });
168
+
169
+ // Setup before/after comparison
170
+ function setupComparison() {
171
+ const compareOriginal = document.getElementById('compareOriginal');
172
+ const compareTransformed = document.getElementById('compareTransformed');
173
+ const compareTransformedWrapper = document.getElementById('compareTransformedWrapper');
174
+ const slider = document.getElementById('slider');
175
+
176
+ compareOriginal.src = originalImage.src;
177
+ compareTransformed.src = transformedImage.src;
178
+
179
+ let isSliding = false;
180
+
181
+ slider.addEventListener('mousedown', () => isSliding = true);
182
+ document.addEventListener('mouseup', () => isSliding = false);
183
+ document.addEventListener('mousemove', (e) => {
184
+ if (!isSliding) return;
185
+
186
+ const rect = comparisonContainer.getBoundingClientRect();
187
+ const x = e.clientX - rect.left;
188
+ const percentage = (x / rect.width) * 100;
189
+
190
+ if (percentage >= 0 && percentage <= 100) {
191
+ slider.style.left = percentage + '%';
192
+ compareTransformedWrapper.style.width = percentage + '%';
193
+ }
194
+ });
195
+
196
+ // Touch support
197
+ slider.addEventListener('touchstart', () => isSliding = true);
198
+ document.addEventListener('touchend', () => isSliding = false);
199
+ document.addEventListener('touchmove', (e) => {
200
+ if (!isSliding) return;
201
+
202
+ const rect = comparisonContainer.getBoundingClientRect();
203
+ const x = e.touches[0].clientX - rect.left;
204
+ const percentage = (x / rect.width) * 100;
205
+
206
+ if (percentage >= 0 && percentage <= 100) {
207
+ slider.style.left = percentage + '%';
208
+ compareTransformedWrapper.style.width = percentage + '%';
209
+ }
210
+ });
211
+ }
212
+
213
+ // Download Image
214
+ downloadBtn.addEventListener('click', () => {
215
+ const link = document.createElement('a');
216
+ link.href = downloadBtn.dataset.url || transformedImage.src;
217
+ link.download = `fittransform-${Date.now()}.jpg`;
218
+ link.click();
219
+ });
220
+
221
+ // Toggle View
222
+ function toggleComparison() {
223
+ if (comparisonContainer.classList.contains('hidden')) {
224
+ comparisonContainer.classList.remove('hidden');
225
+ transformedImage.parentElement.classList.add('hidden');
226
+ } else {
227
+ comparisonContainer.classList.add('hidden');
228
+ transformedImage.parentElement.classList.remove('hidden');
229
+ }
230
+ }
231
+
232
+ // Show error message
233
+ function showError(message) {
234
+ errorText.textContent = message;
235
+ errorMessage.classList.remove('hidden');
236
+ setTimeout(() => {
237
+ errorMessage.classList.add('hidden');
238
+ }, 5000);
239
+ }
240
+
241
+ // Check for required APIs
242
+ if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
243
+ showError('เบราว์เซอร์ของคุณไม่รองรับการเข้าถึงกล้อง');
244
+ }
245
+
246
+ // Auto-save API key to localStorage
247
+ if (localStorage.getItem('openai_api_key')) {
248
+ apiKeyInput.value = localStorage.getItem('openai_api_key');
249
+ checkTransformReady();
250
+ }
251
+
252
+ apiKeyInput.addEventListener('change', () => {
253
+ if (apiKeyInput.value.trim()) {
254
+ localStorage.setItem('openai_api_key', apiKeyInput.value.trim());
255
+ }
256
+ });
257
+
258
+ // Initialize tooltips and interactions
259
+ document.addEventListener('DOMContentLoaded', () => {
260
+ // Add ripple effect to buttons
261
+ document.querySelectorAll('button').forEach(button => {
262
+ button.classList.add('ripple');
263
+ });
264
+
265
+ // Smooth scroll for anchor links
266
+ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
267
+ anchor.addEventListener('click', function (e) {
268
+ e.preventDefault();
269
+ const target = document.querySelector(this.getAttribute('href'));
270
+ if (target) {
271
+ target.scrollIntoView({ behavior: 'smooth' });
272
+ }
273
+ });
274
+ });
275
+ });
style.css CHANGED
@@ -1,28 +1,106 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
 
 
 
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
 
 
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
 
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Custom animations and styles */
2
+ @keyframes pulse-glow {
3
+ 0%, 100% {
4
+ box-shadow: 0 0 20px rgba(16, 185, 129, 0.5);
5
+ }
6
+ 50% {
7
+ box-shadow: 0 0 40px rgba(16, 185, 129, 0.8);
8
+ }
9
  }
10
 
11
+ .gender-btn.active {
12
+ background: linear-gradient(135deg, #10b981 0%, #059669 100%);
13
+ color: white;
14
+ border-color: #059669;
15
+ transform: scale(1.05);
16
  }
17
 
18
+ .camera-active {
19
+ animation: pulse-glow 2s infinite;
 
 
 
20
  }
21
 
22
+ .before-after-slider {
23
+ position: relative;
24
+ overflow: hidden;
 
 
 
25
  }
26
 
27
+ .slider-handle {
28
+ cursor: ew-resize;
29
+ user-select: none;
30
  }
31
+
32
+ /* Smooth transitions */
33
+ * {
34
+ transition: all 0.3s ease;
35
+ }
36
+
37
+ /* Custom scrollbar */
38
+ ::-webkit-scrollbar {
39
+ width: 8px;
40
+ height: 8px;
41
+ }
42
+
43
+ ::-webkit-scrollbar-track {
44
+ background: #f1f1f1;
45
+ border-radius: 10px;
46
+ }
47
+
48
+ ::-webkit-scrollbar-thumb {
49
+ background: linear-gradient(135deg, #10b981 0%, #f97316 100%);
50
+ border-radius: 10px;
51
+ }
52
+
53
+ ::-webkit-scrollbar-thumb:hover {
54
+ background: linear-gradient(135deg, #059669 0%, #ea580c 100%);
55
+ }
56
+
57
+ /* Loading spinner */
58
+ .spinner {
59
+ border: 3px solid #f3f3f3;
60
+ border-top: 3px solid #10b981;
61
+ border-radius: 50%;
62
+ width: 40px;
63
+ height: 40px;
64
+ animation: spin 1s linear infinite;
65
+ }
66
+
67
+ @keyframes spin {
68
+ 0% { transform: rotate(0deg); }
69
+ 100% { transform: rotate(360deg); }
70
+ }
71
+
72
+ /* Hover effects */
73
+ .hover-lift:hover {
74
+ transform: translateY(-5px);
75
+ }
76
+
77
+ .gradient-text {
78
+ background: linear-gradient(135deg, #10b981 0%, #f97316 100%);
79
+ -webkit-background-clip: text;
80
+ -webkit-text-fill-color: transparent;
81
+ background-clip: text;
82
+ }
83
+
84
+ /* Button ripple effect */
85
+ .ripple {
86
+ position: relative;
87
+ overflow: hidden;
88
+ }
89
+
90
+ .ripple:before {
91
+ content: "";
92
+ position: absolute;
93
+ top: 50%;
94
+ left: 50%;
95
+ width: 0;
96
+ height: 0;
97
+ border-radius: 50%;
98
+ background: rgba(255, 255, 255, 0.5);
99
+ transform: translate(-50%, -50%);
100
+ transition: width 0.6s, height 0.6s;
101
+ }
102
+
103
+ .ripple:active:before {
104
+ width: 300px;
105
+ height: 300px;
106
+ }