Opera8 commited on
Commit
99798ee
·
verified ·
1 Parent(s): 173e2b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -29
app.py CHANGED
@@ -2423,42 +2423,79 @@ def ui_generate_video(
2423
  )
2424
 
2425
 
2426
- # کدهای جاوااسکریپت برای انتقال المان‌ها و نظارت بر ارور محدودیت GPU
2427
  relocate_js = r"""
2428
  (() => {
 
 
 
 
 
2429
  function moveIntoFooter() {
2430
- const p = document.querySelector("#prompt_ui"), f = p ? p.querySelector(".ds-footer") : null;
 
 
2431
  if (!f) return false;
2432
- const d = document.querySelector("#duration_ui .cd-wrap"), r = document.querySelector("#resolution_ui .cd-wrap"), c = document.querySelector("#camera_ui .cd-wrap");
 
 
 
2433
  if (!d || !r || !c) return false;
2434
- f.appendChild(d); f.appendChild(r); f.appendChild(c);
 
 
 
2435
  return true;
2436
  }
2437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2438
  function setupErrorObserver() {
2439
- const getRoot = () => {
2440
- const app = document.querySelector('gradio-app');
2441
- return app && app.shadowRoot ? app.shadowRoot : document;
2442
- };
2443
- const observer = new MutationObserver((mutations) => {
2444
- mutations.forEach(m => {
2445
- m.addedNodes.forEach(node => {
2446
- if (node.nodeType === 1) {
2447
- // بررسی ظهور پاپ‌آپ‌های خطا یا محدودیت
2448
- const isToast = node.classList && (node.classList.contains('toast-wrap') || node.classList.contains('error') || node.tagName === 'TOAST');
2449
- const nodeText = (node.innerText || "").toLowerCase();
2450
- if (isToast || nodeText.includes('quota')) {
2451
- if (nodeText.includes("quota") || nodeText.includes("exceeded") || nodeText.includes("error") || nodeText.includes("خطا")) {
2452
- // در صورت مشاهده خطا دکمه ریست نامرئی کلیک می‌شود
2453
- const rb = getRoot().querySelector("#reset_btn");
2454
- if (rb) rb.click();
2455
- }
2456
- }
2457
- }
2458
- });
2459
- });
2460
- });
2461
- observer.observe(document.body, {childList: true, subtree: true});
 
 
2462
  }
2463
 
2464
  const tick = () => {
@@ -2521,7 +2558,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2521
  camera_lora = gr.Dropdown(label="Camera Control LoRA", choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES], value="No LoRA", visible=False)
2522
 
2523
  generate_btn = gr.Button("🤩 ساخت ویدیو", variant="primary", elem_classes="button-gradient", elem_id="generate_btn")
2524
- # دکمه پنهان که در صورت وقوع ارور توسط جاوااسکریپت کلیک می‌شود تا رابط کاربری بازیابی شود
2525
  reset_btn = gr.Button("Reset", visible=False, elem_id="reset_btn")
2526
 
2527
  # اتصال رویدادها
@@ -2533,7 +2570,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2533
  audio_ui.change(fn=lambda v: None if v == "__CLEAR__" or not v else gr.update(), inputs=audio_ui, outputs=audio_input, api_visibility="private")
2534
  download_btn.click(fn=None, inputs=[output_video], js=js_download_video)
2535
 
2536
- # رویداد بازیابی دکمه در زمان وقوع محدودیت (وصل شده به دکمه مخفی)
2537
  reset_btn.click(
2538
  fn=lambda: gr.Button(value="🤩 ساخت ویدیو", interactive=True),
2539
  inputs=[],
 
2423
  )
2424
 
2425
 
2426
+ # کدهای جاوااسکریپت بسیار پیشرفته‌تر برای تشخیص خطای خارج از بدنه گاردریو (ZeroGPU Modals)
2427
  relocate_js = r"""
