Update yml/ltxvideo.py
Browse files- yml/ltxvideo.py +12 -16
yml/ltxvideo.py
CHANGED
|
@@ -7,11 +7,11 @@ import random
|
|
| 7 |
import time
|
| 8 |
import io
|
| 9 |
|
| 10 |
-
# ثبت زمان دقیق شروع اجرای اسکریپت
|
| 11 |
start_time = time.time()
|
| 12 |
|
| 13 |
# =========================================================
|
| 14 |
-
# تنظیم زمان انتظار ارتباطی کلاینت به ۲۵۰ ثانیه جهت
|
| 15 |
import httpx
|
| 16 |
original_client_init = httpx.Client.__init__
|
| 17 |
def patched_client_init(self, *args, **kwargs):
|
|
@@ -80,7 +80,7 @@ except Exception as e:
|
|
| 80 |
report_failure(err_str)
|
| 81 |
sys.exit(1)
|
| 82 |
|
| 83 |
-
# مدیریت دانلود تصویر با
|
| 84 |
image_url = config.get("image_path")
|
| 85 |
local_img = "gen_input.png"
|
| 86 |
download_success = False
|
|
@@ -91,7 +91,6 @@ for dl_attempt in range(max_download_attempts):
|
|
| 91 |
try:
|
| 92 |
r = requests.get(image_url, timeout=45)
|
| 93 |
if r.status_code == 200:
|
| 94 |
-
# تایید سلامت فرمت تصویر و تبدیل به RGB خالص برای سازگاری با Gradio
|
| 95 |
img_data = io.BytesIO(r.content)
|
| 96 |
img = Image.open(img_data)
|
| 97 |
img.verify()
|
|
@@ -117,7 +116,6 @@ if not download_success:
|
|
| 117 |
report_failure(err_str)
|
| 118 |
sys.exit(1)
|
| 119 |
|
| 120 |
-
# پیکربندی پارامترهای اصلی ساخت ویدیو
|
| 121 |
base_seed = int(config.get("seed", -1))
|
| 122 |
seconds = float(config.get("seconds", 5.0))
|
| 123 |
prompt = config.get("prompt", "")
|
|
@@ -129,15 +127,15 @@ max_attempts = 4
|
|
| 129 |
|
| 130 |
# حلقه تلاش مجدد داخلی برای ساخت ویدیو
|
| 131 |
for attempt in range(max_attempts):
|
| 132 |
-
# پایش هوشمند زمان
|
|
|
|
|
|
|
| 133 |
elapsed_time = time.time() - start_time
|
| 134 |
-
if elapsed_time >
|
| 135 |
-
print(f"⏳ WARNING: Elapsed time is {elapsed_time:.1f}s.
|
| 136 |
-
|
| 137 |
-
report_failure("Runner execution time exceeded safe 10-minute limits. Initiating auto-retry on a fresh runner.")
|
| 138 |
sys.exit(1)
|
| 139 |
|
| 140 |
-
# تنظیم سید پردازش
|
| 141 |
seed = base_seed
|
| 142 |
if seed == -1:
|
| 143 |
seed = random.randint(1, 2147483647)
|
|
@@ -237,7 +235,6 @@ for attempt in range(max_attempts):
|
|
| 237 |
api_name="/generate"
|
| 238 |
)
|
| 239 |
|
| 240 |
-
# استخراج مسیر فایل ویدیو خروجی
|
| 241 |
if isinstance(result, (tuple, list)):
|
| 242 |
video_data = result[0]
|
| 243 |
else:
|
|
@@ -256,9 +253,8 @@ for attempt in range(max_attempts):
|
|
| 256 |
err_msg = str(e)
|
| 257 |
print(f" -> Failed on attempt {attempt + 1}: {err_msg}")
|
| 258 |
|
| 259 |
-
# شناسایی فوری محدودیت سهمیه هوش مصنوعی و خروج جهت سوئیچ اکانت گیتهاب توسط سرور اصلی
|
| 260 |
if 'ZeroGPU quota' in err_msg or 'quota' in err_msg.lower():
|
| 261 |
-
print(" -> ZeroGPU quota hit. Aborting internal attempts to
|
| 262 |
report_failure(err_msg)
|
| 263 |
sys.exit(1)
|
| 264 |
|
|
@@ -267,12 +263,12 @@ for attempt in range(max_attempts):
|
|
| 267 |
time.sleep(5.0)
|
| 268 |
|
| 269 |
if not video_path or not os.path.exists(video_path):
|
| 270 |
-
err_str = "Failed to generate video after all internal
|
| 271 |
print(f"CRITICAL ERROR: {err_str}")
|
| 272 |
report_failure(err_str)
|
| 273 |
sys.exit(1)
|
| 274 |
|
| 275 |
-
#
|
| 276 |
print("Uploading video back to space...")
|
| 277 |
ext = 'mp4'
|
| 278 |
if video_path.endswith('.webm'):
|
|
|
|
| 7 |
import time
|
| 8 |
import io
|
| 9 |
|
| 10 |
+
# ثبت زمان دقیق شروع اجرای اسکریپت رانر برای پیشگیری از رفتارهای پیشبینی نشده
|
| 11 |
start_time = time.time()
|
| 12 |
|
| 13 |
# =========================================================
|
| 14 |
+
# تنظیم زمان انتظار ارتباطی کلاینت به ۲۵۰ ثانیه جهت پایش مداوم استریمهای ناپایدار
|
| 15 |
import httpx
|
| 16 |
original_client_init = httpx.Client.__init__
|
| 17 |
def patched_client_init(self, *args, **kwargs):
|
|
|
|
| 80 |
report_failure(err_str)
|
| 81 |
sys.exit(1)
|
| 82 |
|
| 83 |
+
# مدیریت دانلود تصویر با ۵ بار تلاش جهت پیشگیری از خطای تاخیر دیسپچ داکر
|
| 84 |
image_url = config.get("image_path")
|
| 85 |
local_img = "gen_input.png"
|
| 86 |
download_success = False
|
|
|
|
| 91 |
try:
|
| 92 |
r = requests.get(image_url, timeout=45)
|
| 93 |
if r.status_code == 200:
|
|
|
|
| 94 |
img_data = io.BytesIO(r.content)
|
| 95 |
img = Image.open(img_data)
|
| 96 |
img.verify()
|
|
|
|
| 116 |
report_failure(err_str)
|
| 117 |
sys.exit(1)
|
| 118 |
|
|
|
|
| 119 |
base_seed = int(config.get("seed", -1))
|
| 120 |
seconds = float(config.get("seconds", 5.0))
|
| 121 |
prompt = config.get("prompt", "")
|
|
|
|
| 127 |
|
| 128 |
# حلقه تلاش مجدد داخلی برای ساخت ویدیو
|
| 129 |
for attempt in range(max_attempts):
|
| 130 |
+
# پایش زمانی هوشمند: اگر زمان اجرای رانر جاری بیش از ۴۵۰ ثانیه (۷.۵ دقیقه) شده باشد،
|
| 131 |
+
# دیگر وارد رندر جدید که حدود ۴ دقیقه طول میکشد نمیشویم؛ بلافاصله فرآیند را قطع کرده و وبهوک را صدا میزنیم
|
| 132 |
+
# تا تسک بر روی رانر گیتهاب کاملاً مستقل و تازهنفس جدیدی از نو اجرا شود (تا ۱۰ رانر معادل ۱۰۰ دقیقه)
|
| 133 |
elapsed_time = time.time() - start_time
|
| 134 |
+
if elapsed_time > 450.0:
|
| 135 |
+
print(f"⏳ WARNING: Elapsed time is {elapsed_time:.1f}s. Aborting this run to trigger a clean retry on a new runner.")
|
| 136 |
+
report_failure("TIMEOUT_VOLUNTARY_ABORT")
|
|
|
|
| 137 |
sys.exit(1)
|
| 138 |
|
|
|
|
| 139 |
seed = base_seed
|
| 140 |
if seed == -1:
|
| 141 |
seed = random.randint(1, 2147483647)
|
|
|
|
| 235 |
api_name="/generate"
|
| 236 |
)
|
| 237 |
|
|
|
|
| 238 |
if isinstance(result, (tuple, list)):
|
| 239 |
video_data = result[0]
|
| 240 |
else:
|
|
|
|
| 253 |
err_msg = str(e)
|
| 254 |
print(f" -> Failed on attempt {attempt + 1}: {err_msg}")
|
| 255 |
|
|
|
|
| 256 |
if 'ZeroGPU quota' in err_msg or 'quota' in err_msg.lower():
|
| 257 |
+
print(" -> ZeroGPU quota hit. Aborting internal attempts to trigger webhook fail and switch runner.")
|
| 258 |
report_failure(err_msg)
|
| 259 |
sys.exit(1)
|
| 260 |
|
|
|
|
| 263 |
time.sleep(5.0)
|
| 264 |
|
| 265 |
if not video_path or not os.path.exists(video_path):
|
| 266 |
+
err_str = "Failed to generate video after all internal attempts."
|
| 267 |
print(f"CRITICAL ERROR: {err_str}")
|
| 268 |
report_failure(err_str)
|
| 269 |
sys.exit(1)
|
| 270 |
|
| 271 |
+
# آپلود فایل نهایی و فرستادن اطلاعات سید
|
| 272 |
print("Uploading video back to space...")
|
| 273 |
ext = 'mp4'
|
| 274 |
if video_path.endswith('.webm'):
|