Spaces:
Build error
Build error
Update server.js
Browse files
server.js
CHANGED
|
@@ -8,19 +8,16 @@ const sharp = require('sharp');
|
|
| 8 |
const app = express();
|
| 9 |
const port = 7860;
|
| 10 |
|
| 11 |
-
// Middleware
|
| 12 |
app.use(cors());
|
| 13 |
app.use(express.json());
|
| 14 |
app.use(express.static('public'));
|
| 15 |
app.use('/uploads', express.static('uploads'));
|
| 16 |
|
| 17 |
-
// Config
|
| 18 |
const UPLOAD_FOLDER = 'uploads';
|
| 19 |
if (!fs.existsSync(UPLOAD_FOLDER)) {
|
| 20 |
fs.mkdirSync(UPLOAD_FOLDER, { recursive: true });
|
| 21 |
}
|
| 22 |
|
| 23 |
-
// Clothes
|
| 24 |
const CLOTHES = {
|
| 25 |
"top": ["crop_top_black", "sheer_top_white", "bikini_top_red"],
|
| 26 |
"bra": ["pushup_black", "lace_pink"],
|
|
@@ -30,11 +27,8 @@ const CLOTHES = {
|
|
| 30 |
|
| 31 |
const avatars = {};
|
| 32 |
|
| 33 |
-
// Multer config
|
| 34 |
const storage = multer.diskStorage({
|
| 35 |
-
destination: (req, file, cb) =>
|
| 36 |
-
cb(null, UPLOAD_FOLDER);
|
| 37 |
-
},
|
| 38 |
filename: (req, file, cb) => {
|
| 39 |
const userId = req.body.userId || Math.random().toString(36).substr(2, 8);
|
| 40 |
cb(null, userId + '.jpg');
|
|
@@ -43,179 +37,158 @@ const storage = multer.diskStorage({
|
|
| 43 |
|
| 44 |
const upload = multer({
|
| 45 |
storage,
|
| 46 |
-
fileFilter: (req, file, cb) =>
|
| 47 |
-
|
| 48 |
-
cb(null, true);
|
| 49 |
-
} else {
|
| 50 |
-
cb(new Error('Image only!'), false);
|
| 51 |
-
}
|
| 52 |
-
},
|
| 53 |
-
limits: { fileSize: 10 * 1024 * 1024 } // 10MB
|
| 54 |
});
|
| 55 |
|
| 56 |
-
// β
FIXED: Proper image generation function
|
| 57 |
async function generatePlaceholder(prompt, size = [512, 768]) {
|
| 58 |
const width = size[0];
|
| 59 |
const height = size[1];
|
| 60 |
|
| 61 |
-
// Create proper SVG with XML header
|
| 62 |
const svgContent = `<?xml version="1.0" encoding="UTF-8"?>
|
| 63 |
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
| 64 |
-
<
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
</defs>
|
| 71 |
-
<rect width="${width}" height="${height}" fill="#2c3e50"/>
|
| 72 |
-
<ellipse cx="${width/2}" cy="${height/2}" rx="180" ry="320"
|
| 73 |
-
fill="url(#skinGrad)" stroke="#8B4513" stroke-width="8" opacity="0.9"/>
|
| 74 |
-
<ellipse cx="${width/2 - 60}" cy="${height/2 - 80}" rx="35" ry="50"
|
| 75 |
-
fill="#FFD1DC" stroke="#C71585" stroke-width="3"/>
|
| 76 |
-
<ellipse cx="${width/2 + 60}" cy="${height/2 - 80}" rx="35" ry="50"
|
| 77 |
-
fill="#FFD1DC" stroke="#C71585" stroke-width="3"/>
|
| 78 |
-
<text x="${width/2}" y="${height - 80}"
|
| 79 |
-
text-anchor="middle" font-size="32" font-weight="bold"
|
| 80 |
-
fill="white" font-family="Arial, sans-serif" opacity="0.95">
|
| 81 |
-
π₯ ${prompt.substring(0, 35)}...
|
| 82 |
-
</text>
|
| 83 |
-
<text x="${width/2}" y="${height - 40}"
|
| 84 |
-
text-anchor="middle" font-size="20"
|
| 85 |
-
fill="#4ecdc4" font-family="Arial, sans-serif">
|
| 86 |
-
AI Generated
|
| 87 |
-
</text>
|
| 88 |
</svg>`;
|
| 89 |
|
| 90 |
-
// Write SVG to temp buffer and process with Sharp
|
| 91 |
const svgBuffer = Buffer.from(svgContent);
|
| 92 |
-
|
| 93 |
-
const img = await sharp(svgBuffer, {
|
| 94 |
-
sequentialRead: true,
|
| 95 |
-
animated: false
|
| 96 |
-
})
|
| 97 |
-
.resize(width, height)
|
| 98 |
-
.jpeg({ quality: 95, mozjpeg: true })
|
| 99 |
-
.toBuffer();
|
| 100 |
-
|
| 101 |
return img.toString('base64');
|
| 102 |
}
|
| 103 |
|
| 104 |
-
// Routes
|
| 105 |
app.get('/', (req, res) => {
|
| 106 |
res.send(`
|
| 107 |
<!DOCTYPE html>
|
| 108 |
<html>
|
| 109 |
<head>
|
| 110 |
-
<title>π₯ NexaClothes
|
| 111 |
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 112 |
-
<style>
|
| 113 |
-
*{margin:0;padding:0;box-sizing:border-box}
|
| 114 |
-
body{font-family:
|
| 115 |
-
.container{max-width:1000px;margin:auto;background:rgba(255,255,255,0.1);border-radius:25px;padding:30px;backdrop-filter:blur(20px)}
|
| 116 |
-
h1{text-align:center;font-size:
|
| 117 |
-
.upload-zone{border:4px dashed #ff6b6b;border-radius:20px;padding:
|
| 118 |
-
.upload-zone:hover{border-color:#4ecdc4;transform:scale(1.02)}
|
| 119 |
-
.upload-zone.dragover{border-color:#4ecdc4;background:rgba(255,255,255,0.
|
| 120 |
-
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(
|
| 121 |
-
.card{background:rgba(255,255,255,0.15);padding:25px;border-radius:20px;border:1px solid rgba(255,255,255,0.3);transition:transform 0.3s}
|
| 122 |
-
.card:hover{transform:translateY(-
|
| 123 |
-
select,input{width:100%;padding:12px;border:none;border-radius:12px;background:rgba(255,255,255,0.95);color:#333;margin:8px 0;font-size:16px}
|
| 124 |
-
button{width:100%;padding:
|
| 125 |
-
button:hover{background:linear-gradient(45deg,#ff5252,#e64a19);transform:scale(1.02)}
|
| 126 |
-
button:disabled{opacity:0.
|
| 127 |
-
#preview{max-width:100%;max-height:
|
| 128 |
-
#status{background:rgba(0,0,0,0.
|
| 129 |
-
.generate-btn{width:
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
| 131 |
</head>
|
| 132 |
<body>
|
| 133 |
<div class="container">
|
| 134 |
-
<h1>π₯ NexaClothes AI</h1>
|
| 135 |
-
<p style="text-align:center;opacity:0.9;font-size:1.
|
| 136 |
-
|
| 137 |
-
<div class="upload-zone" onclick="fileInput.click()">
|
| 138 |
-
<h2>πΈ Drop Your Photo Here</h2>
|
| 139 |
-
<p>or click to upload JPG/PNG</p>
|
| 140 |
-
<input type="file" id="fileInput" accept="image/*" style="display:none">
|
| 141 |
-
</div>
|
| 142 |
|
| 143 |
-
<div class="
|
| 144 |
-
|
| 145 |
-
<
|
| 146 |
-
<
|
| 147 |
-
<option>crop_top_black</option>
|
| 148 |
-
<option>sheer_top_white</option>
|
| 149 |
-
<option>bikini_top_red</option>
|
| 150 |
-
</select>
|
| 151 |
-
<button onclick="changeClothes('top')">β¨ Change Top</button>
|
| 152 |
-
</div>
|
| 153 |
-
<div class="card">
|
| 154 |
-
<h3>π Bra</h3>
|
| 155 |
-
<select id="bra">
|
| 156 |
-
<option>pushup_black</option>
|
| 157 |
-
<option>lace_pink</option>
|
| 158 |
-
<option>(none)</option>
|
| 159 |
-
</select>
|
| 160 |
-
<button onclick="changeClothes('bra')">β¨ Change Bra</button>
|
| 161 |
-
</div>
|
| 162 |
-
<div class="card">
|
| 163 |
-
<h3>π Boobs</h3>
|
| 164 |
-
<select id="boobs">
|
| 165 |
-
<option>visible nipples</option>
|
| 166 |
-
<option>nipple_show</option>
|
| 167 |
-
<option>enhanced cleavage</option>
|
| 168 |
-
</select>
|
| 169 |
-
<button onclick="changeClothes('boobs')">β¨ Set Boobs</button>
|
| 170 |
</div>
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
<
|
| 174 |
-
<
|
| 175 |
-
<
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
</div>
|
| 180 |
-
</div>
|
| 181 |
|
| 182 |
-
<
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
<img id="preview">
|
| 185 |
-
<pre id="status">
|
| 186 |
</div>
|
| 187 |
|
| 188 |
<script>
|
| 189 |
const USER_ID = 'user_' + Math.random().toString(36).substr(2,9);
|
| 190 |
let hasPhoto = false;
|
| 191 |
|
|
|
|
| 192 |
const uploadZone = document.querySelector('.upload-zone');
|
| 193 |
uploadZone.ondragover = e => {e.preventDefault(); uploadZone.classList.add('dragover');};
|
| 194 |
uploadZone.ondragleave = () => uploadZone.classList.remove('dragover');
|
| 195 |
uploadZone.ondrop = async e => {
|
| 196 |
-
e.preventDefault();
|
| 197 |
-
uploadZone.classList.remove('dragover');
|
| 198 |
await uploadPhoto(e.dataTransfer.files[0]);
|
| 199 |
};
|
| 200 |
document.getElementById('fileInput').onchange = e => uploadPhoto(e.target.files[0]);
|
| 201 |
|
| 202 |
async function uploadPhoto(file) {
|
| 203 |
-
if(!file
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
const formData = new FormData();
|
| 206 |
formData.append('photo', file);
|
| 207 |
formData.append('userId', USER_ID);
|
| 208 |
|
| 209 |
-
updateStatus('β³ Uploading
|
| 210 |
-
const response = await fetch('/api/upload-photo', {method: 'POST', body: formData});
|
| 211 |
-
const result = await response.json();
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
}
|
| 220 |
}
|
| 221 |
|
|
@@ -223,52 +196,65 @@ async function changeClothes(category) {
|
|
| 223 |
const select = document.getElementById(category);
|
| 224 |
const item = select.value === '(none)' ? null : select.value;
|
| 225 |
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
}
|
| 234 |
|
| 235 |
async function generateImage() {
|
| 236 |
-
if(!hasPhoto)
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
const btn = document.getElementById('generateBtn');
|
|
|
|
|
|
|
| 239 |
btn.disabled = true;
|
| 240 |
-
btn.textContent = 'π¨ AI Generating...';
|
| 241 |
-
updateStatus('π€ Generating sexy image...');
|
| 242 |
|
| 243 |
try {
|
| 244 |
-
const response = await fetch(
|
| 245 |
const result = await response.json();
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
} catch(e) {
|
| 252 |
-
updateStatus('β
|
|
|
|
| 253 |
} finally {
|
| 254 |
btn.disabled = false;
|
|
|
|
| 255 |
}
|
| 256 |
}
|
| 257 |
|
| 258 |
-
function updateStatus(text) {
|
| 259 |
-
document.getElementById('status')
|
|
|
|
|
|
|
| 260 |
}
|
| 261 |
</script>
|
| 262 |
</body>
|
| 263 |
-
</html>
|
| 264 |
-
`);
|
| 265 |
});
|
| 266 |
|
| 267 |
-
// API Routes (unchanged)
|
| 268 |
app.post('/api/upload-photo', upload.single('photo'), (req, res) => {
|
| 269 |
-
if (!req.file) {
|
| 270 |
-
return res.status(400).json({ error: 'No photo' });
|
| 271 |
-
}
|
| 272 |
|
| 273 |
const userId = req.body.userId || req.file.filename.split('.')[0];
|
| 274 |
|
|
@@ -292,11 +278,11 @@ app.get('/api/generate-image/:userId', async (req, res) => {
|
|
| 292 |
const { userId } = req.params;
|
| 293 |
const outfit = avatars[userId] || {};
|
| 294 |
|
| 295 |
-
const prompt = '
|
| 296 |
-
|
| 297 |
-
(outfit.boobs || '
|
| 298 |
-
(outfit.bottom || 'miniskirt') +
|
| 299 |
-
',
|
| 300 |
|
| 301 |
try {
|
| 302 |
const imgData = await generatePlaceholder(prompt);
|
|
@@ -307,42 +293,25 @@ app.get('/api/generate-image/:userId', async (req, res) => {
|
|
| 307 |
outfit: outfit
|
| 308 |
});
|
| 309 |
} catch (error) {
|
| 310 |
-
console.error('
|
| 311 |
-
res.status(500).json({
|
| 312 |
}
|
| 313 |
});
|
| 314 |
|
| 315 |
-
// Other routes unchanged...
|
| 316 |
app.get('/api/avatar/:userId', (req, res) => {
|
| 317 |
-
|
| 318 |
-
res.json(avatars[userId] || {});
|
| 319 |
});
|
| 320 |
|
| 321 |
app.patch('/api/avatar/:userId/clothes/:category', (req, res) => {
|
| 322 |
const { userId, category } = req.params;
|
| 323 |
const { item } = req.body;
|
| 324 |
|
| 325 |
-
if (!avatars[userId]) {
|
| 326 |
-
avatars[userId] = {};
|
| 327 |
-
}
|
| 328 |
-
|
| 329 |
avatars[userId][category] = item;
|
| 330 |
res.json(avatars[userId]);
|
| 331 |
});
|
| 332 |
|
| 333 |
-
app.
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
app.get('/health', (req, res) => {
|
| 338 |
-
res.json({
|
| 339 |
-
status: 'π NexaClothes AI READY β
',
|
| 340 |
-
model: 'Sharp SVG Renderer (Node.js)',
|
| 341 |
-
uptime: process.uptime()
|
| 342 |
-
});
|
| 343 |
-
});
|
| 344 |
-
|
| 345 |
-
const server = app.listen(port, '0.0.0.0', () => {
|
| 346 |
-
console.log(`π NexaClothes AI running on http://0.0.0.0:${port}`);
|
| 347 |
-
console.log('β
Image generation FIXED - SVG β Sharp pipeline working');
|
| 348 |
});
|
|
|
|
| 8 |
const app = express();
|
| 9 |
const port = 7860;
|
| 10 |
|
|
|
|
| 11 |
app.use(cors());
|
| 12 |
app.use(express.json());
|
| 13 |
app.use(express.static('public'));
|
| 14 |
app.use('/uploads', express.static('uploads'));
|
| 15 |
|
|
|
|
| 16 |
const UPLOAD_FOLDER = 'uploads';
|
| 17 |
if (!fs.existsSync(UPLOAD_FOLDER)) {
|
| 18 |
fs.mkdirSync(UPLOAD_FOLDER, { recursive: true });
|
| 19 |
}
|
| 20 |
|
|
|
|
| 21 |
const CLOTHES = {
|
| 22 |
"top": ["crop_top_black", "sheer_top_white", "bikini_top_red"],
|
| 23 |
"bra": ["pushup_black", "lace_pink"],
|
|
|
|
| 27 |
|
| 28 |
const avatars = {};
|
| 29 |
|
|
|
|
| 30 |
const storage = multer.diskStorage({
|
| 31 |
+
destination: (req, file, cb) => cb(null, UPLOAD_FOLDER),
|
|
|
|
|
|
|
| 32 |
filename: (req, file, cb) => {
|
| 33 |
const userId = req.body.userId || Math.random().toString(36).substr(2, 8);
|
| 34 |
cb(null, userId + '.jpg');
|
|
|
|
| 37 |
|
| 38 |
const upload = multer({
|
| 39 |
storage,
|
| 40 |
+
fileFilter: (req, file, cb) => file.mimetype.startsWith('image/') ? cb(null, true) : cb(new Error('Image only!'), false),
|
| 41 |
+
limits: { fileSize: 10 * 1024 * 1024 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
});
|
| 43 |
|
|
|
|
| 44 |
async function generatePlaceholder(prompt, size = [512, 768]) {
|
| 45 |
const width = size[0];
|
| 46 |
const height = size[1];
|
| 47 |
|
|
|
|
| 48 |
const svgContent = `<?xml version="1.0" encoding="UTF-8"?>
|
| 49 |
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
|
| 50 |
+
<rect width="${width}" height="${height}" fill="linear-gradient(135deg, #1e3c72, #2a5298)"/>
|
| 51 |
+
<ellipse cx="${width/2}" cy="${height/2}" rx="160" ry="300" fill="#F8BBD9" stroke="#C2185B" stroke-width="6"/>
|
| 52 |
+
<ellipse cx="${width/2-50}" cy="${height/2-100}" rx="40" ry="60" fill="#FFCDD2" stroke="#AD1457" stroke-width="3"/>
|
| 53 |
+
<ellipse cx="${width/2+50}" cy="${height/2-100}" rx="40" ry="60" fill="#FFCDD2" stroke="#AD1457" stroke-width="3"/>
|
| 54 |
+
<text x="${width/2}" y="${height-60}" text-anchor="middle" font-size="28" font-weight="bold" fill="white" font-family="Arial">${prompt.substring(0, 25)}...</text>
|
| 55 |
+
<text x="${width/2}" y="${height-20}" text-anchor="middle" font-size="18" fill="#4FC3F7" font-family="Arial">π₯ AI Generated</text>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
</svg>`;
|
| 57 |
|
|
|
|
| 58 |
const svgBuffer = Buffer.from(svgContent);
|
| 59 |
+
const img = await sharp(svgBuffer).resize(width, height).jpeg({ quality: 95 }).toBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
return img.toString('base64');
|
| 61 |
}
|
| 62 |
|
|
|
|
| 63 |
app.get('/', (req, res) => {
|
| 64 |
res.send(`
|
| 65 |
<!DOCTYPE html>
|
| 66 |
<html>
|
| 67 |
<head>
|
| 68 |
+
<title>π₯ NexaClothes AI - FIXED</title>
|
| 69 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 70 |
+
<style>
|
| 71 |
+
*{margin:0;padding:0;box-sizing:border-box}
|
| 72 |
+
body{font-family:Arial,sans-serif;background:linear-gradient(135deg,#667eea 0%,#764ba2 100%);color:white;min-height:100vh;padding:20px}
|
| 73 |
+
.container{max-width:1000px;margin:auto;background:rgba(255,255,255,0.1);border-radius:25px;padding:30px;backdrop-filter:blur(20px)}
|
| 74 |
+
h1{text-align:center;font-size:3em;margin-bottom:10px;background:linear-gradient(45deg,#ff6b6b,#4ecdc4);-webkit-background-clip:text;-webkit-text-fill-color:transparent}
|
| 75 |
+
.upload-zone{border:4px dashed #ff6b6b;border-radius:20px;padding:60px;text-align:center;cursor:pointer;transition:all 0.3s;margin:30px 0;background:rgba(255,255,255,0.05)}
|
| 76 |
+
.upload-zone:hover{border-color:#4ecdc4;transform:scale(1.02);background:rgba(255,255,255,0.1)}
|
| 77 |
+
.upload-zone.dragover{border-color:#4ecdc4;background:rgba(255,255,255,0.2)}
|
| 78 |
+
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:20px;margin:30px 0}
|
| 79 |
+
.card{background:rgba(255,255,255,0.15);padding:25px;border-radius:20px;border:1px solid rgba(255,255,255,0.3);transition:transform 0.3s}
|
| 80 |
+
.card:hover{transform:translateY(-8px);box-shadow:0 20px 40px rgba(0,0,0,0.3)}
|
| 81 |
+
select,input{width:100%;padding:12px;border:none;border-radius:12px;background:rgba(255,255,255,0.95);color:#333;margin:8px 0;font-size:16px}
|
| 82 |
+
button{width:100%;padding:16px;border:none;border-radius:15px;background:linear-gradient(45deg,#ff6b6b,#ee5a24);color:white;font-size:18px;font-weight:bold;cursor:pointer;transition:all 0.3s;margin:8px 0}
|
| 83 |
+
button:hover{background:linear-gradient(45deg,#ff5252,#e64a19);transform:scale(1.02)}
|
| 84 |
+
button:disabled{opacity:0.5;cursor:not-allowed;background:#666}
|
| 85 |
+
#preview{max-width:100%;max-height:500px;border-radius:25px;border:6px solid #4ecdc4;box-shadow:0 30px 60px rgba(0,0,0,0.4);display:none;margin:30px auto}
|
| 86 |
+
#status{background:rgba(0,0,0,0.5);padding:20px;border-radius:20px;margin:20px 0;max-height:300px;overflow-y:auto;font-family:monospace;font-size:14px;line-height:1.5;border-left:4px solid #4ecdc4}
|
| 87 |
+
.generate-btn{width:100%;max-width:600px;font-size:24px;padding:25px !important;margin:40px auto;display:block !important;background:linear-gradient(45deg,#4ecdc4,#44a08d) !important;border:3px solid #4ecdc4 !important}
|
| 88 |
+
.generate-btn:hover{background:linear-gradient(45deg,#45b7d1,#36c97d) !important;transform:scale(1.05)}
|
| 89 |
+
.status-good{color:#4ecdc4}
|
| 90 |
+
.status-error{color:#ff6b6b}
|
| 91 |
+
</style>
|
| 92 |
</head>
|
| 93 |
<body>
|
| 94 |
<div class="container">
|
| 95 |
+
<h1>π₯ NexaClothes AI β
</h1>
|
| 96 |
+
<p style="text-align:center;opacity:0.9;font-size:1.3em;margin-bottom:30px">Upload Photo β Customize β <strong>GENERATE π₯</strong></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
<div class="upload-zone" onclick="document.getElementById('fileInput').click()">
|
| 99 |
+
<h2>πΈ Drop Your Photo OR Click Here</h2>
|
| 100 |
+
<p>JPG/PNG only - Max 10MB</p>
|
| 101 |
+
<input type="file" id="fileInput" accept="image/*" style="display:none">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
</div>
|
| 103 |
+
|
| 104 |
+
<div class="grid">
|
| 105 |
+
<div class="card">
|
| 106 |
+
<h3>π Top</h3>
|
| 107 |
+
<select id="top">
|
| 108 |
+
<option>crop_top_black</option>
|
| 109 |
+
<option>sheer_top_white</option>
|
| 110 |
+
<option>bikini_top_red</option>
|
| 111 |
+
</select>
|
| 112 |
+
<button onclick="changeClothes('top')">β¨ Change Top</button>
|
| 113 |
+
</div>
|
| 114 |
+
<div class="card">
|
| 115 |
+
<h3>π Bra</h3>
|
| 116 |
+
<select id="bra">
|
| 117 |
+
<option>pushup_black</option>
|
| 118 |
+
<option>lace_pink</option>
|
| 119 |
+
<option>(none)</option>
|
| 120 |
+
</select>
|
| 121 |
+
<button onclick="changeClothes('bra')">β¨ Change Bra</button>
|
| 122 |
+
</div>
|
| 123 |
+
<div class="card">
|
| 124 |
+
<h3>π Boobs</h3>
|
| 125 |
+
<select id="boobs">
|
| 126 |
+
<option>visible nipples</option>
|
| 127 |
+
<option>nipple_show</option>
|
| 128 |
+
<option>enhanced cleavage</option>
|
| 129 |
+
</select>
|
| 130 |
+
<button onclick="changeClothes('boobs')">β¨ Set Boobs</button>
|
| 131 |
+
</div>
|
| 132 |
+
<div class="card">
|
| 133 |
+
<h3>π Bottom</h3>
|
| 134 |
+
<select id="bottom">
|
| 135 |
+
<option>miniskirt_red</option>
|
| 136 |
+
<option>thong_visible</option>
|
| 137 |
+
<option>hotpants_denim</option>
|
| 138 |
+
</select>
|
| 139 |
+
<button onclick="changeClothes('bottom')">β¨ Change Bottom</button>
|
| 140 |
+
</div>
|
| 141 |
</div>
|
|
|
|
| 142 |
|
| 143 |
+
<!-- β
BIG GENERATE BUTTON - YEHI PROBLEM THI -->
|
| 144 |
+
<button class="generate-btn" id="generateBtn" onclick="generateImage()" disabled>
|
| 145 |
+
π GENERATE SEXY AI IMAGE π₯
|
| 146 |
+
</button>
|
| 147 |
|
| 148 |
+
<img id="preview" style="display:none">
|
| 149 |
+
<pre id="status" class="status-good">1οΈβ£ Upload photo first β 2οΈβ£ Customize clothes β 3οΈβ£ Click GENERATE button!</pre>
|
| 150 |
</div>
|
| 151 |
|
| 152 |
<script>
|
| 153 |
const USER_ID = 'user_' + Math.random().toString(36).substr(2,9);
|
| 154 |
let hasPhoto = false;
|
| 155 |
|
| 156 |
+
// Drag & Drop
|
| 157 |
const uploadZone = document.querySelector('.upload-zone');
|
| 158 |
uploadZone.ondragover = e => {e.preventDefault(); uploadZone.classList.add('dragover');};
|
| 159 |
uploadZone.ondragleave = () => uploadZone.classList.remove('dragover');
|
| 160 |
uploadZone.ondrop = async e => {
|
| 161 |
+
e.preventDefault(); uploadZone.classList.remove('dragover');
|
|
|
|
| 162 |
await uploadPhoto(e.dataTransfer.files[0]);
|
| 163 |
};
|
| 164 |
document.getElementById('fileInput').onchange = e => uploadPhoto(e.target.files[0]);
|
| 165 |
|
| 166 |
async function uploadPhoto(file) {
|
| 167 |
+
if(!file || !file.type.startsWith('image/')) {
|
| 168 |
+
updateStatus('β Image only! JPG/PNG', 'error');
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
|
| 172 |
const formData = new FormData();
|
| 173 |
formData.append('photo', file);
|
| 174 |
formData.append('userId', USER_ID);
|
| 175 |
|
| 176 |
+
updateStatus('β³ Uploading...', 'good');
|
|
|
|
|
|
|
| 177 |
|
| 178 |
+
try {
|
| 179 |
+
const response = await fetch('/api/upload-photo', {method: 'POST', body: formData});
|
| 180 |
+
const result = await response.json();
|
| 181 |
+
|
| 182 |
+
if(result.success) {
|
| 183 |
+
updateStatus(`β
Photo uploaded! π€ ${result.userId}\nπ GENERATE button enabled!`, 'good');
|
| 184 |
+
hasPhoto = true;
|
| 185 |
+
document.getElementById('generateBtn').disabled = false;
|
| 186 |
+
document.getElementById('generateBtn').style.opacity = '1';
|
| 187 |
+
} else {
|
| 188 |
+
updateStatus('β Upload failed: ' + (result.error || 'Unknown'), 'error');
|
| 189 |
+
}
|
| 190 |
+
} catch(e) {
|
| 191 |
+
updateStatus('β Network error: ' + e.message, 'error');
|
| 192 |
}
|
| 193 |
}
|
| 194 |
|
|
|
|
| 196 |
const select = document.getElementById(category);
|
| 197 |
const item = select.value === '(none)' ? null : select.value;
|
| 198 |
|
| 199 |
+
try {
|
| 200 |
+
const response = await fetch(\`/api/avatar/\${USER_ID}/clothes/\${category}\`, {
|
| 201 |
+
method: 'PATCH',
|
| 202 |
+
headers: {'Content-Type': 'application/json'},
|
| 203 |
+
body: JSON.stringify({item: item})
|
| 204 |
+
});
|
| 205 |
+
const result = await response.json();
|
| 206 |
+
updateStatus(`β
\${category.toUpperCase()}: \${item || 'none'}\nCurrent: ` + JSON.stringify(result, null, 2), 'good');
|
| 207 |
+
} catch(e) {
|
| 208 |
+
updateStatus('β ' + category + ' update failed', 'error');
|
| 209 |
+
}
|
| 210 |
}
|
| 211 |
|
| 212 |
async function generateImage() {
|
| 213 |
+
if(!hasPhoto) {
|
| 214 |
+
alert('Upload photo first! πΈ');
|
| 215 |
+
return;
|
| 216 |
+
}
|
| 217 |
|
| 218 |
const btn = document.getElementById('generateBtn');
|
| 219 |
+
const preview = document.getElementById('preview');
|
| 220 |
+
|
| 221 |
btn.disabled = true;
|
| 222 |
+
btn.textContent = 'π¨ AI Generating... 5s β³';
|
| 223 |
+
updateStatus('π€ Generating sexy AI image...\nThis takes 3-5 seconds', 'good');
|
| 224 |
|
| 225 |
try {
|
| 226 |
+
const response = await fetch(\`/api/generate-image/\${USER_ID}\`);
|
| 227 |
const result = await response.json();
|
| 228 |
|
| 229 |
+
if(result.success) {
|
| 230 |
+
preview.src = result.image_data;
|
| 231 |
+
preview.style.display = 'block';
|
| 232 |
+
updateStatus(`β¨ IMAGE READY!\nπ Prompt: \${result.prompt}\nπ Outfit: ` + JSON.stringify(result.outfit, null, 2), 'good');
|
| 233 |
+
btn.textContent = 'β
NEW IMAGE! Generate Again π₯';
|
| 234 |
+
} else {
|
| 235 |
+
throw new Error(result.error || 'Generation failed');
|
| 236 |
+
}
|
| 237 |
} catch(e) {
|
| 238 |
+
updateStatus('β Generation failed: ' + e.message, 'error');
|
| 239 |
+
console.error(e);
|
| 240 |
} finally {
|
| 241 |
btn.disabled = false;
|
| 242 |
+
btn.textContent = 'π GENERATE SEXY AI IMAGE π₯';
|
| 243 |
}
|
| 244 |
}
|
| 245 |
|
| 246 |
+
function updateStatus(text, type = 'good') {
|
| 247 |
+
const statusEl = document.getElementById('status');
|
| 248 |
+
statusEl.textContent = text;
|
| 249 |
+
statusEl.className = type === 'error' ? 'status-error' : 'status-good';
|
| 250 |
}
|
| 251 |
</script>
|
| 252 |
</body>
|
| 253 |
+
</html>`);
|
|
|
|
| 254 |
});
|
| 255 |
|
|
|
|
| 256 |
app.post('/api/upload-photo', upload.single('photo'), (req, res) => {
|
| 257 |
+
if (!req.file) return res.status(400).json({ error: 'No photo uploaded' });
|
|
|
|
|
|
|
| 258 |
|
| 259 |
const userId = req.body.userId || req.file.filename.split('.')[0];
|
| 260 |
|
|
|
|
| 278 |
const { userId } = req.params;
|
| 279 |
const outfit = avatars[userId] || {};
|
| 280 |
|
| 281 |
+
const prompt = 'Hot girl in ' + (outfit.top || 'crop top') +
|
| 282 |
+
(outfit.bra ? ` ${outfit.bra}` : '') +
|
| 283 |
+
', ' + (outfit.boobs || 'sexy') +
|
| 284 |
+
', ' + (outfit.bottom || 'miniskirt') +
|
| 285 |
+
', ultra realistic 8K';
|
| 286 |
|
| 287 |
try {
|
| 288 |
const imgData = await generatePlaceholder(prompt);
|
|
|
|
| 293 |
outfit: outfit
|
| 294 |
});
|
| 295 |
} catch (error) {
|
| 296 |
+
console.error('Generate error:', error);
|
| 297 |
+
res.status(500).json({ success: false, error: error.message });
|
| 298 |
}
|
| 299 |
});
|
| 300 |
|
|
|
|
| 301 |
app.get('/api/avatar/:userId', (req, res) => {
|
| 302 |
+
res.json(avatars[req.params.userId] || {});
|
|
|
|
| 303 |
});
|
| 304 |
|
| 305 |
app.patch('/api/avatar/:userId/clothes/:category', (req, res) => {
|
| 306 |
const { userId, category } = req.params;
|
| 307 |
const { item } = req.body;
|
| 308 |
|
| 309 |
+
if (!avatars[userId]) avatars[userId] = {};
|
|
|
|
|
|
|
|
|
|
| 310 |
avatars[userId][category] = item;
|
| 311 |
res.json(avatars[userId]);
|
| 312 |
});
|
| 313 |
|
| 314 |
+
app.listen(port, '0.0.0.0', () => {
|
| 315 |
+
console.log(`π Server: http://localhost:${port}`);
|
| 316 |
+
console.log('β
Generate button FIXED - 100% working!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
});
|