Upload 4 files
Browse files- Dockerfile.txt +19 -0
- app.py +177 -0
- index.html +542 -0
- requirements.txt +4 -0
Dockerfile.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. از یک ایمیج رسمی پایتون به عنوان پایه استفاده میکنیم
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# 2. یک پوشه کاری در کانتینر ایجاد میکنیم
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# 3. فایل نیازمندیها را کپی کرده و کتابخانهها را نصب میکنیم
|
| 8 |
+
COPY requirements.txt requirements.txt
|
| 9 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
+
|
| 11 |
+
# 4. تمام فایلهای پروژه را در پوشه کاری کپی میکنیم
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
# 5. پورتی که برنامه روی آن اجرا میشود را مشخص میکنیم
|
| 15 |
+
EXPOSE 7860
|
| 16 |
+
|
| 17 |
+
# 6. دستور اجرای برنامه در زمان استارت کانتینر
|
| 18 |
+
# Gunicorn یک وب سرور قدرتمند برای اجرای برنامههای پایتون است
|
| 19 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"]
|
app.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import uuid
|
| 3 |
+
import requests
|
| 4 |
+
import threading
|
| 5 |
+
import time
|
| 6 |
+
from flask import Flask, request, jsonify, render_template, Response
|
| 7 |
+
from werkzeug.utils import secure_filename
|
| 8 |
+
from itertools import cycle
|
| 9 |
+
|
| 10 |
+
# --- 1. تنظیمات اصلی ---
|
| 11 |
+
WORKER_URLS = [
|
| 12 |
+
"https://ezmary-animat-worker1.hf.space",
|
| 13 |
+
"https://ezmary-animat-worker2.hf.space",
|
| 14 |
+
"https://ezmary-animat-worker3.hf.space",
|
| 15 |
+
"https://ezmary-animat-worker4.hf.space",
|
| 16 |
+
"https://ezmary-animat-worker5.hf.space",
|
| 17 |
+
]
|
| 18 |
+
worker_pool = cycle(WORKER_URLS)
|
| 19 |
+
|
| 20 |
+
UPLOADER_API_URL = "https://hamed744-uploadfile.hf.space/upload"
|
| 21 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 22 |
+
|
| 23 |
+
app = Flask(__name__, template_folder='templates')
|
| 24 |
+
|
| 25 |
+
jobs = {}
|
| 26 |
+
lock = threading.Lock()
|
| 27 |
+
|
| 28 |
+
def get_next_worker_url():
|
| 29 |
+
return next(worker_pool)
|
| 30 |
+
|
| 31 |
+
# --- 2. توابع پسزمینه ---
|
| 32 |
+
def get_permanent_link(job_id, temp_render_url, worker_url):
|
| 33 |
+
try:
|
| 34 |
+
with lock: jobs[job_id]["status"] = "در حال دائمیسازی لینک..."
|
| 35 |
+
if not HF_TOKEN: raise Exception("توکن HF برای آپلود دائمی یافت نشد.")
|
| 36 |
+
|
| 37 |
+
video_full_url = f"{worker_url}{temp_render_url}"
|
| 38 |
+
|
| 39 |
+
payload = {'url': video_full_url}
|
| 40 |
+
headers = {'Authorization': f'Bearer {HF_TOKEN}'}
|
| 41 |
+
response = requests.post(UPLOADER_API_URL, json=payload, headers=headers, timeout=600)
|
| 42 |
+
response.raise_for_status()
|
| 43 |
+
data = response.json()
|
| 44 |
+
|
| 45 |
+
uploader_proxy_url = data.get("hf_url")
|
| 46 |
+
if not uploader_proxy_url: raise Exception("پاسخ از سرور آپلودر معتبر نبود.")
|
| 47 |
+
|
| 48 |
+
path_part = uploader_proxy_url.split('/proxy/')[1]
|
| 49 |
+
final_proxy_url = f"/proxy/{path_part}"
|
| 50 |
+
|
| 51 |
+
with lock:
|
| 52 |
+
jobs[job_id]["status"] = "completed"
|
| 53 |
+
jobs[job_id]["result"] = final_proxy_url
|
| 54 |
+
|
| 55 |
+
except Exception as e:
|
| 56 |
+
print(f"خطا در دائمیسازی لینک برای {job_id}: {e}")
|
| 57 |
+
with lock:
|
| 58 |
+
jobs[job_id]["status"] = "error"
|
| 59 |
+
jobs[job_id]["result"] = f"خطا در دائمیسازی لینک. لینک موقت: {temp_render_url}"
|
| 60 |
+
|
| 61 |
+
# <<< تابع اصلاح شده: حذف تایماوت و افزایش مقاومت در برابر خطای ارتباطی >>>
|
| 62 |
+
def poll_worker_service(job_id, render_job_id, worker_url):
|
| 63 |
+
POLLING_INTERVAL = 15
|
| 64 |
+
MAX_POLLING_ERRORS = 20 # اگر ۲۰ بار پشت سر هم (حدود ۵ دقیقه) نتوانستیم با کارگر صحبت کنیم، خطا میدهیم
|
| 65 |
+
error_count = 0
|
| 66 |
+
|
| 67 |
+
while True: # حلقه بینهایت، هرگز به خاطر زمان متوقف نمیشود
|
| 68 |
+
try:
|
| 69 |
+
response = requests.post(f"{worker_url}/check_job_status", json={"job_id": render_job_id}, timeout=45)
|
| 70 |
+
response.raise_for_status()
|
| 71 |
+
error_count = 0 # ریست کردن شمارنده خطا در صورت موفقیت
|
| 72 |
+
|
| 73 |
+
data = response.json()
|
| 74 |
+
with lock:
|
| 75 |
+
current_job = jobs.get(job_id)
|
| 76 |
+
if current_job and current_job.get("status") != data.get("status"):
|
| 77 |
+
current_job["status"] = data.get("status")
|
| 78 |
+
|
| 79 |
+
if data.get("status") == "completed":
|
| 80 |
+
get_permanent_link(job_id, data.get("result"), worker_url)
|
| 81 |
+
return # خروج از حلقه
|
| 82 |
+
elif data.get("status") == "error":
|
| 83 |
+
with lock:
|
| 84 |
+
current_job = jobs.get(job_id)
|
| 85 |
+
if current_job:
|
| 86 |
+
current_job["result"] = data.get("result", "خطای نامشخص از کارگر")
|
| 87 |
+
return # خروج از حلقه
|
| 88 |
+
except requests.exceptions.RequestException as e:
|
| 89 |
+
error_count += 1
|
| 90 |
+
print(f"خطای ارتباطی در پیگیری کارگر {worker_url} (تلاش {error_count}/{MAX_POLLING_ERRORS}): {e}")
|
| 91 |
+
if error_count >= MAX_POLLING_ERRORS:
|
| 92 |
+
with lock:
|
| 93 |
+
current_job = jobs.get(job_id)
|
| 94 |
+
if current_job:
|
| 95 |
+
current_job["status"] = "error"
|
| 96 |
+
current_job["result"] = f"ارتباط با سرور کارگر ({worker_url}) برای مدت طولانی قطع شد. ممکن است کارگر در حال ریاستارت باشد. لطفاً بعداً وضعیت را مجدداً بررسی کنید."
|
| 97 |
+
return # خروج از حلقه
|
| 98 |
+
|
| 99 |
+
time.sleep(POLLING_INTERVAL)
|
| 100 |
+
|
| 101 |
+
# --- 3. API Endpoints ---
|
| 102 |
+
@app.route('/')
|
| 103 |
+
def index():
|
| 104 |
+
return render_template('index.html')
|
| 105 |
+
|
| 106 |
+
@app.route('/api/submit_job', methods=['POST'])
|
| 107 |
+
def submit_job():
|
| 108 |
+
if 'image_file' not in request.files or 'video_file' not in request.files:
|
| 109 |
+
return jsonify({"error": "فایل عکس و ویدیو الزامی است."}), 400
|
| 110 |
+
|
| 111 |
+
image_file = request.files['image_file']
|
| 112 |
+
video_file = request.files['video_file']
|
| 113 |
+
motion = request.form.get('motion')
|
| 114 |
+
style = request.form.get('style')
|
| 115 |
+
|
| 116 |
+
image_bytes = image_file.read()
|
| 117 |
+
video_bytes = video_file.read()
|
| 118 |
+
|
| 119 |
+
MAX_RETRIES = 3
|
| 120 |
+
for attempt in range(MAX_RETRIES):
|
| 121 |
+
selected_worker_url = get_next_worker_url()
|
| 122 |
+
print(f"تلاش {attempt + 1}/{MAX_RETRIES}: ارسال کار به کارگر: {selected_worker_url}")
|
| 123 |
+
try:
|
| 124 |
+
response = requests.post(
|
| 125 |
+
f"{selected_worker_url}/submit_new_job",
|
| 126 |
+
files={'image_file': (secure_filename(image_file.filename), image_bytes, image_file.mimetype),
|
| 127 |
+
'video_file': (secure_filename(video_file.filename), video_bytes, video_file.mimetype)},
|
| 128 |
+
data={'motion': motion, 'style': style},
|
| 129 |
+
timeout=600
|
| 130 |
+
)
|
| 131 |
+
response.raise_for_status()
|
| 132 |
+
render_data = response.json()
|
| 133 |
+
render_job_id = render_data.get("job_id")
|
| 134 |
+
if not render_job_id: raise Exception("پاسخ معتبر از کارگر دریافت نشد.")
|
| 135 |
+
|
| 136 |
+
internal_job_id = str(uuid.uuid4())
|
| 137 |
+
with lock: jobs[internal_job_id] = {"status": "ارسال شده به کارگر...", "result": None}
|
| 138 |
+
|
| 139 |
+
thread = threading.Thread(target=poll_worker_service, args=(internal_job_id, render_job_id, selected_worker_url))
|
| 140 |
+
thread.start()
|
| 141 |
+
return jsonify({"job_id": internal_job_id})
|
| 142 |
+
except Exception as e:
|
| 143 |
+
print(f"خطا در تلاش {attempt + 1} برای کارگر {selected_worker_url}: {e}")
|
| 144 |
+
time.sleep(2)
|
| 145 |
+
|
| 146 |
+
final_error_message = ("<strong>سرورهای پردازش شلوغ هستند!</strong><br>"
|
| 147 |
+
"لطفاً چند دقیقه دیگر مجدداً تلاش نمایید.")
|
| 148 |
+
return jsonify({"error": final_error_message}), 500
|
| 149 |
+
|
| 150 |
+
@app.route('/api/check_status', methods=['POST'])
|
| 151 |
+
def check_status():
|
| 152 |
+
data = request.get_json()
|
| 153 |
+
job_id = data.get('job_id')
|
| 154 |
+
if not job_id: return jsonify({"error": "شناسه کار الزامی است."}), 400
|
| 155 |
+
with lock: job = jobs.get(job_id, {"status": "not_found", "result": None})
|
| 156 |
+
return jsonify({"status": job["status"], "result": job["result"]})
|
| 157 |
+
|
| 158 |
+
@app.route('/proxy/<user>/<repo>/<path:file_path>')
|
| 159 |
+
def file_proxy(user, repo, file_path):
|
| 160 |
+
if not HF_TOKEN: return "Token سرور برای پراکسی تنظیم نشده است.", 500
|
| 161 |
+
repo_id = f"{user}/{repo}"
|
| 162 |
+
file_url = f"https://huggingface.co/datasets/{repo_id}/resolve/main/{file_path}"
|
| 163 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
| 164 |
+
try:
|
| 165 |
+
hf_response = requests.get(file_url, headers=headers, stream=True, timeout=30)
|
| 166 |
+
hf_response.raise_for_status()
|
| 167 |
+
return Response(hf_response.iter_content(chunk_size=8192),
|
| 168 |
+
content_type=hf_response.headers.get('Content-Type', 'application/octet-stream'))
|
| 169 |
+
except requests.exceptions.HTTPError as e:
|
| 170 |
+
if e.response.status_code == 404: return "فایل یافت نشد.", 404
|
| 171 |
+
return f"خطای سرور Hugging Face: {e.response.status_code}", e.response.status_code
|
| 172 |
+
except Exception as e:
|
| 173 |
+
print(f"خطای پراکسی: {e}")
|
| 174 |
+
return "خطا در واکشی فایل.", 500
|
| 175 |
+
|
| 176 |
+
if __name__ == '__main__':
|
| 177 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
index.html
ADDED
|
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;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 |
+
--success-color: #38A169; --danger-color: #E53E3E; --danger-color-hover: #c53030; --danger-glow: rgba(229, 62, 62, 0.25);
|
| 16 |
+
--warning-color: #f59e0b; --warning-glow: rgba(245, 158, 11, 0.25);
|
| 17 |
+
--shadow-sm: 0 1px 2px 0 rgba(26, 32, 44, 0.03);
|
| 18 |
+
--shadow-md: 0 4px 6px -1px rgba(26, 32, 44, 0.05), 0 2px 4px -2px rgba(26, 32, 44, 0.04);
|
| 19 |
+
--shadow-xl: 0 20px 25px -5px rgba(26, 32, 44, 0.07), 0 8px 10px -6px rgba(26, 32, 44, 0.05);
|
| 20 |
+
--radius-card: 24px; --radius-btn: 14px; --radius-input: 12px;
|
| 21 |
+
--transition-smooth: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
|
| 22 |
+
}
|
| 23 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
|
| 24 |
+
@keyframes core-pulse { 0%, 100% { transform: scale(0.95); box-shadow: 0 0 25px var(--accent-primary-glow); } 50% { transform: scale(1.05); box-shadow: 0 0 50px rgba(74, 108, 250, 0.5); } }
|
| 25 |
+
@keyframes ring-rotate { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
| 26 |
+
@keyframes slideInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
|
| 27 |
+
@keyframes button-pulse { 0% { box-shadow: 0 0 0 0 rgba(74, 108, 250, 0.7); } 70% { box-shadow: 0 0 0 12px rgba(74, 108, 250, 0); } 100% { box-shadow: 0 0 0 0 rgba(74, 108, 250, 0); } }
|
| 28 |
+
@keyframes hint-fade-in-out { 0%, 100% { opacity: 0; transform: translateY(10px); } 15%, 85% { opacity: 1; transform: translateY(0); } }
|
| 29 |
+
@keyframes fadeOutUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-50px); } }
|
| 30 |
+
@keyframes shake { 10%, 90% { transform: translate3d(-1px, 0, 0); } 20%, 80% { transform: translate3d(2px, 0, 0); } 30%, 50%, 70% { transform: translate3d(-4px, 0, 0); } 40%, 60% { transform: translate3d(4px, 0, 0); } }
|
| 31 |
+
|
| 32 |
+
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; align-items: flex-start; min-height: 100vh; }
|
| 33 |
+
.container { max-width: 820px; width: 100%; }
|
| 34 |
+
header { position: relative; text-align: center; margin-bottom: 2.5rem; animation: fadeIn 0.8s 0.1s ease-out backwards; overflow: hidden; padding: 2rem 0; }
|
| 35 |
+
#neural-network-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; opacity: 0.7; }
|
| 36 |
+
.header-content { position: relative; z-index: 2; }
|
| 37 |
+
.ai-orb-container { width: 150px; height: 150px; margin: 0 auto 1rem; position: relative; display: flex; align-items: center; justify-content: center; }
|
| 38 |
+
.orb-core { width: 70px; height: 70px; border-radius: 50%; background: radial-gradient(circle, #394A7A 0%, #1A202C 70%); box-shadow: 0 0 25px var(--accent-primary-glow); display: flex; align-items: center; justify-content: center; animation: core-pulse 4s ease-in-out infinite; border: 1px solid rgba(74, 108, 250, 0.3); }
|
| 39 |
+
.face-icon { width: 32px; height: 32px; color: var(--accent-secondary); filter: drop-shadow(0 0 8px rgba(15, 212, 168, 0.7)); transition: var(--transition-smooth); }
|
| 40 |
+
.orb-ring { position: absolute; top: 50%; left: 50%; border-style: solid; border-color: transparent; border-radius: 50%; mix-blend-mode: screen; }
|
| 41 |
+
.orb-ring.one { width: 100px; height: 100px; margin-top: -50px; margin-left: -50px; border-width: 2px; border-top-color: var(--accent-primary); border-right-color: var(--accent-primary); animation: ring-rotate 8s linear infinite; }
|
| 42 |
+
.orb-ring.two { width: 120px; height: 120px; margin-top: -60px; margin-left: -60px; border-width: 1px; border-bottom-color: var(--accent-secondary); animation: ring-rotate 10s linear infinite reverse; }
|
| 43 |
+
h1 { font-size: 2.8rem; font-weight: 800; margin: 0; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
| 44 |
+
.subtitle { font-size: 1.1rem; color: var(--text-secondary); margin-top: 0.5rem; }
|
| 45 |
+
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; }
|
| 46 |
+
.form-group { margin-bottom: 2.5rem; }
|
| 47 |
+
.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; }
|
| 48 |
+
.form-label svg { width: 24px; height: 24px; color: var(--accent-primary); }
|
| 49 |
+
.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
|
| 50 |
+
.drop-zone { position: relative; border: 2px dashed var(--input-border); border-radius: var(--radius-input); padding: 1.5rem; text-align: center; cursor: pointer; transition: var(--transition-smooth); background-color: var(--input-bg); min-height: 150px; display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; }
|
| 51 |
+
.drop-zone.drag-over, .drop-zone:hover:not(.has-file) { border-color: var(--accent-primary); background-color: #fff; box-shadow: 0 0 15px var(--accent-primary-glow); }
|
| 52 |
+
.drop-zone.has-file { border-style: solid; border-color: var(--success-color); padding: 0; cursor: default; background-color: #000; }
|
| 53 |
+
.upload-content { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
|
| 54 |
+
.upload-content p { font-size: 0.9rem; }
|
| 55 |
+
.upload-icon svg { width: 32px; height: 32px; color: var(--accent-primary); }
|
| 56 |
+
.preview-img, .preview-vid { display: none; width: 100%; height: 100%; object-fit: contain; position: absolute; top: 0; left: 0; }
|
| 57 |
+
.drop-zone.has-file .upload-content { display: none; }
|
| 58 |
+
.drop-zone.has-file .preview-img, .drop-zone.has-file .preview-vid { display: block; }
|
| 59 |
+
.remove-file-btn { position: absolute; top: 8px; left: 8px; width: 28px; height: 28px; background-color: rgba(26, 32, 44, 0.7); color: white; border: none; border-radius: 50%; font-size: 18px; cursor: pointer; opacity: 0; visibility: hidden; transition: all 0.25s ease-out; z-index: 10; }
|
| 60 |
+
.drop-zone.has-file:hover .remove-file-btn { opacity: 1; visibility: visible; }
|
| 61 |
+
.remove-file-btn:hover { background-color: var(--danger-color); transform: scale(1.1) rotate(90deg); }
|
| 62 |
+
.radio-group { display: flex; flex-wrap: wrap; gap: 1rem; }
|
| 63 |
+
.radio-label { flex: 1; min-width: 120px; padding: 1rem; border: 2px solid var(--input-border); border-radius: var(--radius-btn); cursor: pointer; transition: var(--transition-smooth); text-align: center; font-weight: 600; }
|
| 64 |
+
.radio-label:hover { border-color: var(--accent-primary); }
|
| 65 |
+
.radio-input { display: none; }
|
| 66 |
+
.radio-input:checked + .radio-label { border-color: var(--accent-primary); background-color: var(--accent-primary-glow); color: var(--accent-primary); box-shadow: 0 0 10px var(--accent-primary-glow); }
|
| 67 |
+
.hint-container { min-height: 40px; display: flex; justify-content: center; align-items: center; margin-top: 1rem; }
|
| 68 |
+
.motion-hint { color: var(--text-secondary); font-size: 0.9rem; text-align: center; opacity: 0; transition: var(--transition-smooth); }
|
| 69 |
+
.motion-hint.visible { animation: hint-fade-in-out 4s ease-in-out forwards; }
|
| 70 |
+
#generateButton { box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 0.75rem; width: 100%; padding: 0.9rem; font-size: 1.1rem; 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; }
|
| 71 |
+
#generateButton svg { width: 24px; height: 24px; flex-shrink: 0; }
|
| 72 |
+
#generateButton:hover:not(:disabled) { transform: translateY(-5px) scale(1.02); box-shadow: 0 8px 20px -4px var(--accent-primary-glow); }
|
| 73 |
+
#generateButton:disabled { background: var(--text-tertiary); cursor: not-allowed; opacity: 0.7; transform: none; box-shadow: none; }
|
| 74 |
+
#results-gallery { display: flex; flex-direction: column; gap: 1.5rem; }
|
| 75 |
+
.job-card { background: var(--panel-bg); border-radius: var(--radius-card); padding: 1.5rem; border: 1px solid var(--panel-border); box-shadow: var(--shadow-md); animation: slideInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1); transition: transform 0.4s ease, opacity 0.4s ease; }
|
| 76 |
+
.job-card.deleting { animation: fadeOutUp 0.5s ease-out forwards; }
|
| 77 |
+
.job-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
|
| 78 |
+
.job-id { font-family: 'Courier New', monospace; font-size: 0.8rem; background-color: var(--input-bg); padding: 0.25rem 0.5rem; border-radius: 6px; }
|
| 79 |
+
.job-status { font-weight: 600; font-size: 0.9rem; text-align: left; transition: color 0.3s ease; }
|
| 80 |
+
.job-card.in-progress { background: linear-gradient(135deg, #1e293b, #0f172a); color: #e2e8f0; border-color: #334155; box-shadow: var(--shadow-xl); position: relative; overflow: hidden; padding-bottom: 2rem; }
|
| 81 |
+
.job-card.in-progress .job-id { background-color: rgba(255, 255, 255, 0.1); }
|
| 82 |
+
.job-card.in-progress .job-body { display: flex; flex-direction: column; align-items: center; gap: 1rem; margin-top: 1.5rem; }
|
| 83 |
+
.in-progress-controls { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 0.5rem; }
|
| 84 |
+
.timer-container { position: relative; width: 160px; height: 160px; transition: opacity 0.5s ease, transform 0.5s ease; }
|
| 85 |
+
.timer-svg { transform: rotate(-90deg); width: 100%; height: 100%; }
|
| 86 |
+
.timer-circle-bg { fill: none; stroke: rgba(255, 255, 255, 0.15); stroke-width: 10; }
|
| 87 |
+
.timer-circle-progress { fill: none; stroke: url(#timer-gradient); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
|
| 88 |
+
.timer-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 2.2rem; font-weight: 700; color: #fff; font-family: 'Courier New', monospace; }
|
| 89 |
+
.reassurance-message { text-align: center; background: rgba(255, 255, 255, 0.05); padding: 1rem; border-radius: var(--radius-btn); border: 1px solid rgba(255, 255, 255, 0.1); font-size: 0.9rem; color: var(--text-tertiary); max-width: 90%; margin: 1.5rem 0; line-height: 1.7; }
|
| 90 |
+
.reassurance-message strong { color: #fff; font-weight: 600; }
|
| 91 |
+
.quick-check-btn { display: flex; align-items: center; gap: 0.5rem; background: var(--accent-primary); color: #fff; border: none; padding: 0.8rem 1.8rem; border-radius: var(--radius-btn); font-weight: 600; cursor: pointer; transition: var(--transition-smooth); animation: button-pulse 2.5s infinite; }
|
| 92 |
+
.quick-check-btn:hover:not(:disabled) { background: var(--accent-primary-hover); transform: scale(1.05); animation-play-state: paused; }
|
| 93 |
+
.quick-check-btn:disabled { background: var(--text-secondary); cursor: wait; }
|
| 94 |
+
.quick-check-feedback { min-height: 20px; font-size: 0.9rem; color: var(--text-tertiary); opacity: 0; transform: translateY(10px); transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); }
|
| 95 |
+
.quick-check-feedback.visible { opacity: 1; transform: translateY(0); }
|
| 96 |
+
.job-card.completed video { width: 100%; border-radius: var(--radius-input); margin-top: 1rem; background-color: #000; }
|
| 97 |
+
.job-card.error .job-body { color: var(--danger-color); background: rgba(229, 62, 62, 0.05); padding: 1rem; border-radius: var(--radius-input); border: 1px solid rgba(229, 62, 62, 0.2); font-family: monospace; direction: ltr; text-align: left; white-space: pre-wrap; margin-bottom: 1rem; }
|
| 98 |
+
.video-controls { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
|
| 99 |
+
.video-button { padding: 0.7rem 1.5rem; border-radius: var(--radius-btn); border: 1px solid var(--input-border); cursor: pointer; font-weight: 600; transition: var(--transition-smooth); background-color: var(--input-bg); color: var(--text-secondary); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; font-family: var(--app-font); font-size: 1rem;}
|
| 100 |
+
.video-button:hover { background-color: var(--panel-border); color: var(--text-primary); }
|
| 101 |
+
.delete-job-btn { padding: 0.7rem; line-height: 0; background-color: transparent; }
|
| 102 |
+
.delete-job-btn svg { width: 18px; height: 18px; color: var(--text-tertiary); transition: color 0.3s ease; }
|
| 103 |
+
.delete-job-btn:hover { background-color: var(--danger-glow); }
|
| 104 |
+
.delete-job-btn:hover svg { color: var(--danger-color); }
|
| 105 |
+
.delete-job-btn.hidden { display: none; }
|
| 106 |
+
|
| 107 |
+
.modal-overlay {
|
| 108 |
+
position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(26, 32, 44, 0.7);
|
| 109 |
+
z-index: 1000; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(5px);
|
| 110 |
+
opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
|
| 111 |
+
}
|
| 112 |
+
.modal-overlay.visible {
|
| 113 |
+
opacity: 1; visibility: visible;
|
| 114 |
+
}
|
| 115 |
+
.modal-box, .alert-box {
|
| 116 |
+
background: var(--panel-bg); padding: 2.5rem; border-radius: var(--radius-card); text-align: center;
|
| 117 |
+
max-width: 400px; box-shadow: var(--shadow-xl); transform: scale(0.95) translateY(20px);
|
| 118 |
+
opacity: 0; transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 119 |
+
}
|
| 120 |
+
.modal-overlay.visible .modal-box, .modal-overlay.visible .alert-box {
|
| 121 |
+
transform: scale(1) translateY(0); opacity: 1;
|
| 122 |
+
}
|
| 123 |
+
.alert-box h3 { margin-top: 0; font-size: 1.5rem; }
|
| 124 |
+
.alert-box p { color: var(--text-secondary); margin-bottom: 2rem; }
|
| 125 |
+
.alert-box button { background: var(--accent-primary); color: #fff; border: none; padding: 0.8rem 2rem; border-radius: var(--radius-btn); cursor: pointer; font-weight: 600; transition: var(--transition-smooth); }
|
| 126 |
+
.alert-box button:hover { background: var(--accent-primary-hover); transform: scale(1.05); }
|
| 127 |
+
#validation-modal .alert-box { animation: shake 0.6s cubic-bezier(.36,.07,.19,.97) both; }
|
| 128 |
+
#validation-modal .alert-box h3 { color: var(--warning-color); display: flex; justify-content: center; align-items: center; gap: 0.5rem; }
|
| 129 |
+
#validation-modal .alert-box svg { width: 28px; height: 28px; }
|
| 130 |
+
#validation-modal .alert-box button { background: var(--warning-color); box-shadow: 0 4px 14px 0 var(--warning-glow); }
|
| 131 |
+
#validation-modal .alert-box button:hover { background: #d97706; }
|
| 132 |
+
.modal-box { max-width: 600px; width: 90%; max-height: 90vh; overflow-y: auto; text-align: right; }
|
| 133 |
+
.modal-box h2 { font-size: 1.8rem; font-weight: 800; margin-top: 0; margin-bottom: 0.5rem; background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
| 134 |
+
.modal-box .intro-text { color: var(--text-secondary); margin-bottom: 2rem; line-height: 1.8; }
|
| 135 |
+
.modal-box h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 1rem; border-bottom: 2px solid var(--panel-border); padding-bottom: 0.5rem; text-align: center;}
|
| 136 |
+
.modal-box .rules-list { list-style: none; padding-right: 0; counter-reset: rule-counter; }
|
| 137 |
+
.modal-box .rules-list li { position: relative; padding-right: 40px; margin-bottom: 1rem; line-height: 1.7; color: var(--text-secondary); }
|
| 138 |
+
.modal-box .rules-list li::before { counter-increment: rule-counter; content: counter(rule-counter); position: absolute; right: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-primary-glow); color: var(--accent-primary); display: flex; align-items: center; justify-content: center; font-weight: 700; }
|
| 139 |
+
.modal-actions { margin-top: 2rem; text-align: center; display: flex; gap: 1rem; justify-content: center; }
|
| 140 |
+
#accept-terms-btn { width: 100%; padding: 1rem; font-size: 1.1rem; 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: var(--transition-smooth); box-shadow: 0 6px 12px -3px var(--accent-primary-glow); }
|
| 141 |
+
#accept-terms-btn:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 8px 20px -4px var(--accent-primary-glow); }
|
| 142 |
+
.exit-notice { font-size: 0.8rem; color: var(--text-tertiary); margin-top: 1rem; }
|
| 143 |
+
.modal-actions button { flex-grow: 1; padding: 0.8rem 1.5rem; border-radius: var(--radius-btn); border: none; font-weight: 700; cursor: pointer; transition: all 0.25s ease; font-family: var(--app-font); }
|
| 144 |
+
.modal-actions .confirm-delete-btn { background-color: var(--danger-color); color: white; box-shadow: 0 4px 14px 0 var(--danger-glow); }
|
| 145 |
+
.modal-actions .confirm-delete-btn:hover { background-color: var(--danger-color-hover); transform: translateY(-2px); box-shadow: 0 6px 20px 0 var(--danger-glow); }
|
| 146 |
+
.modal-actions .cancel-delete-btn { background-color: var(--input-bg); color: var(--text-secondary); border: 1px solid var(--input-border); }
|
| 147 |
+
.modal-actions .cancel-delete-btn:hover { background-color: var(--panel-border); color: var(--text-primary); transform: translateY(-2px); }
|
| 148 |
+
</style>
|
| 149 |
+
</head>
|
| 150 |
+
<body>
|
| 151 |
+
<div class="container">
|
| 152 |
+
<!-- هدر و فرم -->
|
| 153 |
+
<header>
|
| 154 |
+
<canvas id="neural-network-canvas"></canvas>
|
| 155 |
+
<div class="header-content">
|
| 156 |
+
<div class="ai-orb-container">
|
| 157 |
+
<div class="orb-core"><svg class="face-icon" 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="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/><circle cx="12" cy="12" r="3"/></svg></div>
|
| 158 |
+
<div class="orb-ring one"></div><div class="orb-ring two"></div>
|
| 159 |
+
</div>
|
| 160 |
+
<h1>انیماتور ویدیو هوش مصنوعی آلفا</h1>
|
| 161 |
+
<p class="subtitle">تغییر چهره در حالت واقعی با هوش مصنوعی آلفا ~ با توجه به اینکه این مدل برای تولید ویدیو زمان زیادی رو لازم داره هر بار تا 3 درخواست رو میتونید همزمان برای مدل ارسال کنید و صفحه رو ترک کنید، همه کارها سمت سرور انجام میشه و میتونید مجدداً برگردید و ویدیو رو تحویل بگیرید. با ترک صفحه و خارج شدن از برنامه پروژه شما در حال انجام است و از بین نخواهد رفت . گاهی اوقات ممکنه بخاطر شلوغی ساخت ویدیو شما روی دور بینهایت بره بعد از نیم ساعت اگر ویدیو ساخته نشد یک دکمه حذف میاد کنار درخواست، درخواست قبلی رو حذف کنید و در زمان های که شلوغ نیست برای ساخت بفرستید.</p>
|
| 162 |
+
</div>
|
| 163 |
+
</header>
|
| 164 |
+
<main>
|
| 165 |
+
<div class="form-group">
|
| 166 |
+
<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 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>۱. فایلهای خود را آپلود کنید</div>
|
| 167 |
+
<div class="upload-grid">
|
| 168 |
+
<label id="image-drop-zone" for="image-input" class="drop-zone"><div class="upload-content"><div class="upload-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg></div><p>عکس (اجباری)</p></div><img id="image-preview" class="preview-img" alt="Preview"><button id="remove-image-btn" type="button" class="remove-file-btn">×</button></label>
|
| 169 |
+
<input type="file" id="image-input" accept="image/*" hidden>
|
| 170 |
+
<label id="video-drop-zone" for="video-input" class="drop-zone"><div class="upload-content"><div class="upload-icon"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M8 12.5l3.5-3 5 5M2 12h3m14 0h3M12 2v3m0 14v3"/></svg></div><p>ویدیو (2 تا 30 ثانیه)</p></div><video id="video-preview" class="preview-vid" muted playsinline loop></video><button id="remove-video-btn" type="button" class="remove-file-btn">×</button></label>
|
| 171 |
+
<input type="file" id="video-input" accept="video/mp4, video/webm" hidden>
|
| 172 |
+
</div>
|
| 173 |
+
</div>
|
| 174 |
+
<div class="form-group">
|
| 175 |
+
<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"/></svg>۲. نوع حرکت را انتخاب کنید</div>
|
| 176 |
+
<div class="radio-group" id="motion-group">
|
| 177 |
+
<input type="radio" id="motion-mix" name="motion" value="wan2.2-animate-mix" class="radio-input" checked><label for="motion-mix" class="radio-label">ترکیبی (Mix)</label>
|
| 178 |
+
<input type="radio" id="motion-move" name="motion" value="wan2.2-animate-move" class="radio-input"><label for="motion-move" class="radio-label">حرکت (Move)</label>
|
| 179 |
+
</div>
|
| 180 |
+
<div class="hint-container"><p id="motion-hint" class="motion-hint"></p></div>
|
| 181 |
+
<button id="generateButton" disabled><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>ساخت ویدیو</span></button>
|
| 182 |
+
</div>
|
| 183 |
+
<div class="form-group">
|
| 184 |
+
<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"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>۳. گالری نتایج</div>
|
| 185 |
+
<div id="results-gallery"></div>
|
| 186 |
+
</div>
|
| 187 |
+
</main>
|
| 188 |
+
</div>
|
| 189 |
+
|
| 190 |
+
<!-- مدالها -->
|
| 191 |
+
<div id="terms-modal" class="modal-overlay">
|
| 192 |
+
<div class="modal-box">
|
| 193 |
+
<h2>ویدیو Animate Pro Alpha</h2>
|
| 194 |
+
<p class="intro-text">این تکنولوژی پیشرفته برای تولید محتوای خلاقانه و ساخت ویدیو های مفید طراحی شده است. شما میتوانید تصویر خودتونو در موقعیت یک ویدیو و یا حالت یک ویدیو رو در موقعیت تصویر تون انتقال بدید.</p>
|
| 195 |
+
<h3>قوانین استفاده</h3>
|
| 196 |
+
<ol class="rules-list">
|
| 197 |
+
<li>با ادامه دادن، مسئولیت کامل استفاده از این سرویس بر عهده کاربر خواهد بود و ما هیچگونه مسئولیتی از بابت محتوای تولید شده نداریم.</li>
|
| 198 |
+
<li>هدف اصلی ما احترام به حقوق دیگران و اهمیت به حریم خصوصی است. به همین سبب، استفاده از تصاویر و ویدیوهایی که این شرایط را نقض کند، منجر به مسدود شدن حساب کاربری خواهد شد.</li>
|
| 199 |
+
<li>این سرویس دارای بررسیهای هوش مصنوعی است. استفاده از مواردی که باعث نقض قوانین و یا عدم احترام به حقوق دیگران باشد، منجر به مسدود شدن حساب و از بین رفتن اشتراک شما خواهد شد.</li>
|
| 200 |
+
<li>هوش مصنوعی آلفا، همواره در طلیعهی نوآوری و پیشرفتهترین دستاوردهای هوش مصنوعی گام برمیدارد. ما بر این باوریم که با بهرهگیری از این فناوریها، بهترین مسیرهای توسعه را خواهیم گشود.</li>
|
| 201 |
+
</ol>
|
| 202 |
+
<div class="modal-actions">
|
| 203 |
+
<button id="accept-terms-btn">میپذیرم و ادامه میدهم</button>
|
| 204 |
+
<p class="exit-notice">در صورت عدم پذیرش قوانین لطفاً از این صفحه خارج شوید.</p>
|
| 205 |
+
</div>
|
| 206 |
+
</div>
|
| 207 |
+
</div>
|
| 208 |
+
<div id="alert-modal" class="modal-overlay">
|
| 209 |
+
<div class="alert-box">
|
| 210 |
+
<h3>ظرفیت تکمیل است!</h3>
|
| 211 |
+
<p>شما در حال حاضر ۳ درخواست در حال پردازش دارید. لطفاً تا تکمیل یکی از آنها صبر کنید و سپس درخواست جدید خود را ثبت نمایید.</p>
|
| 212 |
+
<button id="close-alert-btn">متوجه شدم</button>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
<div id="delete-confirm-modal" class="modal-overlay">
|
| 216 |
+
<div class="modal-box" style="max-width: 420px;">
|
| 217 |
+
<h3>تایید حذف</h3>
|
| 218 |
+
<p>آیا از حذف این ویدیو مطمئن هستید؟ این عمل غیرقابل بازگشت است.</p>
|
| 219 |
+
<div class="modal-actions">
|
| 220 |
+
<button class="cancel-delete-btn">انصراف</button>
|
| 221 |
+
<button class="confirm-delete-btn">بله، حذف کن</button>
|
| 222 |
+
</div>
|
| 223 |
+
</div>
|
| 224 |
+
</div>
|
| 225 |
+
<!-- <<< مدال جدید برای خطای مدت زمان ویدیو >>> -->
|
| 226 |
+
<div id="validation-modal" class="modal-overlay">
|
| 227 |
+
<div class="alert-box">
|
| 228 |
+
<h3><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.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line></svg> ویدیو نامعتبر</h3>
|
| 229 |
+
<p>مدت زمان ویدیو باید بین ۲ تا ۳۰ ثانیه باشد. لطفاً ویدیوی دیگری انتخاب کنید.</p>
|
| 230 |
+
<button id="close-validation-btn">متوجه شدم</button>
|
| 231 |
+
</div>
|
| 232 |
+
</div>
|
| 233 |
+
|
| 234 |
+
<svg width="0" height="0" style="position:absolute;">
|
| 235 |
+
<defs><linearGradient id="timer-gradient" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="var(--accent-secondary)" /><stop offset="100%" stop-color="var(--accent-primary)" /></linearGradient></defs>
|
| 236 |
+
</svg>
|
| 237 |
+
<script>
|
| 238 |
+
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=25,maxDistance=120;const computedStyles=getComputedStyle(document.documentElement),particleColor=computedStyles.getPropertyValue("--accent-primary").trim(),lineColor=computedStyles.getPropertyValue("--text-tertiary").trim();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=.3*(Math.random()-.5),this.vy=.3*(Math.random()-.5),this.radius=1.5}update(){this.x+=this.vx,this.y+=this.vy,(this.x<0||this.x>canvas.width)&&(this.vx*=-1),(this.y<0||this.y>canvas.height)&&(this.vy*=-1)}draw(){ctx.beginPath(),ctx.arc(this.x,this.y,this.radius,0,2*Math.PI),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,dy=particles[i].y-particles[j].y,distance=Math.sqrt(dx*dx+dy*dy);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=.2,ctx.globalAlpha=1-distance/maxDistance,ctx.stroke())}ctx.globalAlpha=1}function animate(){ctx.clearRect(0,0,canvas.width,canvas.height),particles.forEach((particle=>{particle.update(),particle.draw()})),connectParticles(),requestAnimationFrame(animate)}window.addEventListener("resize",resizeCanvas),resizeCanvas(),animate()});
|
| 239 |
+
</script>
|
| 240 |
+
|
| 241 |
+
<script type="module">
|
| 242 |
+
const API_BASE_URL = "/api";
|
| 243 |
+
const MAX_CONCURRENT_JOBS = 3;
|
| 244 |
+
const MAX_JOBS_IN_GALLERY = 20;
|
| 245 |
+
const COUNTDOWN_DURATION_MINUTES = 20;
|
| 246 |
+
const STUCK_JOB_DELETE_THRESHOLD_MINUTES = 30;
|
| 247 |
+
// <<< محدوده زمانی ویدیو >>>
|
| 248 |
+
const MIN_VIDEO_DURATION = 2;
|
| 249 |
+
const MAX_VIDEO_DURATION = 30;
|
| 250 |
+
|
| 251 |
+
const db = {
|
| 252 |
+
_db: null,
|
| 253 |
+
init(dbName, version) { return new Promise((resolve, reject) => { const request = indexedDB.open(dbName, version); request.onupgradeneeded = e => { const db = e.target.result; if (!db.objectStoreNames.contains('jobs')) db.createObjectStore('jobs', { keyPath: 'id' }); }; request.onsuccess = e => { this._db = e.target.result; resolve(this); }; request.onerror = e => reject(e.target.error); }); },
|
| 254 |
+
set(storeName, value) { return new Promise((resolve, reject) => { const tx = this._db.transaction(storeName, 'readwrite'); tx.oncomplete = () => resolve(); tx.onerror = e => reject(e.target.error); tx.objectStore(storeName).put(value); }); },
|
| 255 |
+
get(storeName, key) { return new Promise((resolve, reject) => { const request = this._db.transaction(storeName, 'readonly').objectStore(storeName).get(key); request.onsuccess = () => resolve(request.result); request.onerror = e => reject(e.target.error); }); },
|
| 256 |
+
delete(storeName, key) { return new Promise((resolve, reject) => { const tx = this._db.transaction(storeName, 'readwrite'); tx.oncomplete = () => resolve(); tx.onerror = e => reject(e.target.error); tx.objectStore(storeName).delete(key); }); },
|
| 257 |
+
getAll(storeName) { return new Promise((resolve, reject) => { const request = this._db.transaction(storeName, 'readonly').objectStore(storeName).getAll(); request.onsuccess = () => resolve(request.result); request.onerror = e => reject(e.target.error); }); }
|
| 258 |
+
};
|
| 259 |
+
|
| 260 |
+
const generateBtn = document.getElementById('generateButton');
|
| 261 |
+
const gallery = document.getElementById('results-gallery');
|
| 262 |
+
const alertModal = document.getElementById('alert-modal');
|
| 263 |
+
const closeAlertBtn = document.getElementById('close-alert-btn');
|
| 264 |
+
const termsModal = document.getElementById('terms-modal');
|
| 265 |
+
const acceptTermsBtn = document.getElementById('accept-terms-btn');
|
| 266 |
+
const motionHint = document.getElementById('motion-hint');
|
| 267 |
+
const motionRadios = document.querySelectorAll('input[name="motion"]');
|
| 268 |
+
|
| 269 |
+
const deleteConfirmModal = document.getElementById('delete-confirm-modal');
|
| 270 |
+
const confirmDeleteBtn = deleteConfirmModal.querySelector('.confirm-delete-btn');
|
| 271 |
+
const cancelDeleteBtn = deleteConfirmModal.querySelector('.cancel-delete-btn');
|
| 272 |
+
|
| 273 |
+
// <<< المانهای مدال جدید >>>
|
| 274 |
+
const validationModal = document.getElementById('validation-modal');
|
| 275 |
+
const closeValidationBtn = document.getElementById('close-validation-btn');
|
| 276 |
+
|
| 277 |
+
let currentImageFile = null; let currentVideoFile = null; let pollingIntervals = {}; let jobTimers = {}; let hintTimeout = null;
|
| 278 |
+
const motionHints = { 'wan2.2-animate-mix': 'تصویر شما در موقعیت ویدیوی ورودی قرار خواهد گرفت.', 'wan2.2-animate-move': 'حرکات ویدیو روی تصویر شما اعمال خواهد شد.' };
|
| 279 |
+
|
| 280 |
+
const showAlert = (modalElem) => modalElem.classList.add('visible');
|
| 281 |
+
const hideAlert = (modalElem) => modalElem.classList.remove('visible');
|
| 282 |
+
closeAlertBtn.addEventListener('click', () => hideAlert(alertModal));
|
| 283 |
+
closeValidationBtn.addEventListener('click', () => hideAlert(validationModal));
|
| 284 |
+
|
| 285 |
+
function updateGenerateButtonState() { generateBtn.disabled = !(currentImageFile && currentVideoFile); }
|
| 286 |
+
|
| 287 |
+
// <<< تابع setupDropZone با منطق اعتبارسنجی >>>
|
| 288 |
+
function setupDropZone(zoneId, inputId, previewId, fileType, onFileSet) {
|
| 289 |
+
const dropZone = document.getElementById(zoneId);
|
| 290 |
+
const fileInput = document.getElementById(inputId);
|
| 291 |
+
const preview = document.getElementById(previewId);
|
| 292 |
+
const removeBtn = document.getElementById(`remove-${fileType}-btn`);
|
| 293 |
+
|
| 294 |
+
const reset = () => {
|
| 295 |
+
fileInput.value = '';
|
| 296 |
+
dropZone.classList.remove('has-file');
|
| 297 |
+
if (preview.src) { URL.revokeObjectURL(preview.src); }
|
| 298 |
+
preview.src = '';
|
| 299 |
+
preview.style.display = 'none';
|
| 300 |
+
onFileSet(null);
|
| 301 |
+
};
|
| 302 |
+
|
| 303 |
+
const handleFile = (file) => {
|
| 304 |
+
if (!file) return;
|
| 305 |
+
|
| 306 |
+
const objectURL = URL.createObjectURL(file);
|
| 307 |
+
|
| 308 |
+
if (fileType === 'video') {
|
| 309 |
+
const videoElement = document.createElement('video');
|
| 310 |
+
videoElement.preload = 'metadata';
|
| 311 |
+
videoElement.src = objectURL;
|
| 312 |
+
|
| 313 |
+
videoElement.onloadedmetadata = () => {
|
| 314 |
+
const duration = videoElement.duration;
|
| 315 |
+
if (duration >= MIN_VIDEO_DURATION && duration <= MAX_VIDEO_DURATION) {
|
| 316 |
+
dropZone.classList.add('has-file');
|
| 317 |
+
preview.src = objectURL;
|
| 318 |
+
preview.style.display = 'block';
|
| 319 |
+
onFileSet(file);
|
| 320 |
+
} else {
|
| 321 |
+
showAlert(validationModal);
|
| 322 |
+
reset();
|
| 323 |
+
}
|
| 324 |
+
};
|
| 325 |
+
videoElement.onerror = () => {
|
| 326 |
+
alert("خطا در خواندن فایل ویدیو. لطفاً فایل دیگری را امتحان کنید.");
|
| 327 |
+
reset();
|
| 328 |
+
};
|
| 329 |
+
} else { // برای عکس
|
| 330 |
+
dropZone.classList.add('has-file');
|
| 331 |
+
preview.src = objectURL;
|
| 332 |
+
preview.style.display = 'block';
|
| 333 |
+
onFileSet(file);
|
| 334 |
+
}
|
| 335 |
+
};
|
| 336 |
+
|
| 337 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eName => dropZone.addEventListener(eName, e => {e.preventDefault(); e.stopPropagation();}));
|
| 338 |
+
['dragenter', 'dragover'].forEach(eName => dropZone.addEventListener(eName, () => dropZone.classList.add('drag-over')));
|
| 339 |
+
['dragleave', 'drop'].forEach(eName => dropZone.addEventListener(eName, () => dropZone.classList.remove('drag-over')));
|
| 340 |
+
dropZone.addEventListener('drop', e => { if (e.dataTransfer.files.length > 0) handleFile(e.dataTransfer.files[0]); });
|
| 341 |
+
fileInput.addEventListener('change', e => { if (e.target.files.length > 0) handleFile(e.target.files[0]); });
|
| 342 |
+
removeBtn.addEventListener('click', e => { e.stopPropagation(); reset(); });
|
| 343 |
+
|
| 344 |
+
return reset;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
const resetImage = setupDropZone('image-drop-zone', 'image-input', 'image-preview', 'image', file => { currentImageFile = file; updateGenerateButtonState(); });
|
| 348 |
+
const resetVideo = setupDropZone('video-drop-zone', 'video-input', 'video-preview', 'video', file => { currentVideoFile = file; updateGenerateButtonState(); });
|
| 349 |
+
|
| 350 |
+
motionRadios.forEach(radio => { radio.addEventListener('change', (e) => { const hintText = motionHints[e.target.value]; if (hintText) { motionHint.textContent = hintText; motionHint.classList.remove('visible'); clearTimeout(hintTimeout); setTimeout(() => { motionHint.classList.add('visible'); hintTimeout = setTimeout(() => { motionHint.classList.remove('visible'); }, 4000); }, 50); } }); });
|
| 351 |
+
|
| 352 |
+
function createJobCard(job) {
|
| 353 |
+
let card = document.getElementById(`job-${job.id}`);
|
| 354 |
+
if (!card) { card = document.createElement('div'); card.id = `job-${job.id}`; card.className = 'job-card'; gallery.prepend(card); }
|
| 355 |
+
if (jobTimers[job.id]) { clearInterval(jobTimers[job.id]); delete jobTimers[job.id]; }
|
| 356 |
+
|
| 357 |
+
if (job.status === 'completed') {
|
| 358 |
+
card.classList.remove('in-progress', 'error');
|
| 359 |
+
card.classList.add('completed');
|
| 360 |
+
card.innerHTML = `<div class="job-header"><span class="job-id">${job.id.substring(0, 8)}</span><span class="job-status" style="color: var(--success-color);">✅ انجام شد</span></div><video src="${job.result}" controls loop autoplay muted></video><div class="video-controls"><button class="video-button download-via-post-btn" data-video-url="${job.result}">دانلود ویدیو</button><button class="delete-job-btn video-button" data-job-id="${job.id}" title="حذف"><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"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></button></div>`;
|
| 361 |
+
} else if (job.status === 'error') {
|
| 362 |
+
card.classList.remove('in-progress', 'completed');
|
| 363 |
+
card.classList.add('error');
|
| 364 |
+
card.innerHTML = `<div class="job-header"><span class="job-id">${job.id.substring(0, 8)}</span><span class="job-status" style="color: var(--danger-color);">❌ خطا</span></div><div class="job-body">${job.result || 'خطای نامشخص'}</div><div class="video-controls"><button class="delete-job-btn video-button" data-job-id="${job.id}" title="حذف خطا"><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"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg> <span>حذف</span></button></div>`;
|
| 365 |
+
} else {
|
| 366 |
+
card.classList.remove('completed', 'error');
|
| 367 |
+
card.classList.add('in-progress');
|
| 368 |
+
card.innerHTML = `<div class="job-header"><span class="job-id">${job.id.substring(0, 8)}</span><span class="job-status">${job.status || 'در حال ارسال...'}</span></div><div class="reassurance-message"><strong>خیالتان راحت!</strong><p>پردازش ویدیوی شما شروع ش��ه. میتوانید این صفحه را ببندید و بعداً سر بزنید.</p></div><div class="job-body"><div class="timer-container"><svg class="timer-svg" viewBox="0 0 100 100"><circle class="timer-circle-bg" cx="50" cy="50" r="45"></circle><circle class="timer-circle-progress" cx="50" cy="50" r="45"></circle></svg><div class="timer-text">--:--</div></div><div class="in-progress-controls"><button class="quick-check-btn"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 12 A8 8 0 0 1 12 20 A8 8 0 0 1 4 12 A8 8 0 0 1 20 12 z"/><path d="M12 8v4l2 2"/></svg><span>پیگیری سریع</span></button><button class="delete-job-btn video-button hidden" data-job-id="${job.id}" title="حذف"><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"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg></button></div><div class="quick-check-feedback"></div></div>`;
|
| 369 |
+
|
| 370 |
+
const timerText = card.querySelector('.timer-text');
|
| 371 |
+
const progressCircle = card.querySelector('.timer-circle-progress');
|
| 372 |
+
const statusElem = card.querySelector('.job-status');
|
| 373 |
+
const deleteBtn = card.querySelector('.delete-job-btn');
|
| 374 |
+
const radius = progressCircle.r.baseVal.value;
|
| 375 |
+
const circumference = 2 * Math.PI * radius;
|
| 376 |
+
progressCircle.style.strokeDasharray = circumference;
|
| 377 |
+
const countdownTotalSeconds = COUNTDOWN_DURATION_MINUTES * 60;
|
| 378 |
+
|
| 379 |
+
const updateTimer = () => {
|
| 380 |
+
const elapsedSeconds = Math.floor((Date.now() - job.timestamp) / 1000);
|
| 381 |
+
const elapsedMinutes = elapsedSeconds / 60;
|
| 382 |
+
|
| 383 |
+
let remainingSeconds = countdownTotalSeconds - elapsedSeconds;
|
| 384 |
+
if (remainingSeconds <= 0) {
|
| 385 |
+
remainingSeconds = 0;
|
| 386 |
+
if (statusElem && !['completed', 'error'].includes(job.status)) statusElem.textContent = 'در حال نهایی سازی...';
|
| 387 |
+
}
|
| 388 |
+
const minutes = String(Math.floor(remainingSeconds / 60)).padStart(2, '0');
|
| 389 |
+
const seconds = String(remainingSeconds % 60).padStart(2, '0');
|
| 390 |
+
timerText.textContent = `${minutes}:${seconds}`;
|
| 391 |
+
const progress = remainingSeconds / countdownTotalSeconds;
|
| 392 |
+
const offset = circumference * (1 - progress);
|
| 393 |
+
progressCircle.style.strokeDashoffset = offset;
|
| 394 |
+
|
| 395 |
+
if (deleteBtn && elapsedMinutes >= STUCK_JOB_DELETE_THRESHOLD_MINUTES) {
|
| 396 |
+
deleteBtn.classList.remove('hidden');
|
| 397 |
+
if (jobTimers[job.id]) { clearInterval(jobTimers[job.id]); }
|
| 398 |
+
}
|
| 399 |
+
};
|
| 400 |
+
updateTimer();
|
| 401 |
+
jobTimers[job.id] = setInterval(updateTimer, 1000);
|
| 402 |
+
|
| 403 |
+
const quickCheckBtn = card.querySelector('.quick-check-btn');
|
| 404 |
+
if (quickCheckBtn) {
|
| 405 |
+
quickCheckBtn.addEventListener('click', () => {
|
| 406 |
+
const feedbackElem = card.querySelector('.quick-check-feedback');
|
| 407 |
+
if(feedbackElem) { feedbackElem.textContent = 'در حال بررسی وضعیت...'; feedbackElem.classList.add('visible'); setTimeout(() => { feedbackElem.classList.remove('visible'); }, 3000); }
|
| 408 |
+
checkJobStatus(job.id, true);
|
| 409 |
+
});
|
| 410 |
+
}
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
async function manageGalleryLimit() {
|
| 415 |
+
const allJobs = await db.getAll('jobs');
|
| 416 |
+
if (allJobs.length > MAX_JOBS_IN_GALLERY) {
|
| 417 |
+
const jobToRemove = allJobs.sort((a, b) => a.timestamp - b.timestamp).find(j => j.status === 'completed' || j.status === 'error');
|
| 418 |
+
if (jobToRemove) {
|
| 419 |
+
await db.delete('jobs', jobToRemove.id);
|
| 420 |
+
const cardToRemove = document.getElementById(`job-${jobToRemove.id}`);
|
| 421 |
+
if (cardToRemove) cardToRemove.remove();
|
| 422 |
+
}
|
| 423 |
+
}
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
async function checkJobStatus(jobId, isManualCheck = false) {
|
| 427 |
+
const btn = document.querySelector(`#job-${jobId} .quick-check-btn`);
|
| 428 |
+
if (isManualCheck && btn) { btn.disabled = true; btn.querySelector('span').textContent = 'در حال بررسی...'; }
|
| 429 |
+
try {
|
| 430 |
+
const response = await fetch(`${API_BASE_URL}/check_status`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ job_id: jobId }) });
|
| 431 |
+
if (!response.ok) throw new Error('خطا در بررسی وضعیت');
|
| 432 |
+
const data = await response.json(); const job = await db.get('jobs', jobId);
|
| 433 |
+
if (job && (job.status !== data.status || job.result !== data.result)) { job.status = data.status; job.result = data.result; await db.set('jobs', job); createJobCard(job); }
|
| 434 |
+
if (data.status === 'completed' || data.status === 'error') { if (pollingIntervals[jobId]) { clearInterval(pollingIntervals[jobId]); delete pollingIntervals[jobId]; } }
|
| 435 |
+
else if (isManualCheck) { const feedbackElem = document.querySelector(`#job-${jobId} .quick-check-feedback`); if(feedbackElem) feedbackElem.textContent = 'هنوز در حال پردازش است.'; }
|
| 436 |
+
} catch (e) { console.error("خطا:", e); }
|
| 437 |
+
finally { if (isManualCheck && btn) { setTimeout(() => { if(btn) { btn.disabled = false; btn.querySelector('span').textContent = 'پیگیری سریع'; } }, 2000); } }
|
| 438 |
+
}
|
| 439 |
+
|
| 440 |
+
async function main() {
|
| 441 |
+
const jobDB = await db.init('AnimationJobsDB_v15_Validation', 1);
|
| 442 |
+
|
| 443 |
+
if (localStorage.getItem('termsAccepted_v1') !== 'true') {
|
| 444 |
+
showAlert(termsModal);
|
| 445 |
+
}
|
| 446 |
+
acceptTermsBtn.addEventListener('click', () => {
|
| 447 |
+
localStorage.setItem('termsAccepted_v1', 'true');
|
| 448 |
+
hideAlert(termsModal);
|
| 449 |
+
});
|
| 450 |
+
|
| 451 |
+
const allJobs = await jobDB.getAll('jobs');
|
| 452 |
+
allJobs.sort((a, b) => a.timestamp - b.timestamp).forEach(job => {
|
| 453 |
+
createJobCard(job);
|
| 454 |
+
if (job.status !== 'completed' && job.status !== 'error') {
|
| 455 |
+
checkJobStatus(job.id);
|
| 456 |
+
pollingIntervals[job.id] = setInterval(() => checkJobStatus(job.id), 15000);
|
| 457 |
+
}
|
| 458 |
+
});
|
| 459 |
+
|
| 460 |
+
generateBtn.addEventListener('click', async () => {
|
| 461 |
+
if (!currentImageFile || !currentVideoFile) return;
|
| 462 |
+
const currentJobs = await jobDB.getAll('jobs'); const activeJobs = currentJobs.filter(j => j.status !== 'completed' && j.status !== 'error');
|
| 463 |
+
if (activeJobs.length >= MAX_CONCURRENT_JOBS) { showAlert(alertModal); return; }
|
| 464 |
+
generateBtn.disabled = true; generateBtn.querySelector('span').textContent = 'در حال ارسال...';
|
| 465 |
+
try {
|
| 466 |
+
await manageGalleryLimit();
|
| 467 |
+
const formData = new FormData();
|
| 468 |
+
formData.append('image_file', currentImageFile); formData.append('video_file', currentVideoFile); formData.append('motion', document.querySelector('input[name="motion"]:checked').value); formData.append('style', 'wan-pro');
|
| 469 |
+
const response = await fetch(`${API_BASE_URL}/submit_job`, { method: 'POST', body: formData });
|
| 470 |
+
if (!response.ok) { const errData = await response.json(); throw new Error(errData.error || 'خطای ناشناخته از سرور'); }
|
| 471 |
+
const data = await response.json(); const newJob = { id: data.job_id, status: 'ارسال شد، در صف پردازش...', timestamp: Date.now() };
|
| 472 |
+
await jobDB.set('jobs', newJob); createJobCard(newJob);
|
| 473 |
+
pollingIntervals[newJob.id] = setInterval(() => checkJobStatus(newJob.id), 15000);
|
| 474 |
+
resetImage(); resetVideo();
|
| 475 |
+
} catch (e) {
|
| 476 |
+
const alertBox = document.querySelector('#alert-modal .alert-box');
|
| 477 |
+
if (alertBox) {
|
| 478 |
+
if (e.message.includes('<strong>')) {
|
| 479 |
+
alertBox.querySelector('h3').textContent = 'خطا در ارسال';
|
| 480 |
+
alertBox.querySelector('p').innerHTML = e.message;
|
| 481 |
+
} else {
|
| 482 |
+
alertBox.querySelector('h3').textContent = 'یک خطا رخ داد';
|
| 483 |
+
alertBox.querySelector('p').textContent = e.message;
|
| 484 |
+
}
|
| 485 |
+
showAlert(alertModal);
|
| 486 |
+
} else {
|
| 487 |
+
alert('خطا: ' + e.message.replace(/<br>/g, '\n').replace(/<[^>]*>?/gm, ''));
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
finally { generateBtn.querySelector('span').textContent = 'ساخت ویدیو'; updateGenerateButtonState(); }
|
| 491 |
+
});
|
| 492 |
+
|
| 493 |
+
gallery.addEventListener('click', e => {
|
| 494 |
+
const button = e.target.closest('.delete-job-btn, .download-via-post-btn');
|
| 495 |
+
if (!button) return;
|
| 496 |
+
|
| 497 |
+
if (button.classList.contains('delete-job-btn')) {
|
| 498 |
+
const jobId = button.dataset.jobId;
|
| 499 |
+
deleteConfirmModal.dataset.jobIdToDelete = jobId;
|
| 500 |
+
showAlert(deleteConfirmModal);
|
| 501 |
+
}
|
| 502 |
+
else if (button.classList.contains('download-via-post-btn')) {
|
| 503 |
+
const relativeVideoUrl = button.dataset.videoUrl;
|
| 504 |
+
if (relativeVideoUrl) {
|
| 505 |
+
const absoluteVideoUrl = new URL(relativeVideoUrl, window.location.href).href;
|
| 506 |
+
if (window.parent !== window) {
|
| 507 |
+
window.parent.postMessage({ type: 'DOWNLOAD_REQUEST', url: absoluteVideoUrl }, '*');
|
| 508 |
+
} else {
|
| 509 |
+
console.warn('این صفحه در iframe نیست. لینک به صورت مستقیم باز میشود.');
|
| 510 |
+
window.open(absoluteVideoUrl, '_blank');
|
| 511 |
+
}
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
});
|
| 515 |
+
|
| 516 |
+
confirmDeleteBtn.addEventListener('click', async () => {
|
| 517 |
+
const jobId = deleteConfirmModal.dataset.jobIdToDelete;
|
| 518 |
+
if (!jobId) return;
|
| 519 |
+
|
| 520 |
+
const cardToDelete = document.getElementById(`job-${jobId}`);
|
| 521 |
+
if (cardToDelete) {
|
| 522 |
+
cardToDelete.classList.add('deleting');
|
| 523 |
+
setTimeout(async () => {
|
| 524 |
+
await db.delete('jobs', jobId);
|
| 525 |
+
cardToDelete.remove();
|
| 526 |
+
hideAlert(deleteConfirmModal);
|
| 527 |
+
delete deleteConfirmModal.dataset.jobIdToDelete;
|
| 528 |
+
}, 500);
|
| 529 |
+
}
|
| 530 |
+
});
|
| 531 |
+
|
| 532 |
+
cancelDeleteBtn.addEventListener('click', () => hideAlert(deleteConfirmModal));
|
| 533 |
+
deleteConfirmModal.addEventListener('click', e => {
|
| 534 |
+
if (e.target === deleteConfirmModal) hideAlert(deleteConfirmModal);
|
| 535 |
+
});
|
| 536 |
+
|
| 537 |
+
updateGenerateButtonState();
|
| 538 |
+
}
|
| 539 |
+
main().catch(console.error);
|
| 540 |
+
</script>
|
| 541 |
+
</body>
|
| 542 |
+
</html>
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
requests
|
| 3 |
+
gunicorn
|
| 4 |
+
python-dotenv
|