Mahmoudmody777
commited on
Commit
•
f94ab89
1
Parent(s):
318214d
Update index.html
Browse files- index.html +68 -49
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>Image
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
@@ -25,12 +25,12 @@
|
|
25 |
position: sticky;
|
26 |
top: 0;
|
27 |
z-index: 2;
|
28 |
-
|
29 |
align-items: center;
|
30 |
justify-content: center;
|
31 |
}
|
32 |
-
|
33 |
-
|
34 |
max-height: 50px;
|
35 |
margin-right: 10px;
|
36 |
cursor: pointer;
|
@@ -51,23 +51,23 @@
|
|
51 |
margin-left: -30px;
|
52 |
margin-top: -30px;
|
53 |
}
|
54 |
-
|
55 |
-
|
56 |
display: flex;
|
57 |
flex-direction: column;
|
58 |
align-items: center;
|
59 |
flex: 1;
|
60 |
overflow-y: auto;
|
61 |
}
|
62 |
-
|
63 |
-
|
64 |
-
margin:
|
65 |
text-align: center;
|
66 |
font-size: 16px;
|
67 |
color: #333;
|
68 |
}
|
69 |
-
|
70 |
-
|
71 |
color: #007bff;
|
72 |
text-decoration: none;
|
73 |
}
|
@@ -76,6 +76,7 @@
|
|
76 |
text-decoration: underline;
|
77 |
}
|
78 |
|
|
|
79 |
.controls {
|
80 |
width: 80%;
|
81 |
margin: 20px auto;
|
@@ -145,7 +146,7 @@
|
|
145 |
}
|
146 |
|
147 |
.slider-value {
|
148 |
-
width: 40px;
|
149 |
text-align: center;
|
150 |
font-size: 14px;
|
151 |
margin-left: 10px;
|
@@ -177,21 +178,32 @@
|
|
177 |
position: relative;
|
178 |
}
|
179 |
|
180 |
-
.delete-button {
|
181 |
position: absolute;
|
182 |
top: 10px;
|
183 |
-
right: 10px;
|
184 |
background-color: red;
|
185 |
color: white;
|
186 |
border: none;
|
187 |
border-radius: 5px;
|
188 |
cursor: pointer;
|
189 |
padding: 5px 10px;
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
192 |
}
|
193 |
|
194 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
display: block;
|
196 |
}
|
197 |
|
@@ -277,7 +289,7 @@
|
|
277 |
}
|
278 |
|
279 |
input[type="range"] {
|
280 |
-
width: 100%;
|
281 |
}
|
282 |
|
283 |
.toggle-button {
|
@@ -317,7 +329,7 @@
|
|
317 |
</div>
|
318 |
|
319 |
<label for="prompt">Image Description:</label>
|
320 |
-
<textarea id="prompt" placeholder="Describe the image you want to generate" rows="4"
|
321 |
|
322 |
<div class="sliders">
|
323 |
<div class="slider-container">
|
@@ -337,12 +349,6 @@
|
|
337 |
<input type="range" id="steps" min="1" max="100" step="1" value="8">
|
338 |
<input class="slider-value" type="text" id="steps-value" value="8" readonly>
|
339 |
</div>
|
340 |
-
|
341 |
-
<div class="slider-container">
|
342 |
-
<label for="prompt-power">Prompt Power:</label>
|
343 |
-
<input type="range" id="prompt-power" min="1" max="10" step="0.1" value="3.5">
|
344 |
-
<input class="slider-value" type="text" id="prompt-power-value" value="3.5" readonly>
|
345 |
-
</div>
|
346 |
</div>
|
347 |
|
348 |
<button id="generate-btn">Generate Image</button>
|
@@ -370,11 +376,9 @@
|
|
370 |
const widthSlider = document.getElementById('width');
|
371 |
const heightSlider = document.getElementById('height');
|
372 |
const stepsSlider = document.getElementById('steps');
|
373 |
-
const promptPowerSlider = document.getElementById('prompt-power'); // خانة التحكم الجديدة
|
374 |
const widthValue = document.getElementById('width-value');
|
375 |
const heightValue = document.getElementById('height-value');
|
376 |
const stepsValue = document.getElementById('steps-value');
|
377 |
-
const promptPowerValue = document.getElementById('prompt-power-value'); // خانة التحكم الجديدة
|
378 |
const statusElement = document.getElementById('status');
|
379 |
const outputContainer = document.getElementById('output-container');
|
380 |
const modal = document.getElementById('modal');
|
@@ -401,7 +405,7 @@
|
|
401 |
|
402 |
function loadImagesFromStorage() {
|
403 |
const savedImages = JSON.parse(localStorage.getItem('images')) || [];
|
404 |
-
savedImages.forEach(imgObj => addImageToOutput(imgObj.url, imgObj.prompt, imgObj.width, imgObj.height, imgObj.steps
|
405 |
}
|
406 |
|
407 |
widthSlider.addEventListener('input', () => {
|
@@ -419,23 +423,12 @@
|
|
419 |
localStorage.setItem('lastSteps', stepsSlider.value);
|
420 |
});
|
421 |
|
422 |
-
promptPowerSlider.addEventListener('input', () => {
|
423 |
-
promptPowerValue.value = promptPowerSlider.value;
|
424 |
-
localStorage.setItem('lastPromptPower', promptPowerSlider.value);
|
425 |
-
});
|
426 |
-
|
427 |
generateBtn.addEventListener('click', async () => {
|
428 |
const prompt = promptInput.value;
|
429 |
const apiKey = apiKeyInput.value;
|
430 |
const width = widthSlider.value;
|
431 |
const height = heightSlider.value;
|
432 |
const steps = stepsSlider.value;
|
433 |
-
const promptPower = promptPowerSlider.value; // قيمة Prompt Power
|
434 |
-
|
435 |
-
if (prompt.length > 1000) {
|
436 |
-
alert('The prompt cannot exceed 1000 characters.');
|
437 |
-
return;
|
438 |
-
}
|
439 |
|
440 |
if (!prompt || !apiKey) {
|
441 |
alert('Please enter both a prompt and API key!');
|
@@ -448,9 +441,9 @@
|
|
448 |
statusElement.textContent = 'Generating image...';
|
449 |
|
450 |
try {
|
451 |
-
const requestId = await sendImageGenerationRequest(prompt, width, height, steps,
|
452 |
const imageUrl = await pollResult(requestId, apiKey);
|
453 |
-
addImageToOutput(imageUrl, prompt, width, height, steps
|
454 |
statusElement.textContent = 'Image generated successfully!';
|
455 |
} catch (error) {
|
456 |
statusElement.textContent = `Error: ${error.message}`;
|
@@ -463,31 +456,48 @@
|
|
463 |
toggleApiKeyBtn.textContent = isApiKeyVisible ? 'Hide' : 'Show';
|
464 |
});
|
465 |
|
466 |
-
function addImageToOutput(imageUrl, prompt, width, height, steps
|
467 |
const container = document.createElement('div');
|
468 |
container.className = 'image-container';
|
469 |
|
470 |
const img = document.createElement('img');
|
471 |
img.src = imageUrl;
|
472 |
img.alt = "Generated Image";
|
473 |
-
img.onclick = () => openModal(imageUrl, prompt, width, height, steps
|
474 |
|
|
|
475 |
const deleteButton = document.createElement('button');
|
476 |
deleteButton.className = 'delete-button';
|
477 |
-
|
|
|
|
|
|
|
478 |
deleteButton.onclick = (e) => {
|
479 |
e.stopPropagation();
|
480 |
container.remove();
|
481 |
removeImageFromStorage(imageUrl);
|
482 |
};
|
483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
container.appendChild(img);
|
485 |
container.appendChild(deleteButton);
|
|
|
486 |
outputContainer.prepend(container);
|
487 |
|
488 |
let savedImages = JSON.parse(localStorage.getItem('images')) || [];
|
489 |
if (!savedImages.some(imgObj => imgObj.url === imageUrl)) {
|
490 |
-
savedImages.push({ url: imageUrl, prompt: prompt, width: width, height: height, steps: steps
|
491 |
localStorage.setItem('images', JSON.stringify(savedImages));
|
492 |
}
|
493 |
}
|
@@ -498,11 +508,20 @@
|
|
498 |
localStorage.setItem('images', JSON.stringify(savedImages));
|
499 |
}
|
500 |
|
501 |
-
function openModal(imageUrl, prompt, width, height, steps
|
502 |
modal.style.display = 'flex';
|
503 |
modalImage.src = imageUrl;
|
504 |
promptInfo.innerText = `Prompt: ${prompt}`;
|
505 |
-
settingsInfo.innerText = `Width: ${width}, Height: ${height}, Steps: ${steps}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
}
|
507 |
|
508 |
copyPromptBtn.onclick = () => {
|
@@ -516,7 +535,7 @@
|
|
516 |
}
|
517 |
};
|
518 |
|
519 |
-
async function sendImageGenerationRequest(prompt, width, height, steps,
|
520 |
const response = await fetch('https://api.bfl.ml/v1/image', {
|
521 |
method: 'POST',
|
522 |
headers: {
|
@@ -528,7 +547,6 @@
|
|
528 |
width: parseInt(width),
|
529 |
height: parseInt(height),
|
530 |
steps: parseInt(steps),
|
531 |
-
promptPower: parseFloat(promptPower), // تمرير Prompt Power
|
532 |
}),
|
533 |
});
|
534 |
|
@@ -564,5 +582,6 @@
|
|
564 |
}
|
565 |
</script>
|
566 |
|
|
|
567 |
</body>
|
568 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Image Generator bfl api by mahmoudshokri</title>
|
7 |
<style>
|
8 |
body {
|
9 |
font-family: Arial, sans-serif;
|
|
|
25 |
position: sticky;
|
26 |
top: 0;
|
27 |
z-index: 2;
|
28 |
+
display: flex;
|
29 |
align-items: center;
|
30 |
justify-content: center;
|
31 |
}
|
32 |
+
|
33 |
+
.header img {
|
34 |
max-height: 50px;
|
35 |
margin-right: 10px;
|
36 |
cursor: pointer;
|
|
|
51 |
margin-left: -30px;
|
52 |
margin-top: -30px;
|
53 |
}
|
54 |
+
|
55 |
+
.container {
|
56 |
display: flex;
|
57 |
flex-direction: column;
|
58 |
align-items: center;
|
59 |
flex: 1;
|
60 |
overflow-y: auto;
|
61 |
}
|
62 |
+
|
63 |
+
.api-info {
|
64 |
+
margin: 19px;
|
65 |
text-align: center;
|
66 |
font-size: 16px;
|
67 |
color: #333;
|
68 |
}
|
69 |
+
|
70 |
+
.api-info a {
|
71 |
color: #007bff;
|
72 |
text-decoration: none;
|
73 |
}
|
|
|
76 |
text-decoration: underline;
|
77 |
}
|
78 |
|
79 |
+
|
80 |
.controls {
|
81 |
width: 80%;
|
82 |
margin: 20px auto;
|
|
|
146 |
}
|
147 |
|
148 |
.slider-value {
|
149 |
+
width: 40px; /* تصغير عرض خانة القياس */
|
150 |
text-align: center;
|
151 |
font-size: 14px;
|
152 |
margin-left: 10px;
|
|
|
178 |
position: relative;
|
179 |
}
|
180 |
|
181 |
+
.delete-button, .download-button {
|
182 |
position: absolute;
|
183 |
top: 10px;
|
|
|
184 |
background-color: red;
|
185 |
color: white;
|
186 |
border: none;
|
187 |
border-radius: 5px;
|
188 |
cursor: pointer;
|
189 |
padding: 5px 10px;
|
190 |
+
|
191 |
+
}
|
192 |
+
|
193 |
+
.delete-button {
|
194 |
+
left: 25px; /* وضع زر الحذف على اليسار */
|
195 |
+
background: border-box;
|
196 |
+
width: 55px;
|
197 |
}
|
198 |
|
199 |
+
.download-button {
|
200 |
+
left: 75px; /* وضع زر التحميل على اليمين */
|
201 |
+
width: 52px;
|
202 |
+
background: border-box;
|
203 |
+
}
|
204 |
+
|
205 |
+
.image-container:hover .delete-button,
|
206 |
+
.image-container:hover .download-button {
|
207 |
display: block;
|
208 |
}
|
209 |
|
|
|
289 |
}
|
290 |
|
291 |
input[type="range"] {
|
292 |
+
width: 100%; /* تكبير شريط التمرير */
|
293 |
}
|
294 |
|
295 |
.toggle-button {
|
|
|
329 |
</div>
|
330 |
|
331 |
<label for="prompt">Image Description:</label>
|
332 |
+
<textarea id="prompt" placeholder="Describe the image you want to generate" rows="4"></textarea>
|
333 |
|
334 |
<div class="sliders">
|
335 |
<div class="slider-container">
|
|
|
349 |
<input type="range" id="steps" min="1" max="100" step="1" value="8">
|
350 |
<input class="slider-value" type="text" id="steps-value" value="8" readonly>
|
351 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
</div>
|
353 |
|
354 |
<button id="generate-btn">Generate Image</button>
|
|
|
376 |
const widthSlider = document.getElementById('width');
|
377 |
const heightSlider = document.getElementById('height');
|
378 |
const stepsSlider = document.getElementById('steps');
|
|
|
379 |
const widthValue = document.getElementById('width-value');
|
380 |
const heightValue = document.getElementById('height-value');
|
381 |
const stepsValue = document.getElementById('steps-value');
|
|
|
382 |
const statusElement = document.getElementById('status');
|
383 |
const outputContainer = document.getElementById('output-container');
|
384 |
const modal = document.getElementById('modal');
|
|
|
405 |
|
406 |
function loadImagesFromStorage() {
|
407 |
const savedImages = JSON.parse(localStorage.getItem('images')) || [];
|
408 |
+
savedImages.forEach(imgObj => addImageToOutput(imgObj.url, imgObj.prompt, imgObj.width, imgObj.height, imgObj.steps));
|
409 |
}
|
410 |
|
411 |
widthSlider.addEventListener('input', () => {
|
|
|
423 |
localStorage.setItem('lastSteps', stepsSlider.value);
|
424 |
});
|
425 |
|
|
|
|
|
|
|
|
|
|
|
426 |
generateBtn.addEventListener('click', async () => {
|
427 |
const prompt = promptInput.value;
|
428 |
const apiKey = apiKeyInput.value;
|
429 |
const width = widthSlider.value;
|
430 |
const height = heightSlider.value;
|
431 |
const steps = stepsSlider.value;
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
if (!prompt || !apiKey) {
|
434 |
alert('Please enter both a prompt and API key!');
|
|
|
441 |
statusElement.textContent = 'Generating image...';
|
442 |
|
443 |
try {
|
444 |
+
const requestId = await sendImageGenerationRequest(prompt, width, height, steps, apiKey);
|
445 |
const imageUrl = await pollResult(requestId, apiKey);
|
446 |
+
addImageToOutput(imageUrl, prompt, width, height, steps);
|
447 |
statusElement.textContent = 'Image generated successfully!';
|
448 |
} catch (error) {
|
449 |
statusElement.textContent = `Error: ${error.message}`;
|
|
|
456 |
toggleApiKeyBtn.textContent = isApiKeyVisible ? 'Hide' : 'Show';
|
457 |
});
|
458 |
|
459 |
+
function addImageToOutput(imageUrl, prompt, width, height, steps) {
|
460 |
const container = document.createElement('div');
|
461 |
container.className = 'image-container';
|
462 |
|
463 |
const img = document.createElement('img');
|
464 |
img.src = imageUrl;
|
465 |
img.alt = "Generated Image";
|
466 |
+
img.onclick = () => openModal(imageUrl, prompt, width, height, steps);
|
467 |
|
468 |
+
// زر الحذف مع أيقونة
|
469 |
const deleteButton = document.createElement('button');
|
470 |
deleteButton.className = 'delete-button';
|
471 |
+
const deleteIcon = document.createElement('img');
|
472 |
+
deleteIcon.src = 'delete.png'; // استبدل بالمسار الصحيح للأيقونة
|
473 |
+
|
474 |
+
deleteButton.appendChild(deleteIcon);
|
475 |
deleteButton.onclick = (e) => {
|
476 |
e.stopPropagation();
|
477 |
container.remove();
|
478 |
removeImageFromStorage(imageUrl);
|
479 |
};
|
480 |
|
481 |
+
// زر التحميل مع أيقونة
|
482 |
+
const downloadButton = document.createElement('button');
|
483 |
+
downloadButton.className = 'download-button';
|
484 |
+
const downloadIcon = document.createElement('img');
|
485 |
+
downloadIcon.src = 'download.png'; // استبدل بالمسار الصحيح للأيقونة
|
486 |
+
|
487 |
+
downloadButton.appendChild(downloadIcon);
|
488 |
+
downloadButton.onclick = (e) => {
|
489 |
+
e.stopPropagation();
|
490 |
+
downloadImage(imageUrl);
|
491 |
+
};
|
492 |
+
|
493 |
container.appendChild(img);
|
494 |
container.appendChild(deleteButton);
|
495 |
+
container.appendChild(downloadButton);
|
496 |
outputContainer.prepend(container);
|
497 |
|
498 |
let savedImages = JSON.parse(localStorage.getItem('images')) || [];
|
499 |
if (!savedImages.some(imgObj => imgObj.url === imageUrl)) {
|
500 |
+
savedImages.push({ url: imageUrl, prompt: prompt, width: width, height: height, steps: steps });
|
501 |
localStorage.setItem('images', JSON.stringify(savedImages));
|
502 |
}
|
503 |
}
|
|
|
508 |
localStorage.setItem('images', JSON.stringify(savedImages));
|
509 |
}
|
510 |
|
511 |
+
function openModal(imageUrl, prompt, width, height, steps) {
|
512 |
modal.style.display = 'flex';
|
513 |
modalImage.src = imageUrl;
|
514 |
promptInfo.innerText = `Prompt: ${prompt}`;
|
515 |
+
settingsInfo.innerText = `Width: ${width}, Height: ${height}, Steps: ${steps}`;
|
516 |
+
}
|
517 |
+
|
518 |
+
function downloadImage(imageUrl) {
|
519 |
+
const a = document.createElement('a');
|
520 |
+
a.href = imageUrl;
|
521 |
+
a.download = 'generated-image.png'; // Specify the default filename
|
522 |
+
document.body.appendChild(a);
|
523 |
+
a.click();
|
524 |
+
document.body.removeChild(a);
|
525 |
}
|
526 |
|
527 |
copyPromptBtn.onclick = () => {
|
|
|
535 |
}
|
536 |
};
|
537 |
|
538 |
+
async function sendImageGenerationRequest(prompt, width, height, steps, apiKey) {
|
539 |
const response = await fetch('https://api.bfl.ml/v1/image', {
|
540 |
method: 'POST',
|
541 |
headers: {
|
|
|
547 |
width: parseInt(width),
|
548 |
height: parseInt(height),
|
549 |
steps: parseInt(steps),
|
|
|
550 |
}),
|
551 |
});
|
552 |
|
|
|
582 |
}
|
583 |
</script>
|
584 |
|
585 |
+
|
586 |
</body>
|
587 |
</html>
|