Create templates/index.html
Browse files- templates/index.html +103 -0
templates/index.html
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;600;800&display=swap" rel="stylesheet">
|
| 8 |
+
<style>
|
| 9 |
+
body { font-family: 'Vazirmatn', Tahoma, sans-serif; background-color: #EDF2F7; padding: 40px 20px; display: flex; justify-content: center; }
|
| 10 |
+
.container { background-color: #ffffff; border-radius: 12px; box-shadow: 0 10px 15px rgba(0,0,0,0.1); width: 100%; max-width: 500px; padding: 30px; }
|
| 11 |
+
h2 { text-align: center; color: #5A67D8; margin-top: 0; }
|
| 12 |
+
.form-group { margin-bottom: 20px; }
|
| 13 |
+
label { display: block; margin-bottom: 8px; font-weight: 600; }
|
| 14 |
+
textarea { width: 100%; padding: 12px; border: 1px solid #E2E8F0; border-radius: 8px; box-sizing: border-box; background: #F7FAFC; }
|
| 15 |
+
.size-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
|
| 16 |
+
.size-btn { padding: 10px; border: 1px solid #E2E8F0; border-radius: 8px; background: #F7FAFC; cursor: pointer; font-weight: 600; transition: 0.2s; }
|
| 17 |
+
.size-btn.active { background: #5A67D8; color: white; border-color: #5A67D8; }
|
| 18 |
+
button.main-btn { width: 100%; padding: 14px; background: #5A67D8; color: white; border: none; border-radius: 8px; font-size: 1.1rem; font-weight: bold; cursor: pointer; }
|
| 19 |
+
button.main-btn:disabled { background: #A3B1E1; cursor: not-allowed; }
|
| 20 |
+
#status-box { margin-top: 20px; padding: 15px; border-radius: 8px; display: none; text-align: center; background: #EBF4FF; color: #3182CE; font-weight: bold; }
|
| 21 |
+
#result-container { margin-top: 20px; display: none; text-align: center; }
|
| 22 |
+
#result-container img { max-width: 100%; border-radius: 8px; border: 2px solid #E2E8F0; }
|
| 23 |
+
</style>
|
| 24 |
+
</head>
|
| 25 |
+
<body>
|
| 26 |
+
<div class="container">
|
| 27 |
+
<h2>استودیو تصویر هوش مصنوعی</h2>
|
| 28 |
+
<div class="form-group">
|
| 29 |
+
<label>دستور ساخت تصویر (Prompt)</label>
|
| 30 |
+
<textarea id="prompt" rows="4" placeholder="مثال: A futuristic cyberpunk city..."></textarea>
|
| 31 |
+
</div>
|
| 32 |
+
<div class="form-group">
|
| 33 |
+
<label>ابعاد تصویر</label>
|
| 34 |
+
<div class="size-grid">
|
| 35 |
+
<button class="size-btn active" data-w="1024" data-h="1024" onclick="selectSize(this)">۱:۱ مربع</button>
|
| 36 |
+
<button class="size-btn" data-w="1344" data-h="768" onclick="selectSize(this)">۱۶:۹ افقی</button>
|
| 37 |
+
</div>
|
| 38 |
+
</div>
|
| 39 |
+
<button id="btn-submit" class="main-btn" onclick="generateImage()">🚀 ساخت تصویر</button>
|
| 40 |
+
<div id="status-box"></div>
|
| 41 |
+
<div id="result-container">
|
| 42 |
+
<h3 style="color: #2ea44f;">🎉 تصویر شما آماده است!</h3>
|
| 43 |
+
<img id="generated-image" src="" alt="AI Image">
|
| 44 |
+
</div>
|
| 45 |
+
</div>
|
| 46 |
+
|
| 47 |
+
<script>
|
| 48 |
+
let w = 1024, h = 1024, timer;
|
| 49 |
+
|
| 50 |
+
function selectSize(btn) {
|
| 51 |
+
document.querySelectorAll('.size-btn').forEach(b => b.classList.remove('active'));
|
| 52 |
+
btn.classList.add('active');
|
| 53 |
+
w = btn.getAttribute('data-w');
|
| 54 |
+
h = btn.getAttribute('data-h');
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
async function generateImage() {
|
| 58 |
+
const prompt = document.getElementById('prompt').value.trim();
|
| 59 |
+
if (!prompt) return alert('پرامپت خالی است!');
|
| 60 |
+
|
| 61 |
+
document.getElementById('btn-submit').disabled = true;
|
| 62 |
+
document.getElementById('result-container').style.display = 'none';
|
| 63 |
+
const statusBox = document.getElementById('status-box');
|
| 64 |
+
statusBox.style.display = 'block';
|
| 65 |
+
statusBox.innerHTML = 'در حال ارتباط با سرور... ⏳';
|
| 66 |
+
|
| 67 |
+
try {
|
| 68 |
+
// درخواست به بکاندِ داکر اسپیسِ خودمان
|
| 69 |
+
const res = await fetch('/api/generate', {
|
| 70 |
+
method: 'POST', headers: {'Content-Type': 'application/json'},
|
| 71 |
+
body: JSON.stringify({ prompt, width: w, height: h })
|
| 72 |
+
});
|
| 73 |
+
const data = await res.json();
|
| 74 |
+
|
| 75 |
+
if (data.status === 'success') {
|
| 76 |
+
statusBox.innerHTML = 'گیتهاب در حال ساخت و آپلود تصویر است... (حدود ۳۰ تا ۶۰ ثانیه) 🎨';
|
| 77 |
+
// بررسی دورهای تا زمانی که گیت هاب عکس را در سرور آپلود کند
|
| 78 |
+
timer = setInterval(() => checkStatus(data.run_id), 3000);
|
| 79 |
+
} else {
|
| 80 |
+
statusBox.innerHTML = 'خطا در ارسال به گیتهاب!';
|
| 81 |
+
document.getElementById('btn-submit').disabled = false;
|
| 82 |
+
}
|
| 83 |
+
} catch (e) {
|
| 84 |
+
statusBox.innerHTML = 'خطای ارتباط با سرور.';
|
| 85 |
+
document.getElementById('btn-submit').disabled = false;
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
async function checkStatus(run_id) {
|
| 90 |
+
let res = await fetch(`/api/status/${run_id}`);
|
| 91 |
+
let data = await res.json();
|
| 92 |
+
|
| 93 |
+
if (data.status === 'ready') {
|
| 94 |
+
clearInterval(timer);
|
| 95 |
+
document.getElementById('status-box').style.display = 'none';
|
| 96 |
+
document.getElementById('result-container').style.display = 'block';
|
| 97 |
+
document.getElementById('generated-image').src = data.url; // نمایش عکسی که در داکر ذخیره شده
|
| 98 |
+
document.getElementById('btn-submit').disabled = false;
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
</script>
|
| 102 |
+
</body>
|
| 103 |
+
</html>
|