Spaces:
Running
Running
Update index.html
Browse files- index.html +133 -27
index.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>فتوشاپ هوش
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
:root {
|
|
@@ -195,14 +195,29 @@
|
|
| 195 |
position: relative;
|
| 196 |
background-color: var(--drop-zone-bg);
|
| 197 |
overflow: hidden;
|
|
|
|
| 198 |
}
|
| 199 |
-
|
| 200 |
-
#result-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
border-radius: 0.75rem;
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
}
|
| 207 |
|
| 208 |
.spinner {
|
|
@@ -227,6 +242,64 @@
|
|
| 227 |
display: none;
|
| 228 |
font-weight: 500;
|
| 229 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
@media (max-width: 800px) {
|
| 232 |
.editor-grid {
|
|
@@ -265,7 +338,7 @@
|
|
| 265 |
<h2>۲. نتیجه را مشاهده کنید</h2>
|
| 266 |
<div id="result-container">
|
| 267 |
<div class="spinner" id="loader"></div>
|
| 268 |
-
<
|
| 269 |
</div>
|
| 270 |
</div>
|
| 271 |
</div>
|
|
@@ -279,6 +352,17 @@
|
|
| 279 |
</main>
|
| 280 |
</div>
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
<script>
|
| 283 |
// API Endpoint from the provided chatbot code
|
| 284 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
|
@@ -290,9 +374,14 @@
|
|
| 290 |
const dropZoneText = document.getElementById('drop-zone-text');
|
| 291 |
const promptInput = document.getElementById('prompt-input');
|
| 292 |
const submitBtn = document.getElementById('submit-btn');
|
| 293 |
-
const
|
| 294 |
const loader = document.getElementById('loader');
|
| 295 |
const errorMessage = document.getElementById('error-message');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
let uploadedFile = null;
|
| 298 |
|
|
@@ -301,12 +390,9 @@
|
|
| 301 |
dropZone.addEventListener('click', () => fileInput.click());
|
| 302 |
fileInput.addEventListener('change', (e) => {
|
| 303 |
const file = e.target.files[0];
|
| 304 |
-
if (file)
|
| 305 |
-
handleFile(file);
|
| 306 |
-
}
|
| 307 |
});
|
| 308 |
|
| 309 |
-
// Drag and Drop events
|
| 310 |
dropZone.addEventListener('dragover', (e) => {
|
| 311 |
e.preventDefault();
|
| 312 |
dropZone.classList.add('dragover');
|
|
@@ -320,9 +406,7 @@
|
|
| 320 |
e.preventDefault();
|
| 321 |
dropZone.classList.remove('dragover');
|
| 322 |
const file = e.dataTransfer.files[0];
|
| 323 |
-
if (file)
|
| 324 |
-
handleFile(file);
|
| 325 |
-
}
|
| 326 |
});
|
| 327 |
|
| 328 |
function handleFile(file) {
|
|
@@ -357,10 +441,8 @@
|
|
| 357 |
return;
|
| 358 |
}
|
| 359 |
|
| 360 |
-
// Start loading state
|
| 361 |
setLoading(true);
|
| 362 |
|
| 363 |
-
// Create FormData to send to the API
|
| 364 |
const formData = new FormData();
|
| 365 |
formData.append('image', uploadedFile);
|
| 366 |
formData.append('prompt', prompt);
|
|
@@ -378,10 +460,10 @@
|
|
| 378 |
|
| 379 |
const result = await response.json();
|
| 380 |
|
| 381 |
-
if (result.image_urls && result.image_urls.length > 0) {
|
| 382 |
-
displayResult(result.image_urls
|
| 383 |
} else {
|
| 384 |
-
throw new Error('پاسخ معتبری از سرور دریافت نشد.');
|
| 385 |
}
|
| 386 |
|
| 387 |
} catch (error) {
|
|
@@ -398,7 +480,7 @@
|
|
| 398 |
loader.style.display = 'block';
|
| 399 |
submitBtn.disabled = true;
|
| 400 |
submitBtn.textContent = 'در حال پردازش...';
|
| 401 |
-
|
| 402 |
errorMessage.style.display = 'none';
|
| 403 |
} else {
|
| 404 |
loader.style.display = 'none';
|
|
@@ -407,14 +489,19 @@
|
|
| 407 |
}
|
| 408 |
}
|
| 409 |
|
| 410 |
-
function displayResult(
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
}
|
| 414 |
|
| 415 |
function clearResult() {
|
| 416 |
-
|
| 417 |
-
resultImage.style.display = 'none';
|
| 418 |
errorMessage.style.display = 'none';
|
| 419 |
}
|
| 420 |
|
|
@@ -422,6 +509,25 @@
|
|
| 422 |
errorMessage.textContent = message;
|
| 423 |
errorMessage.style.display = 'block';
|
| 424 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
|
| 426 |
</script>
|
| 427 |
</body>
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>فتوشاپ هوش مصنوعی (نسخه گالری)</title>
|
| 7 |
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&display=swap" rel="stylesheet">
|
| 8 |
<style>
|
| 9 |
:root {
|
|
|
|
| 195 |
position: relative;
|
| 196 |
background-color: var(--drop-zone-bg);
|
| 197 |
overflow: hidden;
|
| 198 |
+
padding: 0.5rem;
|
| 199 |
}
|
| 200 |
+
|
| 201 |
+
#result-grid {
|
| 202 |
+
display: grid;
|
| 203 |
+
grid-template-columns: repeat(2, 1fr);
|
| 204 |
+
gap: 0.5rem;
|
| 205 |
+
width: 100%;
|
| 206 |
+
height: 100%;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
#result-grid img {
|
| 210 |
+
width: 100%;
|
| 211 |
+
height: 100%;
|
| 212 |
+
object-fit: cover;
|
| 213 |
border-radius: 0.75rem;
|
| 214 |
+
cursor: pointer;
|
| 215 |
+
transition: transform 0.2s ease, box-shadow 0.2s ease;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
#result-grid img:hover {
|
| 219 |
+
transform: scale(1.05);
|
| 220 |
+
box-shadow: 0 5px 15px var(--shadow-color);
|
| 221 |
}
|
| 222 |
|
| 223 |
.spinner {
|
|
|
|
| 242 |
display: none;
|
| 243 |
font-weight: 500;
|
| 244 |
}
|
| 245 |
+
|
| 246 |
+
/* Lightbox Styles */
|
| 247 |
+
#lightbox {
|
| 248 |
+
position: fixed;
|
| 249 |
+
top: 0;
|
| 250 |
+
left: 0;
|
| 251 |
+
width: 100%;
|
| 252 |
+
height: 100%;
|
| 253 |
+
background-color: rgba(0, 0, 0, 0.85);
|
| 254 |
+
z-index: 1000;
|
| 255 |
+
display: none;
|
| 256 |
+
justify-content: center;
|
| 257 |
+
align-items: center;
|
| 258 |
+
padding: 2rem;
|
| 259 |
+
box-sizing: border-box;
|
| 260 |
+
backdrop-filter: blur(5px);
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
#lightbox-content {
|
| 264 |
+
position: relative;
|
| 265 |
+
max-width: 80vw;
|
| 266 |
+
max-height: 90vh;
|
| 267 |
+
}
|
| 268 |
+
|
| 269 |
+
#lightbox-img {
|
| 270 |
+
max-width: 100%;
|
| 271 |
+
max-height: 90vh;
|
| 272 |
+
object-fit: contain;
|
| 273 |
+
border-radius: 1rem;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
#lightbox-close, #lightbox-download {
|
| 277 |
+
position: absolute;
|
| 278 |
+
top: -40px;
|
| 279 |
+
background-color: rgba(255, 255, 255, 0.2);
|
| 280 |
+
color: white;
|
| 281 |
+
border: none;
|
| 282 |
+
width: 35px;
|
| 283 |
+
height: 35px;
|
| 284 |
+
border-radius: 50%;
|
| 285 |
+
cursor: pointer;
|
| 286 |
+
font-size: 1.5rem;
|
| 287 |
+
display: flex;
|
| 288 |
+
justify-content: center;
|
| 289 |
+
align-items: center;
|
| 290 |
+
transition: background-color 0.2s;
|
| 291 |
+
}
|
| 292 |
+
#lightbox-close {
|
| 293 |
+
left: 10px;
|
| 294 |
+
}
|
| 295 |
+
#lightbox-download {
|
| 296 |
+
right: 10px;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
#lightbox-close:hover, #lightbox-download:hover {
|
| 300 |
+
background-color: rgba(255, 255, 255, 0.4);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
|
| 304 |
@media (max-width: 800px) {
|
| 305 |
.editor-grid {
|
|
|
|
| 338 |
<h2>۲. نتیجه را مشاهده کنید</h2>
|
| 339 |
<div id="result-container">
|
| 340 |
<div class="spinner" id="loader"></div>
|
| 341 |
+
<div id="result-grid"></div>
|
| 342 |
</div>
|
| 343 |
</div>
|
| 344 |
</div>
|
|
|
|
| 352 |
</main>
|
| 353 |
</div>
|
| 354 |
|
| 355 |
+
<!-- Lightbox Structure -->
|
| 356 |
+
<div id="lightbox">
|
| 357 |
+
<div id="lightbox-content">
|
| 358 |
+
<img id="lightbox-img" src="">
|
| 359 |
+
<button id="lightbox-close">×</button>
|
| 360 |
+
<a id="lightbox-download" href="#" download="edited-image.png" title="دانلود تصویر">
|
| 361 |
+
<svg fill="white" width="20px" height="20px" viewBox="0 0 24 24"><path d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z"/></svg>
|
| 362 |
+
</a>
|
| 363 |
+
</div>
|
| 364 |
+
</div>
|
| 365 |
+
|
| 366 |
<script>
|
| 367 |
// API Endpoint from the provided chatbot code
|
| 368 |
const API_URL = 'https://alfa-editor-worker.onrender.com/api/edit';
|
|
|
|
| 374 |
const dropZoneText = document.getElementById('drop-zone-text');
|
| 375 |
const promptInput = document.getElementById('prompt-input');
|
| 376 |
const submitBtn = document.getElementById('submit-btn');
|
| 377 |
+
const resultGrid = document.getElementById('result-grid');
|
| 378 |
const loader = document.getElementById('loader');
|
| 379 |
const errorMessage = document.getElementById('error-message');
|
| 380 |
+
const lightbox = document.getElementById('lightbox');
|
| 381 |
+
const lightboxImg = document.getElementById('lightbox-img');
|
| 382 |
+
const lightboxClose = document.getElementById('lightbox-close');
|
| 383 |
+
const lightboxDownload = document.getElementById('lightbox-download');
|
| 384 |
+
|
| 385 |
|
| 386 |
let uploadedFile = null;
|
| 387 |
|
|
|
|
| 390 |
dropZone.addEventListener('click', () => fileInput.click());
|
| 391 |
fileInput.addEventListener('change', (e) => {
|
| 392 |
const file = e.target.files[0];
|
| 393 |
+
if (file) handleFile(file);
|
|
|
|
|
|
|
| 394 |
});
|
| 395 |
|
|
|
|
| 396 |
dropZone.addEventListener('dragover', (e) => {
|
| 397 |
e.preventDefault();
|
| 398 |
dropZone.classList.add('dragover');
|
|
|
|
| 406 |
e.preventDefault();
|
| 407 |
dropZone.classList.remove('dragover');
|
| 408 |
const file = e.dataTransfer.files[0];
|
| 409 |
+
if (file) handleFile(file);
|
|
|
|
|
|
|
| 410 |
});
|
| 411 |
|
| 412 |
function handleFile(file) {
|
|
|
|
| 441 |
return;
|
| 442 |
}
|
| 443 |
|
|
|
|
| 444 |
setLoading(true);
|
| 445 |
|
|
|
|
| 446 |
const formData = new FormData();
|
| 447 |
formData.append('image', uploadedFile);
|
| 448 |
formData.append('prompt', prompt);
|
|
|
|
| 460 |
|
| 461 |
const result = await response.json();
|
| 462 |
|
| 463 |
+
if (result.image_urls && Array.isArray(result.image_urls) && result.image_urls.length > 0) {
|
| 464 |
+
displayResult(result.image_urls);
|
| 465 |
} else {
|
| 466 |
+
throw new Error('پاسخ معتبری از سرور دریافت نشد. ممکن است سرور موقتا با مشکل مواجه شده باشد.');
|
| 467 |
}
|
| 468 |
|
| 469 |
} catch (error) {
|
|
|
|
| 480 |
loader.style.display = 'block';
|
| 481 |
submitBtn.disabled = true;
|
| 482 |
submitBtn.textContent = 'در حال پردازش...';
|
| 483 |
+
resultGrid.innerHTML = '';
|
| 484 |
errorMessage.style.display = 'none';
|
| 485 |
} else {
|
| 486 |
loader.style.display = 'none';
|
|
|
|
| 489 |
}
|
| 490 |
}
|
| 491 |
|
| 492 |
+
function displayResult(imageUrls) {
|
| 493 |
+
resultGrid.innerHTML = ''; // Clear previous results
|
| 494 |
+
imageUrls.forEach(url => {
|
| 495 |
+
const img = document.createElement('img');
|
| 496 |
+
img.src = url;
|
| 497 |
+
img.alt = 'تصویر ویرایش شده';
|
| 498 |
+
img.addEventListener('click', () => openLightbox(url));
|
| 499 |
+
resultGrid.appendChild(img);
|
| 500 |
+
});
|
| 501 |
}
|
| 502 |
|
| 503 |
function clearResult() {
|
| 504 |
+
resultGrid.innerHTML = '';
|
|
|
|
| 505 |
errorMessage.style.display = 'none';
|
| 506 |
}
|
| 507 |
|
|
|
|
| 509 |
errorMessage.textContent = message;
|
| 510 |
errorMessage.style.display = 'block';
|
| 511 |
}
|
| 512 |
+
|
| 513 |
+
// --- Lightbox Functions ---
|
| 514 |
+
|
| 515 |
+
function openLightbox(url) {
|
| 516 |
+
lightboxImg.src = url;
|
| 517 |
+
lightboxDownload.href = url; // Set simple download link
|
| 518 |
+
lightbox.style.display = 'flex';
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
function closeLightbox() {
|
| 522 |
+
lightbox.style.display = 'none';
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
lightboxClose.addEventListener('click', closeLightbox);
|
| 526 |
+
lightbox.addEventListener('click', (e) => {
|
| 527 |
+
if (e.target === lightbox) { // Close if clicked on the background
|
| 528 |
+
closeLightbox();
|
| 529 |
+
}
|
| 530 |
+
});
|
| 531 |
|
| 532 |
</script>
|
| 533 |
</body>
|