2428
  (() => {
2429
+ function getGradioRoot() {
2430
+ const app = document.querySelector('gradio-app');
2431
+ return app && app.shadowRoot ? app.shadowRoot : document;
2432
+ }
2433
+
2434
  function moveIntoFooter() {
2435
+ const root = getGradioRoot();
2436
+ const p = root.querySelector("#prompt_ui");
2437
+ const f = p ? p.querySelector(".ds-footer") : null;
2438
  if (!f) return false;
2439
+
2440
+ const d = root.querySelector("#duration_ui .cd-wrap");
2441
+ const r = root.querySelector("#resolution_ui .cd-wrap");
2442
+ const c = root.querySelector("#camera_ui .cd-wrap");
2443
  if (!d || !r || !c) return false;
2444
+
2445
+ f.appendChild(d);
2446
+ f.appendChild(r);
2447
+ f.appendChild(c);
2448
  return true;
2449
  }
2450
 
2451
+ function forceResetButton() {
2452
+ const root = getGradioRoot();
2453
+
2454
+ // 1. شبیه‌سازی کلیک روی دکمه مخفی برای ریست بک‌اند پایتون
2455
+ const resetWrap = root.querySelector("#reset_btn");
2456
+ if (resetWrap) {
2457
+ const btn = resetWrap.querySelector("button") || resetWrap;
2458
+ if (btn) btn.click();
2459
+ }
2460
+
2461
+ // 2. تغییر ظاهری فوری دکمه اصلی جهت رفع سریع قفل
2462
+ const mainWrap = root.querySelector("#generate_btn");
2463
+ if (mainWrap) {
2464
+ const mainBtn = mainWrap.querySelector("button") || mainWrap;
2465
+ if (mainBtn) {
2466
+ mainBtn.innerText = "🤩 ساخت ویدیو";
2467
+ mainBtn.disabled = false;
2468
+ mainBtn.style.pointerEvents = "auto";
2469
+ }
2470
+ }
2471
+ }
2472
+
2473
  function setupErrorObserver() {
2474
+ // یک حلقه بی‌نهایت و امن که هر 800 میلی‌ثانیه کل صفحه را اسکن می‌کند
2475
+ setInterval(() => {
2476
+ let fullText = "";
2477
+
2478
+ // دریافت محتوای متنی از بدنه اصلی (Hugging Face مودال‌های خطا را اینجا تزریق می‌کند)
2479
+ fullText += document.body.innerText || "";
2480
+
2481
+ // دریافت محتوای متنی از ShadowDOM (خطاهای داخلی گاردریو)
2482
+ const root = getGradioRoot();
2483
+ if (root !== document) {
2484
+ fullText += root.textContent || "";
2485
+ }
2486
+
2487
+ fullText = fullText.toLowerCase();
2488
+
2489
+ // اگر خطای محدودیت کوپون دیده شد
2490
+ if (fullText.includes("exceeded your gpu quota") || fullText.includes("gpu quota")) {
2491
+ if (!window._quotaResetFired) {
2492
+ forceResetButton();
2493
+ window._quotaResetFired = true;
2494
+ // یک توقف کوتاه تا از اسپم شدن کلیک‌ها در طول نمایش خطا جلوگیری شود
2495
+ setTimeout(() => { window._quotaResetFired = false; }, 6000);
2496
+ }
2497
+ }
2498
+ }, 800);
2499
  }
2500
 
2501
  const tick = () => {
 
2558
  camera_lora = gr.Dropdown(label="Camera Control LoRA", choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES], value="No LoRA", visible=False)
2559
 
2560
  generate_btn = gr.Button("🤩 ساخت ویدیو", variant="primary", elem_classes="button-gradient", elem_id="generate_btn")
2561
+ # دکمه پنهانی که هنگام وقوع خطا کلیک می‌شود تا UI را بازسازی کند
2562
  reset_btn = gr.Button("Reset", visible=False, elem_id="reset_btn")
2563
 
2564
  # اتصال رویدادها
 
2570
  audio_ui.change(fn=lambda v: None if v == "__CLEAR__" or not v else gr.update(), inputs=audio_ui, outputs=audio_input, api_visibility="private")
2571
  download_btn.click(fn=None, inputs=[output_video], js=js_download_video)
2572
 
2573
+ # رویداد بازیابی دکمه در زمان وقوع محدودیت
2574
  reset_btn.click(
2575
  fn=lambda: gr.Button(value="🤩 ساخت ویدیو", interactive=True),
2576
  inputs=[],