Opera8 commited on
Commit
cc5d85e
·
verified ·
1 Parent(s): 8e3cc3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -39
app.py CHANGED
@@ -1017,13 +1017,13 @@ class AudioDropUpload(gr.HTML):
1017
 
1018
  html_template = f"""
1019
  <div class="aud-wrap" data-aud="{uid}">
1020
- <div class="aud-drop" role="button" tabindex="0" aria-label="Upload audio">
1021
- <div><strong>(Optional) Drag &amp; drop an audio file here</strong></div>
1022
- <div class="aud-hint">…or click to browse</div>
1023
  </div>
1024
  <div class="aud-row" aria-live="polite">
1025
  <audio class="aud-player" controls></audio>
1026
- <button class="aud-remove" type="button" aria-label="Remove audio">
1027
  <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
1028
  <path d="M18 6L6 18M6 6l12 12"
1029
  stroke="currentColor"
@@ -1073,7 +1073,7 @@ class AudioDropUpload(gr.HTML):
1073
  drop.style.display = "none";
1074
  row.style.display = "flex";
1075
  if (filename) {{
1076
- label.textContent = "Loaded: " + filename;
1077
  label.style.display = "block";
1078
  }}
1079
  }}
@@ -1093,8 +1093,8 @@ class AudioDropUpload(gr.HTML):
1093
  fileInput.value = "";
1094
  const dt = new DataTransfer();
1095
  fileInput.files = dt.files;
1096
- fileInput.dispatchEvent(new Event("input", { bubbles: true }));
1097
- fileInput.dispatchEvent(new Event("change", { bubbles: true }));
1098
  }}
1099
  function clearAll() {
1100
  clearPreview();
@@ -1112,7 +1112,7 @@ class AudioDropUpload(gr.HTML):
1112
  function loadFileToPreview(file) {{
1113
  if (!file) return;
1114
  if (!file.type || !file.type.startsWith("audio/")) {{
1115
- alert("Please choose an audio file.");
1116
  return;
1117
  }}
1118
  clearPreview();
@@ -1136,8 +1136,8 @@ class AudioDropUpload(gr.HTML):
1136
  fileInput.files = dt.files;
1137
 
1138
  // Trigger Gradio listeners
1139
- fileInput.dispatchEvent(new Event("input", { bubbles: true }));
1140
- fileInput.dispatchEvent(new Event("change", { bubbles: true }));
1141
  }
1142
 
1143
  function handleFile(file) {{
@@ -2385,13 +2385,13 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2385
  with gr.Row():
2386
 
2387
  first_frame = gr.Image(
2388
- label="First Frame (Optional)",
2389
  type="filepath",
2390
  height=256
2391
  )
2392
 
2393
  end_frame = gr.Image(
2394
- label="Last Frame (Optional)",
2395
  type="filepath",
2396
  height=256,
2397
  visible=False,
@@ -2439,7 +2439,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2439
 
2440
 
2441
  prompt_ui = PromptBox(
2442
- value="Make this image come alive with cinematic motion, smooth animation",
2443
  elem_id="prompt_ui",
2444
  )
2445
 
@@ -2459,10 +2459,10 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2459
 
2460
  prompt = gr.Textbox(
2461
  label="Prompt",
2462
- value="Make this image come alive with cinematic motion, smooth animation",
2463
  lines=3,
2464
  max_lines=3,
2465
- placeholder="Describe the motion and animation you want...",
2466
  visible=False
2467
  )
2468
 
@@ -2472,32 +2472,30 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2472
  visible=False
2473
  )
2474
 
2475
- with gr.Accordion("Advanced Settings", open=False, visible=False):
2476
  seed = gr.Slider(
2477
- label="Seed",
2478
  minimum=0,
2479
  maximum=MAX_SEED,
2480
  value=DEFAULT_SEED,
2481
  step=1
2482
  )
2483
 
2484
- randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
2485
 
2486
 
2487
  with gr.Column(elem_id="step-column"):
2488
- output_video = gr.Video(label="Generated Video", autoplay=True, height=512)
2489
 
2490
  with gr.Row(elem_id="controls-row"):
2491
 
2492
- # REMOVED 15s from choices
2493
  duration_ui = CameraDropdown(
2494
  choices=["3s", "5s", "10s"],
2495
  value="5s",
2496
- title="Clip Duration",
2497
  elem_id="duration_ui"
2498
  )
2499
 
2500
- # Reduced maximum to 10.0
2501
  duration = gr.Slider(
2502
  label="Duration (seconds)",
2503
  minimum=1.0,
@@ -2527,7 +2525,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2527
  {"label": "9:16", "value": "9:16", "icon": ICON_9_16},
2528
  ],
2529
  value="16:9",
2530
- title="Resolution",
2531
  elem_id="resolution_ui"
2532
  )
2533
 
@@ -2538,7 +2536,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2538
  camera_ui = CameraDropdown(
2539
  choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES],
2540
  value="No LoRA",
2541
- title="Camera LoRA",
2542
  elem_id="camera_ui",
2543
  )
2544
 
@@ -2550,7 +2548,7 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2550
  visible=False
2551
  )
2552
 
2553
- generate_btn = gr.Button("🤩 Generate Video", variant="primary", elem_classes="button-gradient")
2554
 
2555
 
2556
  camera_ui.change(
@@ -2672,28 +2670,26 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2672
  ],
2673
  ]
2674
 
2675
- # Create examples object just for caching/display, logic handled manually below
2676
  examples_obj = create_examples(
2677
  examples=examples_list,
2678
  fn=generate_video_example,
2679
  inputs=[first_frame, prompt_ui, camera_ui, resolution_ui, radioanimated_mode, input_video, audio_input, end_frame],
2680
  outputs = [output_video],
2681
- label="Examples",
2682
  cache_examples=True,
2683
  visible=False
2684
  )
2685
 
2686
  preset_gallery = PresetGallery(
2687
  items=[
2688
- {"thumb": "examples/supergirl-2.png", "label": "Example 1", "title": "Image + Audio to Video" },
2689
- {"thumb": "examples/frame3.png" , "label": "Example 2", "title": "First and Last Frame" },
2690
- {"thumb": "examples/supergirl.png" , "label": "Example 3", "title": "Image to Video" },
2691
- {"thumb": "examples/highland.png" , "label": "Example 6", "title": "Image to Video" },
2692
- {"thumb": "examples/wednesday.png" , "label": "Example 7", "title": "Image to Video" },
2693
- {"thumb": "examples/astronaut.png" , "label": "Example 8", "title": "Image to Video" },
2694
-
2695
  ],
2696
- title="Click on Our Examples",
2697
  )
2698
 
2699
  def on_audio_ui_change(v):
@@ -2710,9 +2706,6 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2710
  api_visibility="private",
2711
  )
2712
 
2713
- # REMOVED the run_cached_example_by_index logic.
2714
- # Just populate the fields.
2715
-
2716
  preset_gallery.change(
2717
  fn=apply_example,
2718
  inputs=preset_gallery,
@@ -2730,7 +2723,6 @@ with gr.Blocks(title="LTX-2 Video Distilled 🎥🔈") as demo:
2730
  ],
2731
  api_visibility="private",
2732
  )
2733
- # The .then() block is removed, so generation won't start automatically.
2734
 
2735
  if __name__ == "__main__":
2736
  demo.launch(ssr_mode=False, mcp_server=True, css=css, allowed_paths=["./examples"])
 
1017
 
1018
  html_template = f"""
