Opera8 commited on
Commit
be55781
·
verified ·
1 Parent(s): 0c14836

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -2492,10 +2492,14 @@ ENHANCE_NO_TEXT = "دستور بهینه نشود ✋"
2492
 
2493
  # --- توابع کنترل کننده (بدون وابستگی محلی) ---
2494
 
2495
- def ui_lock_and_enhance(first_frame, prompt, mode, enhance_toggle):
2496
  """
2497
  مرحله ۱: قفل کردن UI و بررسی اینکه آیا پرامپت نیاز به بهینه‌سازی دارد یا خیر
2498
  """
 
 
 
 
2499
  if enhance_toggle == ENHANCE_YES_TEXT:
2500
  yield (
2501
  gr.Button(value="⏳ در حال بهینه سازی پرامپت (CPU)...", interactive=False),
@@ -2530,6 +2534,10 @@ def ui_generate_video(
2530
  """
2531
  مرحله ۲: ساخت ویدیو با استفاده از GPU
2532
  """
 
 
 
 
2533
  video_path = generate_video(
2534
  first_frame, end_frame, enhanced_prompt, duration, input_video,
2535
  radioanimated_mode, False, seed, randomize_seed,
@@ -2574,7 +2582,7 @@ relocate_js = r"""
2574
  m.addedNodes.forEach(node => {
2575
  if (node.nodeType === 1) {
2576
  const txt = (node.textContent || "").toLowerCase();
2577
- if (txt.includes("quota") || txt.includes("exceeded") || txt.includes("error") || txt.includes("خطا")) {
2578
  errorFound = true;
2579
  }
2580
  if (node.classList && node.classList.contains("toast-wrap")) {
@@ -2685,7 +2693,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2685
  with gr.Row():
2686
  download_btn = gr.Button("📥 دانلود ویدیو", variant="secondary", size="sm", scale=0, visible=False)
2687
  with gr.Row(elem_id="controls-row"):
2688
- duration_ui = CameraDropdown(choices=["3s", "5s", "6s", "10s"], value="5s", title="مدت زمان ویدیو", elem_id="duration_ui")
2689
  duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=5.0, step=0.1, visible=False)
2690
  ICON_16_9, ICON_1_1, ICON_9_16 = ("<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='3' y='7' width='18' height='10' rx='2' stroke='currentColor' stroke-width='2'/></svg>", "<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='6' y='6' width='12' height='12' rx='2' stroke='currentColor' stroke-width='2'/></svg>", "<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='7' y='3' width='10' height='18' rx='2' stroke='currentColor' stroke-width='2'/></svg>")
2691
  resolution_ui = CameraDropdown(choices=[{"label": "16:9", "value": "16:9", "icon": ICON_16_9}, {"label": "1:1", "value": "1:1", "icon": ICON_1_1}, {"label": "9:16", "value": "9:16", "icon": ICON_9_16}], value="16:9", title="ابعاد تصویر", elem_id="resolution_ui")
@@ -2778,7 +2786,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2778
  # زنجیره اصلی ساخت ویدیو
2779
  generate_btn.click(
2780
  fn=ui_lock_and_enhance,
2781
- inputs=[first_frame, prompt, radioanimated_mode, enhance_toggle],
2782
  outputs=[generate_btn, prompt_ui, prompt, output_video]
2783
  ).then(
2784
  fn=ui_generate_video,
 
2492
 
2493
  # --- توابع کنترل کننده (بدون وابستگی محلی) ---
2494
 
2495
+ def ui_lock_and_enhance(first_frame, prompt, mode, enhance_toggle, audio_input, duration):
2496
  """
2497
  مرحله ۱: قفل کردن UI و بررسی اینکه آیا پرامپت نیاز به بهینه‌سازی دارد یا خیر
2498
  """
2499
+ # بررسی محدودیت زمانی برای فایل صوتی
2500
+ if audio_input is not None and float(duration) > 5.0:
2501
+ raise gr.Error("در صورت وجود همزمان فایل صوتی امکان ساخت فقط تا پنج ثانیه امکان پذیر است")
2502
+
2503
  if enhance_toggle == ENHANCE_YES_TEXT:
2504
  yield (
2505
  gr.Button(value="⏳ در حال بهینه سازی پرامپت (CPU)...", interactive=False),
 
2534
  """
2535
  مرحله ۲: ساخت ویدیو با استفاده از GPU
2536
  """
2537
+ # بررسی مجدد محدودیت زمانی برای اطمینان در مرحله ساخت
2538
+ if audio_input is not None and float(duration) > 5.0:
2539
+ raise gr.Error("در صورت وجود همزمان فایل صوتی امکان ساخت فقط تا پنج ثانیه امکان پذیر است")
2540
+
2541
  video_path = generate_video(
2542
  first_frame, end_frame, enhanced_prompt, duration, input_video,
2543
  radioanimated_mode, False, seed, randomize_seed,
 
2582
  m.addedNodes.forEach(node => {
2583
  if (node.nodeType === 1) {
2584
  const txt = (node.textContent || "").toLowerCase();
2585
+ if (txt.includes("quota") || txt.includes("exceeded") || txt.includes("error") || txt.includes("خطا") || txt.includes("فایل صوتی")) {
2586
  errorFound = true;
2587
  }
2588
  if (node.classList && node.classList.contains("toast-wrap")) {
 
2693
  with gr.Row():
2694
  download_btn = gr.Button("📥 دانلود ویدیو", variant="secondary", size="sm", scale=0, visible=False)
2695
  with gr.Row(elem_id="controls-row"):
2696
+ duration_ui = CameraDropdown(choices=["3s", "5s", "7s", "10s"], value="5s", title="مدت زمان ویدیو", elem_id="duration_ui")
2697
  duration = gr.Slider(label="Duration (seconds)", minimum=1.0, maximum=10.0, value=5.0, step=0.1, visible=False)
2698
  ICON_16_9, ICON_1_1, ICON_9_16 = ("<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='3' y='7' width='18' height='10' rx='2' stroke='currentColor' stroke-width='2'/></svg>", "<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='6' y='6' width='12' height='12' rx='2' stroke='currentColor' stroke-width='2'/></svg>", "<svg viewBox='0 0 24 24' fill='none' aria-hidden='true'><rect x='7' y='3' width='10' height='18' rx='2' stroke='currentColor' stroke-width='2'/></svg>")
2699
  resolution_ui = CameraDropdown(choices=[{"label": "16:9", "value": "16:9", "icon": ICON_16_9}, {"label": "1:1", "value": "1:1", "icon": ICON_1_1}, {"label": "9:16", "value": "9:16", "icon": ICON_9_16}], value="16:9", title="ابعاد تصویر", elem_id="resolution_ui")
 
2786
  # زنجیره اصلی ساخت ویدیو
2787
  generate_btn.click(
2788
  fn=ui_lock_and_enhance,
2789
+ inputs=[first_frame, prompt, radioanimated_mode, enhance_toggle, audio_input, duration],
2790
  outputs=[generate_btn, prompt_ui, prompt, output_video]
2791
  ).then(
2792
  fn=ui_generate_video,