Opera8 commited on
Commit
2573dbd
·
verified ·
1 Parent(s): 2219ee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -4
app.py CHANGED
@@ -2404,17 +2404,45 @@ import requests
2404
  import time
2405
 
2406
  # JS Function to handle download request via PostMessage
 
2407
  js_download_video = """
2408
  async (video) => {
2409
  if (!video) {
2410
  alert("لطفاً ابتدا ویدیو را تولید کنید.");
2411
  return;
2412
  }
2413
- let fileUrl = typeof video === 'string' ? video : (video && (video.url || video.path));
2414
- if (fileUrl && !fileUrl.startsWith('http')) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2415
  let cleanPath = fileUrl.startsWith('/') ? fileUrl.substring(1) : fileUrl;
2416
- fileUrl = window.location.origin + (cleanPath.startsWith('file=') ? "/" + cleanPath : "/file=" + cleanPath);
 
 
 
 
 
 
2417
  }
 
2418
  if (fileUrl) {
2419
  console.log("Sending download request for:", fileUrl);
2420
  window.parent.postMessage({ type: 'DOWNLOAD_REQUEST', url: fileUrl }, '*');
@@ -2465,7 +2493,6 @@ def ui_lock_and_enhance(first_frame, prompt, mode, enhance_toggle):
2465
  """
2466
  مرحله ۱: قفل کردن UI و بررسی اینکه آیا پرامپت نیاز به بهینه‌سازی دارد یا خیر
2467
  """
2468
- # بررسی متن جدید سوییچ پرامپت
2469
  if enhance_toggle == "دستور بهینه شود (پیشفرض) ✨":
2470
  yield (
2471
  gr.Button(value="⏳ در حال بهینه سازی پرامپت (CPU)...", interactive=False),
 
2404
  import time
2405
 
2406
  # JS Function to handle download request via PostMessage
2407
+ # این بخش کاملاً بهینه‌سازی شده تا آدرس‌های فایل‌های داخلی گاردریو را با دقت استخراج کند
2408
  js_download_video = """
2409
  async (video) => {
2410
  if (!video) {
2411
  alert("لطفاً ابتدا ویدیو را تولید کنید.");
2412
  return;
2413
  }
2414
+
2415
+ let fileUrl = "";
2416
+
2417
+ // پیدا کردن لینک فایل از داخل ساختار پیچیده خروجی گاردریو نسخه 4
2418
+ if (typeof video === 'string') {
2419
+ fileUrl = video;
2420
+ } else if (video && video.video && typeof video.video.url === 'string') {
2421
+ fileUrl = video.video.url;
2422
+ } else if (video && video.video && typeof video.video.path === 'string') {
2423
+ fileUrl = video.video.path;
2424
+ } else if (video && typeof video.url === 'string') {
2425
+ fileUrl = video.url;
2426
+ } else if (video && typeof video.path === 'string') {
2427
+ fileUrl = video.path;
2428
+ }
2429
+
2430
+ if (!fileUrl) {
2431
+ alert("خطا: مسیر ویدیو یافت نشد.");
2432
+ return;
2433
+ }
2434
+
2435
+ if (fileUrl && !fileUrl.startsWith('http') && !fileUrl.startsWith('blob:')) {
2436
  let cleanPath = fileUrl.startsWith('/') ? fileUrl.substring(1) : fileUrl;
2437
+
2438
+ // اطمینان از قرار گرفتن کلمه file= برای گاردریو
2439
+ if (!cleanPath.startsWith('gradio_api/') && !cleanPath.startsWith('file=')) {
2440
+ cleanPath = 'file=' + cleanPath;
2441
+ }
2442
+
2443
+ fileUrl = window.location.origin + "/" + cleanPath;
2444
  }
2445
+
2446
  if (fileUrl) {
2447
  console.log("Sending download request for:", fileUrl);
2448
  window.parent.postMessage({ type: 'DOWNLOAD_REQUEST', url: fileUrl }, '*');
 
2493
  """
2494
  مرحله ۱: قفل کردن UI و بررسی اینکه آیا پرامپت نیاز به بهینه‌سازی دارد یا خیر
2495
  """
 
2496
  if enhance_toggle == "دستور بهینه شود (پیشفرض) ✨":
2497
  yield (
2498
  gr.Button(value="⏳ در حال بهینه سازی پرامپت (CPU)...", interactive=False),