1019
  <div class="aud-wrap" data-aud="{uid}">
1020
+ <div class="aud-drop" role="button" tabindex="0" aria-label="بارگذاری صدا">
1021
+ <div><strong>(اختیاری) فایل صوتی را اینجا بکشید و رها کنید</strong></div>
1022
+ <div class="aud-hint">…یا برای انتخاب کلیک کنید</div>
1023
  </div>
1024
  <div class="aud-row" aria-live="polite">
1025
  <audio class="aud-player" controls></audio>
1026
+ <button class="aud-remove" type="button" aria-label="حذف صدا">
1027
  <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
1028
  <path d="M18 6L6 18M6 6l12 12"
1029
  stroke="currentColor"
 
1073
  drop.style.display = "none";
1074
  row.style.display = "flex";
1075
  if (filename) {{
1076
+ label.textContent = "فایل بارگذاری شده: " + filename;
1077
  label.style.display = "block";
1078
  }}
1079
  }}
 
1093
  fileInput.value = "";
1094
  const dt = new DataTransfer();
1095
  fileInput.files = dt.files;
1096
+ fileInput.dispatchEvent(new Event("input", {{ bubbles: true }}));
1097
+ fileInput.dispatchEvent(new Event("change", {{ bubbles: true }}));
1098
  }}
