Elias207 commited on
Commit
0a41c97
·
verified ·
1 Parent(s): f3143f3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +428 -19
index.html CHANGED
@@ -1,19 +1,428 @@
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="fa" dir="rtl">
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 {
10
+ --bg-color: #f8f9fa;
11
+ --text-color: #212529;
12
+ --card-bg: #ffffff;
13
+ --border-color: #dee2e6;
14
+ --primary-color-start: #3b82f6;
15
+ --primary-color-end: #8b5cf6;
16
+ --shadow-color: rgba(0, 0, 0, 0.1);
17
+ --drop-zone-bg: #f1f5f9;
18
+ --drop-zone-border-active: #a5b4fc;
19
+ }
20
+
21
+ .dark {
22
+ --bg-color: #111827;
23
+ --text-color: #d1d5db;
24
+ --card-bg: #1f2937;
25
+ --border-color: #374151;
26
+ --shadow-color: rgba(0, 0, 0, 0.25);
27
+ --drop-zone-bg: #374151;
28
+ --drop-zone-border-active: #6366f1;
29
+ }
30
+
31
+ body {
32
+ font-family: 'Vazirmatn', sans-serif;
33
+ background-color: var(--bg-color);
34
+ color: var(--text-color);
35
+ margin: 0;
36
+ padding: 2rem;
37
+ display: flex;
38
+ justify-content: center;
39
+ align-items: flex-start;
40
+ min-height: 100vh;
41
+ transition: background-color 0.3s, color 0.3s;
42
+ }
43
+
44
+ .container {
45
+ max-width: 900px;
46
+ width: 100%;
47
+ }
48
+
49
+ header {
50
+ text-align: center;
51
+ margin-bottom: 2.5rem;
52
+ }
53
+
54
+ h1 {
55
+ font-size: 2.5rem;
56
+ font-weight: 700;
57
+ margin: 0;
58
+ background: linear-gradient(45deg, var(--primary-color-start), var(--primary-color-end));
59
+ -webkit-background-clip: text;
60
+ -webkit-text-fill-color: transparent;
61
+ background-clip: text;
62
+ color: transparent;
63
+ }
64
+
65
+ p.subtitle {
66
+ font-size: 1.1rem;
67
+ color: #6b7280;
68
+ margin-top: 0.5rem;
69
+ }
70
+
71
+ .dark p.subtitle {
72
+ color: #9ca3af;
73
+ }
74
+
75
+ main {
76
+ background-color: var(--card-bg);
77
+ border-radius: 1.5rem;
78
+ box-shadow: 0 10px 30px var(--shadow-color);
79
+ padding: 2.5rem;
80
+ transition: background-color 0.3s;
81
+ }
82
+
83
+ .editor-grid {
84
+ display: grid;
85
+ grid-template-columns: 1fr 1fr;
86
+ gap: 2.5rem;
87
+ }
88
+
89
+ .panel {
90
+ display: flex;
91
+ flex-direction: column;
92
+ }
93
+
94
+ h2 {
95
+ font-size: 1.25rem;
96
+ font-weight: 600;
97
+ margin-top: 0;
98
+ margin-bottom: 1.5rem;
99
+ border-bottom: 2px solid var(--border-color);
100
+ padding-bottom: 0.75rem;
101
+ }
102
+
103
+ #drop-zone {
104
+ border: 3px dashed var(--border-color);
105
+ border-radius: 1rem;
106
+ padding: 2rem;
107
+ text-align: center;
108
+ cursor: pointer;
109
+ transition: all 0.3s ease;
110
+ position: relative;
111
+ overflow: hidden;
112
+ background-color: var(--drop-zone-bg);
113
+ height: 100%;
114
+ display: flex;
115
+ flex-direction: column;
116
+ justify-content: center;
117
+ align-items: center;
118
+ }
119
+
120
+ #drop-zone.dragover {
121
+ border-color: var(--drop-zone-border-active);
122
+ background-color: rgba(99, 102, 241, 0.1);
123
+ }
124
+
125
+ #drop-zone-text {
126
+ color: #4b5563;
127
+ }
128
+ .dark #drop-zone-text { color: #d1d5db; }
129
+
130
+ #image-preview {
131
+ max-width: 100%;
132
+ max-height: 300px;
133
+ border-radius: 0.75rem;
134
+ object-fit: contain;
135
+ display: none;
136
+ }
137
+
138
+ .controls {
139
+ margin-top: 2rem;
140
+ }
141
+
142
+ textarea {
143
+ width: 100%;
144
+ padding: 1rem;
145
+ border: 2px solid var(--border-color);
146
+ border-radius: 0.75rem;
147
+ background-color: var(--bg-color);
148
+ color: var(--text-color);
149
+ font-family: 'Vazirmatn', sans-serif;
150
+ font-size: 1rem;
151
+ resize: vertical;
152
+ min-height: 80px;
153
+ box-sizing: border-box;
154
+ transition: all 0.3s ease;
155
+ }
156
+
157
+ textarea:focus {
158
+ outline: none;
159
+ border-color: var(--primary-color-start);
160
+ box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
161
+ }
162
+
163
+ button#submit-btn {
164
+ width: 100%;
165
+ padding: 1rem;
166
+ border: none;
167
+ border-radius: 0.75rem;
168
+ background: linear-gradient(45deg, var(--primary-color-start), var(--primary-color-end));
169
+ color: white;
170
+ font-size: 1.1rem;
171
+ font-weight: 600;
172
+ cursor: pointer;
173
+ margin-top: 1rem;
174
+ transition: all 0.3s ease;
175
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
176
+ }
177
+
178
+ button#submit-btn:hover:not(:disabled) {
179
+ transform: translateY(-2px);
180
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
181
+ }
182
+
183
+ button#submit-btn:disabled {
184
+ opacity: 0.5;
185
+ cursor: not-allowed;
186
+ }
187
+
188
+ #result-container {
189
+ border: 3px solid var(--border-color);
190
+ border-radius: 1rem;
191
+ min-height: 300px;
192
+ display: flex;
193
+ justify-content: center;
194
+ align-items: center;
195
+ position: relative;
196
+ background-color: var(--drop-zone-bg);
197
+ overflow: hidden;
198
+ }
199
+
200
+ #result-image {
201
+ max-width: 100%;
202
+ max-height: 400px;
203
+ border-radius: 0.75rem;
204
+ object-fit: contain;
205
+ display: none;
206
+ }
207
+
208
+ .spinner {
209
+ width: 50px;
210
+ height: 50px;
211
+ border: 5px solid rgba(0,0,0,0.1);
212
+ border-left-color: var(--primary-color-start);
213
+ border-radius: 50%;
214
+ animation: spin 1s linear infinite;
215
+ position: absolute;
216
+ display: none;
217
+ }
218
+
219
+ @keyframes spin {
220
+ to { transform: rotate(360deg); }
221
+ }
222
+
223
+ #error-message {
224
+ color: #ef4444;
225
+ text-align: center;
226
+ margin-top: 1rem;
227
+ display: none;
228
+ font-weight: 500;
229
+ }
230
+
231
+ @media (max-width: 800px) {
232
+ .editor-grid {
233
+ grid-template-columns: 1fr;
234
+ gap: 2rem;
235
+ }
236
+ body {
237
+ padding: 1rem;
238
+ }
239
+ main {
240
+ padding: 1.5rem;
241
+ }
242
+ }
243
+ </style>
244
+ </head>
245
+ <body>
246
+
247
+ <div class="container">
248
+ <header>
249
+ <h1>فتوشاپ هوش مصنوعی</h1>
250
+ <p class="subtitle">تصاویر خود را با قدرت هوش مصنوعی و به زبان ساده ویرایش کنید</p>
251
+ </header>
252
+
253
+ <main>
254
+ <div class="editor-grid">
255
+ <div class="panel">
256
+ <h2>۱. تصویر خود را آپلود کنید</h2>
257
+ <div id="drop-zone">
258
+ <span id="drop-zone-text">تصویر را اینجا بکشید یا برای انتخاب کلیک کنید</span>
259
+ <img id="image-preview" src="#" alt="پیش‌نمایش تصویر" />
260
+ </div>
261
+ <input type="file" id="file-input" accept="image/*" hidden>
262
+ </div>
263
+
264
+ <div class="panel">
265
+ <h2>۲. نتیجه را مشاهده کنید</h2>
266
+ <div id="result-container">
267
+ <div class="spinner" id="loader"></div>
268
+ <img id="result-image" src="#" alt="تصویر ویرایش شده" />
269
+ </div>
270
+ </div>
271
+ </div>
272
+
273
+ <div class="controls">
274
+ <h2>۳. دستور ویرایش را وارد کنید</h2>
275
+ <textarea id="prompt-input" rows="3" placeholder="مثال: پس‌زمینه را حذف کن و یک ساحل آفتابی قرار بده"></textarea>
276
+ <button id="submit-btn" disabled>ویرایش کن</button>
277
+ <p id="error-message"></p>
278
+ </div>
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';
285
+
286
+ // DOM Elements
287
+ const dropZone = document.getElementById('drop-zone');
288
+ const fileInput = document.getElementById('file-input');
289
+ const imagePreview = document.getElementById('image-preview');
290
+ const dropZoneText = document.getElementById('drop-zone-text');
291
+ const promptInput = document.getElementById('prompt-input');
292
+ const submitBtn = document.getElementById('submit-btn');
293
+ const resultImage = document.getElementById('result-image');
294
+ const loader = document.getElementById('loader');
295
+ const errorMessage = document.getElementById('error-message');
296
+
297
+ let uploadedFile = null;
298
+
299
+ // --- File Upload Logic ---
300
+
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');
313
+ });
314
+
315
+ dropZone.addEventListener('dragleave', () => {
316
+ dropZone.classList.remove('dragover');
317
+ });
318
+
319
+ dropZone.addEventListener('drop', (e) => {
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) {
329
+ if (!file.type.startsWith('image/')) {
330
+ displayError('لطفا یک فایل تصویری انتخاب کنید.');
331
+ return;
332
+ }
333
+
334
+ uploadedFile = file;
335
+
336
+ const reader = new FileReader();
337
+ reader.onload = (e) => {
338
+ imagePreview.src = e.target.result;
339
+ imagePreview.style.display = 'block';
340
+ dropZoneText.style.display = 'none';
341
+ submitBtn.disabled = false;
342
+ clearResult();
343
+ };
344
+ reader.readAsDataURL(file);
345
+ }
346
+
347
+ // --- API Call Logic ---
348
+
349
+ submitBtn.addEventListener('click', async () => {
350
+ if (!uploadedFile) {
351
+ displayError('ابتدا باید یک تصویر آپلود کنید.');
352
+ return;
353
+ }
354
+ const prompt = promptInput.value.trim();
355
+ if (!prompt) {
356
+ displayError('لطفا دستور ویرایش را وارد کنید.');
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);
367
+
368
+ try {
369
+ const response = await fetch(API_URL, {
370
+ method: 'POST',
371
+ body: formData,
372
+ });
373
+
374
+ if (!response.ok) {
375
+ const errorData = await response.json().catch(() => ({ error: `خطای سرور: ${response.statusText}` }));
376
+ throw new Error(errorData.error || `یک خطای ناشناخته رخ داد.`);
377
+ }
378
+
379
+ const result = await response.json();
380
+
381
+ if (result.image_urls && result.image_urls.length > 0) {
382
+ displayResult(result.image_urls[0]);
383
+ } else {
384
+ throw new Error('پاسخ معتبری از سرور دریافت نشد.');
385
+ }
386
+
387
+ } catch (error) {
388
+ displayError(error.message);
389
+ } finally {
390
+ setLoading(false);
391
+ }
392
+ });
393
+
394
+ // --- UI Helper Functions ---
395
+
396
+ function setLoading(isLoading) {
397
+ if (isLoading) {
398
+ loader.style.display = 'block';
399
+ submitBtn.disabled = true;
400
+ submitBtn.textContent = 'در حال پردازش...';
401
+ resultImage.style.display = 'none';
402
+ errorMessage.style.display = 'none';
403
+ } else {
404
+ loader.style.display = 'none';
405
+ submitBtn.disabled = false;
406
+ submitBtn.textContent = 'ویرایش کن';
407
+ }
408
+ }
409
+
410
+ function displayResult(imageUrl) {
411
+ resultImage.src = imageUrl;
412
+ resultImage.style.display = 'block';
413
+ }
414
+
415
+ function clearResult() {
416
+ resultImage.src = '#';
417
+ resultImage.style.display = 'none';
418
+ errorMessage.style.display = 'none';
419
+ }
420
+
421
+ function displayError(message) {
422
+ errorMessage.textContent = message;
423
+ errorMessage.style.display = 'block';
424
+ }
425
+
426
+ </script>
427
+ </body>
428
+ </html>