runflare / templates /cartoon.html
Sada8888's picture
Create cartoon.html
a027658 verified
Raw
History Blame Contribute Delete
24 kB
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>خلق تصاویر کارتونی</title>
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<style>
/* تمام CSS های اختصاصی شما بدون هیچ تغییری حفظ شده است */
:root {
--app-font: 'Vazirmatn', sans-serif;
--app-bg: #F8F9FC; --panel-bg: #FFFFFF; --panel-border: #EAEFF7;
--input-bg: #F6F8FB; --input-border: #E1E7EF;
--text-primary: #1A202C; --text-secondary: #626F86; --text-tertiary: #8A94A6;
--accent-primary: #4A6CFA; --accent-primary-hover: #3553D6;
--accent-primary-glow: rgba(74, 108, 250, 0.25);
--accent-secondary: #0FD4A8;
--shadow-sm: 0 1px 2px 0 rgba(26, 32, 44, 0.03);
--shadow-md: 0 4px 6px -1px rgba(26, 32, 44, 0.05);
--shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07);
--radius-card: 24px; --radius-btn: 14px; --radius-input: 12px;
--transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@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); } }
@keyframes glow-text { 0% { opacity: 0.7; } 50% { opacity: 1; } 100% { opacity: 0.7; } }
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; }
.container { max-width: 820px; width: 100%; }
header { position: relative; text-align: center; margin-bottom: 2.5rem; padding: 2rem 0; animation: fadeIn 0.8s 0.1s ease-out backwards; overflow: hidden; }
#neural-network-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
h1, .subtitle { position: relative; z-index: 2; }
h1 { font-size: 2.8rem; font-weight: 800; margin: 0 0 0.8rem 0; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { font-size: 1.1rem; color: var(--text-secondary); margin-top: 0; max-width: 650px; margin-left: auto; margin-right: auto; line-height: 1.8; }
main { padding: 3rem; background-color: var(--panel-bg); border-radius: var(--radius-card); box-shadow: var(--shadow-xl); border: 1px solid var(--panel-border); animation: fadeIn 0.8s 0.3s ease-out backwards; }
.form-group { margin-bottom: 2.5rem; }
.form-label { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; color: var(--text-primary); font-size: 1.2em; margin-bottom: 1.2rem; }
.form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
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; transition: var(--transition-smooth); min-height: 90px; resize: vertical; }
textarea:focus { outline: none; border-color: var(--accent-primary); box-shadow: 0 0 0 3px var(--accent-primary-glow); background-color: var(--panel-bg); }
.aspect-ratio-selector { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.ratio-option { background-color: var(--input-bg); border: 2px solid var(--input-border); border-radius: var(--radius-input); padding: 1rem; cursor: pointer; transition: var(--transition-smooth); text-align: center; }
.ratio-option.active { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 0 3px var(--accent-primary-glow); }
.ratio-icon { height: 50px; display: flex; align-items: center; justify-content: center; margin: 0 auto 0.75rem; }
.ratio-icon > div, .ratio-icon > svg { background-color: var(--panel-bg); border: 2px solid var(--text-tertiary); border-radius: 6px; transition: var(--transition-smooth); box-sizing: border-box; }
.ratio-option.active .ratio-icon > div, .ratio-option.active .ratio-icon > svg { border-color: var(--accent-primary); background-color: var(--accent-primary-glow); }
.ratio-label { font-weight: 600; color: var(--text-secondary); font-size: 0.9rem; }
.ratio-option.active .ratio-label { color: var(--text-primary); }
#icon-portrait > div { width: 28px; height: 50px; }
#icon-landscape > div { width: 60px; height: 34px; }
#icon-square > div { width: 45px; height: 45px; }
#icon-custom > svg { width: 45px; height: 45px; padding: 8px; color: var(--text-tertiary); }
.ratio-option.active #icon-custom > svg { color: var(--accent-primary); }
#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: 1.5rem; }
#submit-btn svg { width: 24px; height: 24px; }
#submit-btn:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); }
#submit-btn:disabled { background: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; box-shadow: none; transform: none;}
#submit-btn .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; }
#result-container { min-height: 250px; 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; box-sizing: border-box; }
#result-container.loading { padding: 0; border: none; background-color: transparent; }
#result-container.has-content { border-style: solid; border-color: var(--panel-border); }
.generator-container { position: relative; width: 100%; max-width: 500px; height: 200px; border: 2px solid #38bdf8; border-radius: 20px; overflow: hidden; box-shadow: 0 0 40px rgba(56, 189, 248, 0.3); animation: pulse 5s infinite; background-color: #161b22; color: #f0f6fc; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.text-overlay { font-size: 18px; font-weight: 700; animation: glow-text 7s infinite ease-in-out; text-align: center; }
.progress-bar { position: absolute; bottom: 0; left: 0; width: 0%; height: 6px; background: linear-gradient(to right, #38bdf8, #bb86fc, #facc15); transition: width 1s linear; }
#result-image-wrapper { display: none; width: 100%; text-align: center; }
#result-image-display { max-width: 100%; max-height: 500px; object-fit: contain; border-radius: var(--radius-input); box-shadow: var(--shadow-md); border: 1px solid var(--panel-border); }
.download-button { padding: 12px 25px; margin-top: 1.5rem; border: none; border-radius: var(--radius-btn); font-size: 1rem; font-weight: 600; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 0.7rem; background-color: var(--accent-primary); color: white; box-shadow: var(--shadow-md); text-decoration: none;}
.download-button:hover { background-color: var(--accent-primary-hover); transform: translateY(-3px); }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(18, 24, 38, 0.6); backdrop-filter: blur(8px); display: none; justify-content: center; align-items: center; z-index: 1000; }
.modal-content-small { background: var(--panel-bg); padding: 2rem; border-radius: var(--radius-card); max-width: 350px; width: 90%; text-align: center; box-shadow: var(--shadow-xl); position: relative; }
.modal-content-small h3 { margin-top: 0; margin-bottom: 1.5rem; }
.modal-content-small input { width: 100%; padding: 0.8rem 1rem; 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; margin-bottom: 1rem;}
#confirm-custom-size-btn { width: 100%; padding: 0.9rem; font-size: 1rem; font-weight: 700; background-color: var(--accent-primary); color: #fff; border: none; border-radius: var(--radius-btn); cursor: pointer; }
#close-custom-modal-btn { position: absolute; top: 10px; left: 10px; background: transparent; border: none; font-size: 2rem; cursor: pointer; color: var(--text-tertiary); line-height: 1; padding: 0.5rem; }
@media (max-width: 768px) {
main { padding: 1.5rem; } h1 { font-size: 2.2rem; }
.aspect-ratio-selector { grid-template-columns: repeat(2, 1fr); }
}
</style>
</head>
<body>
<div class="container">
<header>
<canvas id="neural-network-canvas"></canvas>
<h1>خلق تصاویر انیمیشنی جذاب</h1>
<p class="subtitle">ایده‌های خود را به سادگی به تصاویر انیمیشنی با سبک منحصر به فرد تبدیل کنید.</p>
</header>
<main>
<div class="form-group">
<div class="form-label">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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>
۱. ایده خود را توصیف کنید
</div>
<textarea id="prompt-input" rows="3" placeholder="مثال: یک فضانورد که روی ماه در حال موج‌سواری است"></textarea>
</div>
<div class="form-group">
<div class="form-label">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 9V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h4"/><rect x="12" y="13" width="10" height="8" rx="2"/><path d="M17 12v-1a2 2 0 0 0-2-2h-1"/></svg>
۲. اندازه تصویر را انتخاب کنید
</div>
<div class="aspect-ratio-selector" id="aspect-ratio-selector">
<div class="ratio-option" data-ratio="9:16">
<div class="ratio-icon" id="icon-portrait"><div></div></div>
<div class="ratio-label">عمودی ۹:۱۶</div>
</div>
<div class="ratio-option" data-ratio="16:9">
<div class="ratio-icon" id="icon-landscape"><div></div></div>
<div class="ratio-label">افقی ۱۶:۹</div>
</div>
<div class="ratio-option" data-ratio="custom">
<div class="ratio-icon" id="icon-custom">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 16V8a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h8"/><circle cx="18" cy="18" r="3"/><path d="M18 15v-2"/><path d="M18 21v-2"/><path d="M15 18h-2"/><path d="M21 18h-2"/></svg>
</div>
<div class="ratio-label">
اندازه دلخواه <span id="custom-ratio-label-value"></span>
</div>
</div>
<div class="ratio-option active" data-ratio="1:1">
<div class="ratio-icon" id="icon-square"><div></div></div>
<div class="ratio-label">مربع ۱:۱</div>
</div>
</div>
</div>
<button id="submit-btn">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 3L12 8L17 10L12 12L10 17L8 12L3 10L8 8L10 3z"/></svg>
<span id="btn-text">خلق کن!</span>
<div class="spinner" style="display: none;"></div>
</button>
<div class="form-group" style="margin-top: 3rem;">
<div class="form-label">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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"/></svg>
۳. نتیجه
</div>
<div id="result-container">
<p id="idle-text">برای شروع، ایده خود را نوشته و دکمه را بزنید.</p>
</div>
</div>
</main>
</div>
<!-- Modal for Custom Size -->
<div class="modal-overlay" id="custom-size-modal">
<div class="modal-content-small">
<button id="close-custom-modal-btn">&times;</button>
<h3>تنظیم اندازه دلخواه</h3>
<label>عرض (Width)</label>
<input type="number" id="custom-width-input" value="1024" min="512" max="1536" step="8">
<label>طول (Height)</label>
<input type="number" id="custom-height-input" value="1024" min="512" max="1536" step="8">
<button id="confirm-custom-size-btn">تایید و اعمال</button>
</div>
</div>
<script>
// اتصال بخش UI به کدهای جاوا اسکریپت
const promptInput = document.getElementById('prompt-input');
const submitBtn = document.getElementById('submit-btn');
const resultContainer = document.getElementById('result-container');
const ratioSelector = document.getElementById('aspect-ratio-selector');
let selectedRatio = '1:1';
let customWidth = 1024;
let customHeight = 1024;
let pollTimer = null;
const getDimensions = (ratio) => {
if (ratio === 'custom') return { width: customWidth, height: customHeight };
switch (ratio) {
case '9:16': return { width: 768, height: 1344 };
case '16:9': return { width: 1344, height: 768 };
case '1:1': return { width: 1024, height: 1024 };
default: return { width: 1024, height: 1024 };
}
};
const setLoadingState = (isLoading, message) => {
const spinner = submitBtn.querySelector('.spinner');
const icon = submitBtn.querySelector('svg');
const btnText = document.getElementById('btn-text');
if (isLoading) {
submitBtn.disabled = true;
icon.style.display = 'none';
spinner.style.display = 'inline-block';
btnText.textContent = message;
resultContainer.className = 'loading';
resultContainer.innerHTML = `
<div class="generator-container">
<div class="text-overlay" id="loading-status-text">${message}</div>
<div class="progress-bar" style="width: 50%;"></div>
</div>`;
} else {
submitBtn.disabled = false;
icon.style.display = 'inline-block';
spinner.style.display = 'none';
btnText.textContent = 'خلق کن!';
}
};
submitBtn.addEventListener('click', async () => {
const userPrompt = promptInput.value.trim();
if (!userPrompt) return alert('لطفاً ایده خود را بنویسید.');
setLoadingState(true, 'در حال ترجمه متن و ارتباط با سرور...');
const dims = getDimensions(selectedRatio);
try {
// ارسال اطلاعات به بک‌اند داکر (که خودش به گیت هاب میفرستد)
// نکته مهم: ما action_name را generate-cartoon گذاشتیم تا گیت هاب بداند کدام مدل را اجرا کند
const res = await fetch('/api/generate', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: userPrompt + " کارتونی انیمیشن سه بعدی", // کلمه کلیدی برای راهنمایی مترجم
width: dims.width,
height: dims.height,
action_name: "generate-cartoon"
})
});
const data = await res.json();
if (data.status === 'success') {
document.getElementById('loading-status-text').textContent = 'در حال ساخت تصویر... (حدود ۴۵ ثانیه زمان میبرد)';
// شروع به پیگیری وضعیت از داکر
pollTimer = setInterval(() => checkResult(data.run_id), 3000);
} else {
alert('خطا در ارسال به گیت‌هاب!');
setLoadingState(false);
}
} catch (e) {
alert('خطای اتصال به سرور!');
setLoadingState(false);
}
});
async function checkResult(run_id) {
try {
const res = await fetch(`/api/status/${run_id}`);
const data = await res.json();
if (data.status === 'ready') {
clearInterval(pollTimer);
setLoadingState(false);
// نمایش عکس و دکمه دانلود
resultContainer.className = 'has-content';
resultContainer.innerHTML = `
<div id="result-image-wrapper" style="display: block;">
<img id="result-image-display" src="${data.url}" alt="تصویر کارتونی">
<div class="download-actions">
<a href="${data.url}" download="cartoon_image.webp" class="download-button">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<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>
<span>دانلود تصویر</span>
</a>
</div>
</div>`;
}
} catch(e) {
console.log('Polling...', e);
}
}
// --- کدهای مربوط به انتخاب سایز و مُدال ---
const customSizeModal = document.getElementById('custom-size-modal');
ratioSelector.addEventListener('click', (event) => {
const selectedOption = event.target.closest('.ratio-option');
if (!selectedOption) return;
const ratioValue = selectedOption.dataset.ratio;
if (ratioValue === 'custom') {
customSizeModal.style.display = 'flex';
} else {
ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active'));
selectedOption.classList.add('active');
selectedRatio = ratioValue;
}
});
document.getElementById('close-custom-modal-btn').addEventListener('click', () => { customSizeModal.style.display = 'none'; });
document.getElementById('confirm-custom-size-btn').addEventListener('click', () => {
const wInput = document.getElementById('custom-width-input').value;
const hInput = document.getElementById('custom-height-input').value;
customWidth = parseInt(wInput);
customHeight = parseInt(hInput);
selectedRatio = 'custom';
ratioSelector.querySelectorAll('.ratio-option').forEach(opt => opt.classList.remove('active'));
document.querySelector('.ratio-option[data-ratio="custom"]').classList.add('active');
document.getElementById('custom-ratio-label-value').textContent = `(${customWidth}x${customHeight})`;
customSizeModal.style.display = 'none';
});
// انیمیشن شبکه عصبی پس‌زمینه
document.addEventListener('DOMContentLoaded', () => {
const canvas = document.getElementById('neural-network-canvas');
if(!canvas) return; const header = canvas.parentElement; const ctx = canvas.getContext('2d');
let particles = []; const particleCount = 20; const maxDistance = 100;
const particleColor = '#4A6CFA'; const lineColor = '#8A94A6';
function resizeCanvas() { canvas.width = header.clientWidth; canvas.height = header.clientHeight; init(); }
class Particle { constructor() { this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.vx = (Math.random() - 0.5) * 0.3; this.vy = (Math.random() - 0.5) * 0.3; this.radius = 1.2; } update() { this.x += this.vx; this.y += this.vy; if (this.x < 0 || this.x > canvas.width) this.vx *= -1; if (this.y < 0 || this.y > canvas.height) this.vy *= -1; } draw() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); ctx.fillStyle = particleColor; ctx.fill(); } }
function init() { particles = []; for (let i = 0; i < particleCount; i++) { particles.push(new Particle()); } }
function connectParticles() { for (let i = 0; i < particles.length; i++) { for (let j = i + 1; j < particles.length; j++) { const dx = particles[i].x - particles[j].x; const dy = particles[i].y - particles[j].y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < maxDistance) { ctx.beginPath(); ctx.moveTo(particles[i].x, particles[i].y); ctx.lineTo(particles[j].x, particles[j].y); ctx.strokeStyle = lineColor; ctx.lineWidth = 0.2; ctx.globalAlpha = 1 - distance / maxDistance; ctx.stroke(); } } } ctx.globalAlpha = 1; }
function animate() { if(!ctx) return; ctx.clearRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => { particle.update(); particle.draw(); }); connectParticles(); requestAnimationFrame(animate); }
window.addEventListener('resize', resizeCanvas); resizeCanvas(); animate();
});
</script>
</body>
</html>