1099
  function clearAll() {
1100
  clearPreview();
 
1112
  function loadFileToPreview(file) {{
1113
  if (!file) return;
1114
  if (!file.type || !file.type.startsWith("audio/")) {{
1115
+ alert("لطفا یک فایل صوتی انتخاب کنید.");
1116
  return;
1117
  }}
1118
  clearPreview();
 
1136
  fileInput.files = dt.files;
1137
 
1138
  // Trigger Gradio listeners
1139
+ fileInput.dispatchEvent(new Event("input", {{ bubbles: true }}));
1140
+ fileInput.dispatchEvent(new Event("change", {{ bubbles: true }}));
1141
  }
1142
 
1143
  function handleFile(file) {{
 
2385
  with gr.Row():
2386
 
2387
  first_frame = gr.Image(
2388
+ label="تصویر اول (اختیاری)",
2389
  type="filepath",
2390
  height=256
2391
  )
2392
 
2393
  end_frame = gr.Image(
2394
+ label="تصویر آخر (اختیاری)",
2395
  type="filepath",
2396
  height=256,
2397
  visible=False,
 
2439
 
2440
 
2441
  prompt_ui = PromptBox(
2442
+ value="این تصویر را با حرکت سینمایی و انیمیشن روان زنده کن",
2443
  elem_id="prompt_ui",
2444
  )
2445
 
 
2459
 
2460
  prompt = gr.Textbox(
2461
  label="Prompt",
2462
+ value="این تصویر را با حرکت سینمایی و انیمیشن روان زنده کن",
2463
  lines=3,
2464
  max_lines=3,
2465
+ placeholder="حرکت و انیمیشن مورد نظر خود را توصیف کنید...",
2466
  visible=False
2467
  )
2468
 
 
2472
  visible=False
2473
  )
2474
 
2475
+ with gr.Accordion("تنظیمات پیشرفته", open=False, visible=False):
2476
  seed = gr.Slider(
2477
+ label="سید (Seed)",
2478
  minimum=0,
2479
  maximum=MAX_SEED,
2480
  value=DEFAULT_SEED,
2481
  step=1
2482
  )
2483
 
2484
+ randomize_seed = gr.Checkbox(label="استفاده از سید تصادفی", value=True)
2485
 
2486
 
2487
  with gr.Column(elem_id="step-column"):
2488
+ output_video = gr.Video(label="ویدیوی ساخته شده", autoplay=True, height=512)
2489
 
2490
  with gr.Row(elem_id="controls-row"):
2491
 
 
2492
  duration_ui = CameraDropdown(
2493
  choices=["3s", "5s", "10s"],
2494
  value="5s",
2495
+ title="مدت زمان ویدیو",
2496
  elem_id="duration_ui"
2497
  )
2498
 
 
2499
  duration = gr.Slider(
2500
  label="Duration (seconds)",
2501
  minimum=1.0,
 
2525
  {"label": "9:16", "value": "9:16", "icon": ICON_9_16},
2526
  ],
2527
  value="16:9",
2528
+ title="ابعاد تصویر",
2529
  elem_id="resolution_ui"
2530
  )
2531
 
 
2536
  camera_ui = CameraDropdown(
2537
  choices=[name for name, _ in VISIBLE_RUNTIME_LORA_CHOICES],
2538
  value="No LoRA",
2539
+ title="افکت دوربین (LoRA)",
2540
  elem_id="camera_ui",
2541
  )
2542
 
 
2548
  visible=False
2549
  )
2550
 
2551
+ generate_btn = gr.Button("🤩 ساخت ویدیو", variant="primary", elem_classes="button-gradient")
2552
 
2553
 
2554
  camera_ui.change(
 
2670
  ],
2671
  ]
2672
 
 
2673
  examples_obj = create_examples(
2674
  examples=examples_list,
2675
  fn=generate_video_example,
2676
  inputs=[first_frame, prompt_ui, camera_ui, resolution_ui, radioanimated_mode, input_video, audio_input, end_frame],
2677
  outputs = [output_video],
2678
+ label="نمونه‌ها",
2679
  cache_examples=True,
2680
  visible=False
2681
  )
2682
 
2683
  preset_gallery = PresetGallery(
2684
  items=[
2685
+ {"thumb": "examples/supergirl-2.png", "label": "تصویر و صدا به ویدیو"},
2686
+ {"thumb": "examples/frame3.png", "label": "تصویر اول و آخر"},
2687
+ {"thumb": "examples/supergirl.png", "label": "تصویر به ویدیو (عروسک)"},
2688
+ {"thumb": "examples/highland.png", "label": "تصویر به ویدیو (گاو)"},
2689
+ {"thumb": "examples/wednesday.png", "label": "تصویر به ویدیو (ونزدی)"},
2690
+ {"thumb": "examples/astronaut.png", "label": "تصویر به ویدیو (فضانورد)"},
 
2691
  ],
2692
+ title="برای شروع روی یکی از نمونه‌ها کلیک کنید",
2693
  )
2694
 
2695
  def on_audio_ui_change(v):
 
2706
  api_visibility="private",
2707
  )
2708
 
 
 
 
2709
  preset_gallery.change(
2710
  fn=apply_example,
2711
  inputs=preset_gallery,
 
2723
  ],
2724
  api_visibility="private",
2725
  )
 
2726
 
2727
  if __name__ == "__main__":
2728
  demo.launch(ssr_mode=False, mcp_server=True, css=css, allowed_paths=["./examples"])