Update templates/index.html
Browse files- templates/index.html +24 -14
templates/index.html
CHANGED
|
@@ -505,7 +505,7 @@
|
|
| 505 |
|
| 506 |
function initializeForm() {
|
| 507 |
if (videoGenerationJob) {
|
| 508 |
-
videoGenerationJob.cancel();
|
| 509 |
videoGenerationJob = null;
|
| 510 |
}
|
| 511 |
hideCriticalError();
|
|
@@ -526,9 +526,11 @@
|
|
| 526 |
}
|
| 527 |
|
| 528 |
async function translatePersianToEnglish(persianText, { timeoutMs = TRANSLATION_TIMEOUT } = {}) {
|
| 529 |
-
if (!persianText?.trim())
|
|
|
|
|
|
|
|
|
|
| 530 |
|
| 531 |
-
if (aiLoader.style.display !== 'none') setAiLoaderText("در حال ترجمه دستور شما...");
|
| 532 |
const translator = await Client.connect(TRANSLATOR_SPACE_NAME);
|
| 533 |
|
| 534 |
const predictPromise = translator.predict(FN_INDEX_TRANSLATE_SPEAK, [
|
|
@@ -538,13 +540,13 @@
|
|
| 538 |
]);
|
| 539 |
|
| 540 |
const timeoutPromise = new Promise((_, reject) =>
|
| 541 |
-
setTimeout(() => reject(new Error("
|
| 542 |
);
|
| 543 |
|
| 544 |
const resp = await Promise.race([predictPromise, timeoutPromise]);
|
| 545 |
|
| 546 |
const english = resp?.data?.[0];
|
| 547 |
-
if (
|
| 548 |
return english;
|
| 549 |
}
|
| 550 |
|
|
@@ -645,15 +647,27 @@
|
|
| 645 |
addStatusMessage('در حال آماده سازی...', 'info');
|
| 646 |
|
| 647 |
lastAttemptedVideoPayload = { persianPrompt, imageSourceFile: imageFile, duration };
|
| 648 |
-
|
| 649 |
-
|
|
|
|
| 650 |
try {
|
|
|
|
| 651 |
const englishPrompt = await translatePersianToEnglish(persianPrompt);
|
| 652 |
-
|
| 653 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
} catch (e) {
|
|
|
|
| 655 |
addStatusMessage('ترجمه ناموفق بود. با متن فارسی ادامه میدهیم.', 'error');
|
|
|
|
| 656 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 657 |
|
| 658 |
try {
|
| 659 |
const client = await Client.connect(VIDEO_SPACE_NAME);
|
|
@@ -669,7 +683,6 @@
|
|
| 669 |
true // randomize_seed
|
| 670 |
]);
|
| 671 |
|
| 672 |
-
// --- START: NEW CORRECT WAY TO HANDLE STATUS ---
|
| 673 |
for await (const status of videoGenerationJob) {
|
| 674 |
console.log(status); // For debugging
|
| 675 |
switch (status.type) {
|
|
@@ -685,11 +698,9 @@
|
|
| 685 |
let progressText = "در حال پردازش...";
|
| 686 |
|
| 687 |
if (progressItem.desc === "ZeroGPU init") {
|
| 688 |
-
// Phase 1: Preparation (estimated 20% of total process)
|
| 689 |
percentage = (progressItem.index / progressItem.length) * 20;
|
| 690 |
progressText = `آمادهسازی: ${Math.round(percentage)}%`;
|
| 691 |
} else if (progressItem.unit === "steps" && progressItem.desc === null) {
|
| 692 |
-
// Phase 2: Video Generation (estimated 80% of total process)
|
| 693 |
percentage = 20 + (progressItem.index / progressItem.length) * 80;
|
| 694 |
progressText = `ساخت ویدیو: ${Math.round(percentage)}%`;
|
| 695 |
}
|
|
@@ -712,10 +723,9 @@
|
|
| 712 |
showCriticalError(errorMessage, isGpuQuotaError);
|
| 713 |
}
|
| 714 |
videoGenerationJob = null; // Clear the job after completion
|
| 715 |
-
return;
|
| 716 |
}
|
| 717 |
}
|
| 718 |
-
// --- END: NEW CORRECT WAY TO HANDLE STATUS ---
|
| 719 |
|
| 720 |
} catch (errorCaught) {
|
| 721 |
showCriticalError(`خطای اولیه: ${errorCaught.message}`);
|
|
|
|
| 505 |
|
| 506 |
function initializeForm() {
|
| 507 |
if (videoGenerationJob) {
|
| 508 |
+
try { videoGenerationJob.cancel(); } catch(e) { console.warn("Could not cancel previous job:", e); }
|
| 509 |
videoGenerationJob = null;
|
| 510 |
}
|
| 511 |
hideCriticalError();
|
|
|
|
| 526 |
}
|
| 527 |
|
| 528 |
async function translatePersianToEnglish(persianText, { timeoutMs = TRANSLATION_TIMEOUT } = {}) {
|
| 529 |
+
if (!persianText?.trim()) {
|
| 530 |
+
// اگر متن خالی باشد، یک پرامیس موفق با یک رشته خالی برمیگردانیم تا فرآیند متوقف نشود
|
| 531 |
+
return Promise.resolve("");
|
| 532 |
+
}
|
| 533 |
|
|
|
|
| 534 |
const translator = await Client.connect(TRANSLATOR_SPACE_NAME);
|
| 535 |
|
| 536 |
const predictPromise = translator.predict(FN_INDEX_TRANSLATE_SPEAK, [
|
|
|
|
| 540 |
]);
|
| 541 |
|
| 542 |
const timeoutPromise = new Promise((_, reject) =>
|
| 543 |
+
setTimeout(() => reject(new Error("Translation request timed out.")), timeoutMs)
|
| 544 |
);
|
| 545 |
|
| 546 |
const resp = await Promise.race([predictPromise, timeoutPromise]);
|
| 547 |
|
| 548 |
const english = resp?.data?.[0];
|
| 549 |
+
if (typeof english !== 'string') throw new Error("Invalid translation response.");
|
| 550 |
return english;
|
| 551 |
}
|
| 552 |
|
|
|
|
| 647 |
addStatusMessage('در حال آماده سازی...', 'info');
|
| 648 |
|
| 649 |
lastAttemptedVideoPayload = { persianPrompt, imageSourceFile: imageFile, duration };
|
| 650 |
+
|
| 651 |
+
// --- START: ROBUST TRANSLATION BLOCK ---
|
| 652 |
+
let promptForVideo = persianPrompt; // Default to Persian
|
| 653 |
try {
|
| 654 |
+
setAiLoaderText("در حال ترجمه دستور شما...");
|
| 655 |
const englishPrompt = await translatePersianToEnglish(persianPrompt);
|
| 656 |
+
if(englishPrompt){
|
| 657 |
+
addStatusMessage(`ترجمه: ${englishPrompt}`, 'info');
|
| 658 |
+
promptForVideo = englishPrompt;
|
| 659 |
+
} else {
|
| 660 |
+
addStatusMessage('دستور ساخت خالی بود، از متن فارسی استفاده میشود.', 'info');
|
| 661 |
+
}
|
| 662 |
} catch (e) {
|
| 663 |
+
console.warn("Translation failed or timed out:", e.message);
|
| 664 |
addStatusMessage('ترجمه ناموفق بود. با متن فارسی ادامه میدهیم.', 'error');
|
| 665 |
+
// promptForVideo is already set to persianPrompt, so we just continue.
|
| 666 |
}
|
| 667 |
+
// --- END: ROBUST TRANSLATION BLOCK ---
|
| 668 |
+
|
| 669 |
+
// **CRITICAL FIX**: Update UI to show progress AFTER translation attempt, regardless of outcome.
|
| 670 |
+
setAiLoaderText("اتصال به سرور ویدیو...");
|
| 671 |
|
| 672 |
try {
|
| 673 |
const client = await Client.connect(VIDEO_SPACE_NAME);
|
|
|
|
| 683 |
true // randomize_seed
|
| 684 |
]);
|
| 685 |
|
|
|
|
| 686 |
for await (const status of videoGenerationJob) {
|
| 687 |
console.log(status); // For debugging
|
| 688 |
switch (status.type) {
|
|
|
|
| 698 |
let progressText = "در حال پردازش...";
|
| 699 |
|
| 700 |
if (progressItem.desc === "ZeroGPU init") {
|
|
|
|
| 701 |
percentage = (progressItem.index / progressItem.length) * 20;
|
| 702 |
progressText = `آمادهسازی: ${Math.round(percentage)}%`;
|
| 703 |
} else if (progressItem.unit === "steps" && progressItem.desc === null) {
|
|
|
|
| 704 |
percentage = 20 + (progressItem.index / progressItem.length) * 80;
|
| 705 |
progressText = `ساخت ویدیو: ${Math.round(percentage)}%`;
|
| 706 |
}
|
|
|
|
| 723 |
showCriticalError(errorMessage, isGpuQuotaError);
|
| 724 |
}
|
| 725 |
videoGenerationJob = null; // Clear the job after completion
|
| 726 |
+
return;
|
| 727 |
}
|
| 728 |
}
|
|
|
|
| 729 |
|
| 730 |
} catch (errorCaught) {
|
| 731 |
showCriticalError(`خطای اولیه: ${errorCaught.message}`);
|