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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="fa" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>AI Photoshop Pro</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
--app-font: 'Vazirmatn', sans-serif; --app-bg: #F8F9FC; --panel-bg: #FFFFFF;
|
| 11 |
+
--panel-border: #EAEFF7; --input-bg: #F6F8FB; --input-border: #E1E7EF;
|
| 12 |
+
--text-primary: #1A202C; --text-secondary: #626F86; --text-tertiary: #8A94A6;
|
| 13 |
+
--accent-primary: #4A6CFA; --accent-primary-hover: #3553D6;
|
| 14 |
+
--accent-primary-glow: rgba(74, 108, 250, 0.25); --accent-secondary: #0FD4A8;
|
| 15 |
+
--danger-color: #e53e3e;
|
| 16 |
+
--radius-card: 24px; --radius-btn: 14px; --radius-input: 12px;
|
| 17 |
+
--transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
| 21 |
+
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
| 22 |
+
@keyframes pulse { 0% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } 50% { box-shadow: 0 0 60px rgba(56, 189, 248, 0.7); } 100% { box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); } }
|
| 23 |
+
@keyframes glow-text { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }
|
| 24 |
+
|
| 25 |
+
body { font-family: var(--app-font); background-color: var(--app-bg); color: var(--text-primary); margin: 0; padding: 2.5rem 1rem; display: flex; justify-content: center; min-height: 100vh; }
|
| 26 |
+
.container { max-width: 820px; width: 100%; }
|
| 27 |
+
header { text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s ease-out; }
|
| 28 |
+
h1 { font-size: 2.8rem; font-weight: 800; margin: 0 0 0.8rem; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
| 29 |
+
.subtitle { font-size: 1.1rem; color: var(--text-secondary); margin-top: 0; }
|
| 30 |
+
main { padding: 3rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.05); border: 1px solid var(--panel-border); animation: fadeIn 0.8s ease-out backwards; }
|
| 31 |
+
.form-group { margin-bottom: 2.5rem; }
|
| 32 |
+
.form-label { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; font-size: 1.2em; margin-bottom: 1.2rem; }
|
| 33 |
+
.form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
|
| 34 |
+
|
| 35 |
+
#upload-area { position: relative; border: 2px dashed var(--input-border); border-radius: var(--radius-input); padding: 2.5rem; text-align: center; cursor: pointer; background-color: var(--input-bg); min-height: 200px; display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; }
|
| 36 |
+
#upload-area:hover { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 15px var(--accent-primary-glow); }
|
| 37 |
+
#upload-area.has-file { border-style: solid; border-color: var(--panel-border); padding: 0; cursor: default; }
|
| 38 |
+
#upload-content { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
|
| 39 |
+
#upload-icon svg { width: 48px; height: 48px; color: var(--accent-primary); }
|
| 40 |
+
#preview-image-main { display: none; width: 100%; height: 100%; object-fit: contain; position: absolute; top: 0; left: 0; }
|
| 41 |
+
#remove-file-btn { display: none; position: absolute; top: 12px; right: 12px; background-color: rgba(26,32,44,0.6); color: white; border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; z-index: 10; padding: 0; }
|
| 42 |
+
#remove-file-btn:hover { background-color: var(--danger-color); }
|
| 43 |
+
#upload-area.has-file #upload-content { display: none; }
|
| 44 |
+
#upload-area.has-file #preview-image-main, #upload-area.has-file #remove-file-btn { display: block; }
|
| 45 |
+
|
| 46 |
+
textarea { width: 100%; padding: 1rem 1.2rem; border-radius: var(--radius-input); border: 1px solid var(--input-border); background-color: var(--input-bg); font-family: inherit; font-size: 1rem; box-sizing: border-box; min-height: 90px; resize: vertical; }
|
| 47 |
+
textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow); background-color: var(--panel-bg); }
|
| 48 |
+
|
| 49 |
+
#submit-btn { display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 1.1rem; font-size: 1.2rem; font-weight: 700; background: linear-gradient(95deg, var(--accent-secondary) 0%, var(--accent-primary) 100%); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; transition: all 0.3s ease; box-shadow: 0 6px 12px -3px var(--accent-primary-glow); margin-top: 1rem; }
|
| 50 |
+
#submit-btn:hover:not(:disabled) { transform: translateY(-5px); }
|
| 51 |
+
#submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; box-shadow: none; transform: none; }
|
| 52 |
+
.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.8s linear infinite; display: none; }
|
| 53 |
+
|
| 54 |
+
#result-container { min-height: 350px; position: relative; padding: 1rem; background-color: var(--input-bg); border-radius: var(--radius-card); border: 2px dashed var(--input-border); display: flex; align-items: center; justify-content: center; flex-direction: column;}
|
| 55 |
+
.generator-container { position: relative; width: 400px; max-width: 100%; height: 250px; border: 2px solid #38bdf8; border-radius: 20px; overflow: hidden; background-color: #161b22; color: #f0f6fc; display: none; flex-direction: column; justify-content: center; align-items: center; animation: pulse 5s infinite; }
|
| 56 |
+
.text-overlay { font-size: 18px; font-weight: 700; animation: glow-text 3s infinite ease-in-out; text-align: center; z-index: 2; padding: 10px; }
|
| 57 |
+
.progress-bar { position: absolute; bottom: 0; left: 0; width: 0%; height: 6px; background: linear-gradient(to right, #38bdf8, #bb86fc, #facc15); transition: 1s linear; z-index: 2; }
|
| 58 |
+
#result-image-wrapper { display: none; width: 100%; text-align: center; }
|
| 59 |
+
#result-image-display { max-width: 100%; max-height: 500px; border-radius: var(--radius-input); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
|
| 60 |
+
.download-button { padding: 12px 25px; margin-top: 1.5rem; border: none; border-radius: var(--radius-btn); font-size: 1rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 0.7rem; background-color: var(--accent-primary); color: white; box-shadow: var(--shadow-md); text-decoration: none; }
|
| 61 |
+
.download-button:hover { background-color: var(--accent-primary-hover); transform: translateY(-3px); }
|
| 62 |
+
.download-button svg { width: 20px; height: 20px; }
|
| 63 |
+
</style>
|
| 64 |
+
</head>
|
| 65 |
+
<body>
|
| 66 |
+
<div class="container">
|
| 67 |
+
<header>
|
| 68 |
+
<h1>فتوشاپ هوش مصنوعی ✨</h1>
|
| 69 |
+
<p class="subtitle">تصاویر خود را با قدرت هوش مصنوعی و به زبان ساده ویرایش کنید</p>
|
| 70 |
+
</header>
|
| 71 |
+
<main>
|
| 72 |
+
<div class="form-group">
|
| 73 |
+
<div class="form-label">
|
| 74 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4Z"/></svg>
|
| 75 |
+
۱. تصویر خود را انتخاب کنید
|
| 76 |
+
</div>
|
| 77 |
+
<label id="upload-area" for="file-input">
|
| 78 |
+
<div id="upload-content">
|
| 79 |
+
<div id="upload-icon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="17 8 12 3 7 8"></polyline><line x1="12" y1="3" x2="12" y2="15"></line></svg></div>
|
| 80 |
+
<p>فایل تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</p>
|
| 81 |
+
</div>
|
| 82 |
+
<img id="preview-image-main" src="" alt="Preview">
|
| 83 |
+
<button type="button" id="remove-file-btn" title="حذف تصویر">×</button>
|
| 84 |
+
</label>
|
| 85 |
+
<input type="file" id="file-input" accept="image/png, image/jpeg, image/webp" hidden>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<div class="form-group">
|
| 89 |
+
<label class="form-label">
|
| 90 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>
|
| 91 |
+
۲. دستور ویرایش را بنویسید
|
| 92 |
+
</label>
|
| 93 |
+
<textarea id="prompt-input" rows="3" placeholder="مثال: پسزمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
|
| 94 |
+
|
| 95 |
+
<button id="submit-btn" disabled>
|
| 96 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/></svg>
|
| 97 |
+
<span id="btn-text">ایجاد کن</span>
|
| 98 |
+
<div class="spinner"></div>
|
| 99 |
+
</button>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<div class="form-group">
|
| 103 |
+
<div class="form-label">
|
| 104 |
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/><path d="M21 14l-1.5 3-3-1.5 3-3 1.5 3z"/><path d="M19.5 2.5l-3 1.5 1.5 3 3-1.5-1.5-3z"/></svg>
|
| 105 |
+
۳. نتیجه نهایی
|
| 106 |
+
</div>
|
| 107 |
+
<div id="result-container">
|
| 108 |
+
<p id="idle-text" style="color: var(--text-secondary);">برای شروع عکس و متن را وارد کنید.</p>
|
| 109 |
+
|
| 110 |
+
<div class="generator-container" id="loading-box">
|
| 111 |
+
<div class="text-overlay" id="loading-text">در حال پردازش...</div>
|
| 112 |
+
<div class="progress-bar" id="progress-bar"></div>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<div id="result-image-wrapper">
|
| 116 |
+
<img id="result-image-display" src="">
|
| 117 |
+
<div>
|
| 118 |
+
<a id="download-btn" href="#" download="edited_image.webp" class="download-button">
|
| 119 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
|
| 120 |
+
<span>دانلود تصویر ویرایش شده</span>
|
| 121 |
+
</a>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
</main>
|
| 127 |
+
</div>
|
| 128 |
+
|
| 129 |
+
<script>
|
| 130 |
+
const uploadArea = document.getElementById('upload-area');
|
| 131 |
+
const fileInput = document.getElementById('file-input');
|
| 132 |
+
const previewImage = document.getElementById('preview-image-main');
|
| 133 |
+
const removeFileBtn = document.getElementById('remove-file-btn');
|
| 134 |
+
const promptInput = document.getElementById('prompt-input');
|
| 135 |
+
const submitBtn = document.getElementById('submit-btn');
|
| 136 |
+
const resultContainer = document.getElementById('result-container');
|
| 137 |
+
|
| 138 |
+
let uploadedFile = null;
|
| 139 |
+
let pollTimer = null;
|
| 140 |
+
|
| 141 |
+
// --- مدیریت آپلود عکس ---
|
| 142 |
+
function handleFile(file) {
|
| 143 |
+
if (!file || !file.type.startsWith('image/')) return alert('لطفاً یک تصویر انتخاب کنید.');
|
| 144 |
+
uploadedFile = file;
|
| 145 |
+
const reader = new FileReader();
|
| 146 |
+
reader.onload = (e) => { previewImage.src = e.target.result; };
|
| 147 |
+
reader.readAsDataURL(file);
|
| 148 |
+
uploadArea.classList.add('has-file');
|
| 149 |
+
checkFormState();
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
removeFileBtn.onclick = (e) => {
|
| 153 |
+
e.preventDefault(); e.stopPropagation();
|
| 154 |
+
uploadedFile = null; fileInput.value = ''; previewImage.src = '';
|
| 155 |
+
uploadArea.classList.remove('has-file');
|
| 156 |
+
checkFormState();
|
| 157 |
+
};
|
| 158 |
+
|
| 159 |
+
fileInput.onchange = (e) => handleFile(e.target.files[0]);
|
| 160 |
+
uploadArea.ondragover = (e) => { e.preventDefault(); uploadArea.classList.add('drag-over'); };
|
| 161 |
+
uploadArea.ondragleave = () => uploadArea.classList.remove('drag-over');
|
| 162 |
+
uploadArea.ondrop = (e) => { e.preventDefault(); uploadArea.classList.remove('drag-over'); handleFile(e.dataTransfer.files[0]); };
|
| 163 |
+
|
| 164 |
+
function checkFormState() {
|
| 165 |
+
submitBtn.disabled = !(uploadedFile && promptInput.value.trim() !== '');
|
| 166 |
+
}
|
| 167 |
+
promptInput.oninput = checkFormState;
|
| 168 |
+
|
| 169 |
+
// --- مدیریت ارسال به سرور ---
|
| 170 |
+
submitBtn.onclick = async () => {
|
| 171 |
+
submitBtn.disabled = true;
|
| 172 |
+
document.getElementById('btn-text').style.display = 'none';
|
| 173 |
+
document.querySelector('.spinner').style.display = 'inline-block';
|
| 174 |
+
|
| 175 |
+
document.getElementById('idle-text').style.display = 'none';
|
| 176 |
+
document.getElementById('result-image-wrapper').style.display = 'none';
|
| 177 |
+
document.getElementById('loading-box').style.display = 'flex';
|
| 178 |
+
document.getElementById('result-container').style.borderStyle = 'none';
|
| 179 |
+
|
| 180 |
+
const formData = new FormData();
|
| 181 |
+
formData.append('image', uploadedFile);
|
| 182 |
+
formData.append('prompt', promptInput.value.trim());
|
| 183 |
+
|
| 184 |
+
try {
|
| 185 |
+
document.getElementById('loading-text').innerHTML = 'در حال آپلود و ترجمه...<br><small>مرحله ۱ از ۳</small>';
|
| 186 |
+
document.getElementById('progress-bar').style.width = '30%';
|
| 187 |
+
|
| 188 |
+
const res = await fetch('/api/edit', {
|
| 189 |
+
method: 'POST',
|
| 190 |
+
body: formData
|
| 191 |
+
});
|
| 192 |
+
|
| 193 |
+
const data = await res.json();
|
| 194 |
+
|
| 195 |
+
if (data.status === 'success') {
|
| 196 |
+
document.getElementById('loading-text').innerHTML = `دستور ترجمه شد: ${data.translated}<br><small>مرحله ۲ از ۳: در حال ویرایش تصویر در سرور... (حدود ۱ دقیقه)</small>`;
|
| 197 |
+
document.getElementById('progress-bar').style.width = '60%';
|
| 198 |
+
pollTimer = setInterval(() => checkResult(data.run_id), 3000);
|
| 199 |
+
} else {
|
| 200 |
+
alert('خطا در ارسال به گیتهاب!');
|
| 201 |
+
resetBtn();
|
| 202 |
+
}
|
| 203 |
+
} catch (e) {
|
| 204 |
+
alert('خطای اتصال به سرور!');
|
| 205 |
+
resetBtn();
|
| 206 |
+
}
|
| 207 |
+
};
|
| 208 |
+
|
| 209 |
+
async function checkResult(run_id) {
|
| 210 |
+
try {
|
| 211 |
+
const res = await fetch(`/api/status/${run_id}`);
|
| 212 |
+
const data = await res.json();
|
| 213 |
+
|
| 214 |
+
if (data.status === 'ready') {
|
| 215 |
+
clearInterval(pollTimer);
|
| 216 |
+
document.getElementById('loading-box').style.display = 'none';
|
| 217 |
+
document.getElementById('result-container').style.borderStyle = 'solid';
|
| 218 |
+
|
| 219 |
+
const resultImg = document.getElementById('result-image-display');
|
| 220 |
+
resultImg.src = data.url;
|
| 221 |
+
document.getElementById('download-btn').href = data.url;
|
| 222 |
+
|
| 223 |
+
document.getElementById('result-image-wrapper').style.display = 'block';
|
| 224 |
+
resetBtn();
|
| 225 |
+
}
|
| 226 |
+
} catch(e) { console.log('Polling...', e); }
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
function resetBtn() {
|
| 230 |
+
submitBtn.disabled = false;
|
| 231 |
+
document.getElementById('btn-text').style.display = 'inline-block';
|
| 232 |
+
document.querySelector('.spinner').style.display = 'none';
|
| 233 |
+
}
|
| 234 |
+
</script>
|
| 235 |
+
</body>
|
| 236 |
+
</html>
|