Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,74 +10,6 @@ import json
|
|
10 |
|
11 |
os.environ['HF_HOME'] = os.path.abspath(os.path.realpath(os.path.join(os.path.dirname(__file__), './hf_download')))
|
12 |
|
13 |
-
# 日英両言語の翻訳辞書を追加
|
14 |
-
translations = {
|
15 |
-
"en": {
|
16 |
-
"title": "FramePack_rotate_landscape - Rotating Landscape Video Generator",
|
17 |
-
"upload_image": "Upload Image",
|
18 |
-
"prompt": "Prompt",
|
19 |
-
"quick_prompts": "Quick Prompts",
|
20 |
-
"start_generation": "Generate",
|
21 |
-
"stop_generation": "Stop",
|
22 |
-
"use_teacache": "Use TeaCache",
|
23 |
-
"teacache_info": "Faster speed, but may result in slightly worse finger and hand generation.",
|
24 |
-
"negative_prompt": "Negative Prompt",
|
25 |
-
"seed": "Seed",
|
26 |
-
"video_length": "Video Length (max 5 seconds)",
|
27 |
-
"next_latents": "Next Latents",
|
28 |
-
"generated_video": "Generated Video",
|
29 |
-
"sampling_note": "Note: Due to reversed sampling, ending actions will be generated before starting actions. If the starting action is not in the video, please wait, it will be generated later.",
|
30 |
-
"error_message": "Error",
|
31 |
-
"processing_error": "Processing error",
|
32 |
-
"network_error": "Network connection is unstable, model download timed out. Please try again later.",
|
33 |
-
"memory_error": "GPU memory insufficient, please try increasing GPU memory preservation value or reduce video length.",
|
34 |
-
"model_error": "Failed to load model, possibly due to network issues or high server load. Please try again later.",
|
35 |
-
"partial_video": "Processing error, but partial video has been generated",
|
36 |
-
"processing_interrupt": "Processing was interrupted, but partial video has been generated"
|
37 |
-
},
|
38 |
-
"ja": {
|
39 |
-
"title": "FramePack_rotate_landscape - 風景回転動画ジェネレーター",
|
40 |
-
"upload_image": "画像をアップロード",
|
41 |
-
"prompt": "プロンプト",
|
42 |
-
"quick_prompts": "クイックプロンプト一覧",
|
43 |
-
"start_generation": "生成開始",
|
44 |
-
"stop_generation": "停止",
|
45 |
-
"use_teacache": "TeaCacheを使用",
|
46 |
-
"teacache_info": "処理速度が速くなりますが、指や手の生成品質が若干低下する可能性があります。",
|
47 |
-
"negative_prompt": "ネガティブプロンプト",
|
48 |
-
"seed": "シード値",
|
49 |
-
"video_length": "動画の長さ(最大5秒)",
|
50 |
-
"gpu_memory": "GPU推論保存メモリ(GB)(値が大きいほど処理が遅くなります)",
|
51 |
-
"gpu_memory_info": "OOMエラーが発生した場合は、この値を大きくしてください。値が大きいほど処理が遅くなります。",
|
52 |
-
"next_latents": "次の潜在変数",
|
53 |
-
"generated_video": "生成された動画",
|
54 |
-
"sampling_note": "注意:逆順サンプリングのため、終了動作が開始動作より先に生成されます。開始動作が動画に表示されていない場合は、しばらくお待ちください。後で生成されます。",
|
55 |
-
"error_message": "エラーメッセージ",
|
56 |
-
"processing_error": "処理中にエラーが発生しました",
|
57 |
-
"network_error": "ネットワーク接続が不安定です。モデルのダウンロードがタイムアウトしました。後ほど再試行してください。",
|
58 |
-
"memory_error": "GPUメモリが不足しています。GPU推論保存メモリの値を大きくするか、動画の長さを短くしてください。",
|
59 |
-
"model_error": "モデルの読み込みに失敗しました。ネットワークの問題やサーバー負荷が高い可能性があります。後ほど再試行してください。",
|
60 |
-
"partial_video": "処理中にエラーが発生しましたが、部分的な動画は生成されています",
|
61 |
-
"processing_interrupt": "処理が中断されましたが、部分的な動画は生成されています"
|
62 |
-
}
|
63 |
-
}
|
64 |
-
|
65 |
-
# 言語切り替え機能
|
66 |
-
def get_translation(key, lang="en"):
|
67 |
-
if lang in translations and key in translations[lang]:
|
68 |
-
return translations[lang][key]
|
69 |
-
# デフォルトで英語を返す
|
70 |
-
return translations["en"].get(key, key)
|
71 |
-
|
72 |
-
# デフォルト言語設定
|
73 |
-
current_language = "en"
|
74 |
-
|
75 |
-
# 言語切り替え関数
|
76 |
-
def switch_language():
|
77 |
-
global current_language
|
78 |
-
current_language = "ja" if current_language == "en" else "en"
|
79 |
-
return current_language
|
80 |
-
|
81 |
import gradio as gr
|
82 |
import torch
|
83 |
import traceback
|
@@ -1000,8 +932,7 @@ if IN_HF_SPACE and 'spaces' in globals():
|
|
1000 |
|
1001 |
# エラーメッセージがある場合、わかりやすいエラー表示を作成
|
1002 |
if error_message:
|
1003 |
-
|
1004 |
-
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1005 |
else:
|
1006 |
# 成功時にエラー表示をしない
|
1007 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
@@ -1015,11 +946,9 @@ if IN_HF_SPACE and 'spaces' in globals():
|
|
1015 |
|
1016 |
# 部分的に生成された動画がある場合、それを返す
|
1017 |
if prev_output_filename:
|
1018 |
-
|
1019 |
-
yield prev_output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1020 |
else:
|
1021 |
-
|
1022 |
-
yield None, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1023 |
break
|
1024 |
|
1025 |
except Exception as e:
|
@@ -1027,8 +956,7 @@ if IN_HF_SPACE and 'spaces' in globals():
|
|
1027 |
traceback.print_exc()
|
1028 |
error_msg = str(e)
|
1029 |
|
1030 |
-
|
1031 |
-
yield None, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1032 |
|
1033 |
process = process_with_gpu
|
1034 |
else:
|
@@ -1084,8 +1012,7 @@ else:
|
|
1084 |
|
1085 |
# エラーメッセージがある場合、わかりやすいエラー表示を作成
|
1086 |
if error_message:
|
1087 |
-
|
1088 |
-
yield output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1089 |
else:
|
1090 |
# 成功時にエラー表示をしない
|
1091 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
@@ -1099,11 +1026,9 @@ else:
|
|
1099 |
|
1100 |
# 部分的に生成された動画がある場合、それを返す
|
1101 |
if prev_output_filename:
|
1102 |
-
|
1103 |
-
yield prev_output_filename, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1104 |
else:
|
1105 |
-
|
1106 |
-
yield None, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1107 |
break
|
1108 |
|
1109 |
except Exception as e:
|
@@ -1111,8 +1036,7 @@ else:
|
|
1111 |
traceback.print_exc()
|
1112 |
error_msg = str(e)
|
1113 |
|
1114 |
-
|
1115 |
-
yield None, gr.update(visible=False), gr.update(), error_html, gr.update(interactive=True), gr.update(interactive=False)
|
1116 |
|
1117 |
|
1118 |
def end_process():
|
@@ -1163,17 +1087,6 @@ def make_custom_css():
|
|
1163 |
margin: 0 auto;
|
1164 |
}
|
1165 |
|
1166 |
-
/* 言語切り替えボタンのスタイル - CSSは自動生成されるので不要です */
|
1167 |
-
|
1168 |
-
/* 言語切り替え用のクラス */
|
1169 |
-
body.lang-ja .lang-en,
|
1170 |
-
body.lang-en .lang-ja {
|
1171 |
-
display: none !important;
|
1172 |
-
}
|
1173 |
-
|
1174 |
-
body.lang-initialized .dual-lang-text {
|
1175 |
-
display: none !important;
|
1176 |
-
}
|
1177 |
|
1178 |
/* ページタイトルのスタイル */
|
1179 |
h1 {
|
@@ -1316,288 +1229,6 @@ def make_custom_css():
|
|
1316 |
css = make_custom_css()
|
1317 |
block = gr.Blocks(css=css).queue()
|
1318 |
with block:
|
1319 |
-
# 言語切り替え機能を追加
|
1320 |
-
gr.HTML("""
|
1321 |
-
<div id="app-container">
|
1322 |
-
<script>
|
1323 |
-
// 言語切り替え機能のJavaScriptコード
|
1324 |
-
document.addEventListener('DOMContentLoaded', function() {
|
1325 |
-
console.log('DOM読み込み完了、言語切り替え初期化処理を開始します');
|
1326 |
-
|
1327 |
-
// グローバル変数、現在の言語を保存(デフォルトは日本語)
|
1328 |
-
window.currentLang = "ja";
|
1329 |
-
|
1330 |
-
// CSSを動的に追加
|
1331 |
-
const styleElement = document.createElement('style');
|
1332 |
-
styleElement.textContent = `
|
1333 |
-
/* 言語切り替え用のスタイル */
|
1334 |
-
body.lang-ja .lang-en,
|
1335 |
-
body.lang-en .lang-ja {
|
1336 |
-
display: none !important;
|
1337 |
-
}
|
1338 |
-
|
1339 |
-
/* スラッシュ付きのデュアル言語表示を非表示 */
|
1340 |
-
body.lang-initialized .dual-lang-text {
|
1341 |
-
display: none !important;
|
1342 |
-
}
|
1343 |
-
|
1344 |
-
/* 言語固有表示用クラス */
|
1345 |
-
.lang-ja, .lang-en {
|
1346 |
-
display: block;
|
1347 |
-
}
|
1348 |
-
`;
|
1349 |
-
document.head.appendChild(styleElement);
|
1350 |
-
|
1351 |
-
// 翻訳データ
|
1352 |
-
const translations = {
|
1353 |
-
"en": {
|
1354 |
-
"title": "FramePack_rotate_landscape - Rotating Landscape Video Generator",
|
1355 |
-
"upload_image": "Upload Image",
|
1356 |
-
"prompt": "Prompt",
|
1357 |
-
"quick_prompts": "Quick Prompts",
|
1358 |
-
"start_generation": "Generate",
|
1359 |
-
"stop_generation": "Stop",
|
1360 |
-
"use_teacache": "Use TeaCache",
|
1361 |
-
"teacache_info": "Faster speed, but may result in slightly worse finger and hand generation.",
|
1362 |
-
"negative_prompt": "Negative Prompt",
|
1363 |
-
"seed": "Seed",
|
1364 |
-
"video_length": "Video Length (max 1 seconds)",
|
1365 |
-
"next_latents": "Next Latents",
|
1366 |
-
"generated_video": "Generated Video",
|
1367 |
-
"preview": "Preview",
|
1368 |
-
"sampling_note": "Note: Due to reversed sampling, ending actions will be generated before starting actions. If the starting action is not in the video, please wait, it will be generated later.",
|
1369 |
-
"error_message": "Error",
|
1370 |
-
"processing_error": "Processing error",
|
1371 |
-
"network_error": "Network connection is unstable, model download timed out. Please try again later.",
|
1372 |
-
"memory_error": "GPU memory insufficient, please try increasing GPU memory preservation value or reduce video length.",
|
1373 |
-
"model_error": "Failed to load model, possibly due to network issues or high server load. Please try again later.",
|
1374 |
-
"partial_video": "Processing error, but partial video has been generated",
|
1375 |
-
"processing_interrupt": "Processing was interrupted, but partial video has been generated"
|
1376 |
-
},
|
1377 |
-
"ja": {
|
1378 |
-
"title": "FramePack_rotate_landscape - 風景回転動画ジェネレーター",
|
1379 |
-
"upload_image": "画像をアップロード",
|
1380 |
-
"prompt": "プロンプト",
|
1381 |
-
"quick_prompts": "クイックプロンプト一覧",
|
1382 |
-
"start_generation": "生成開始",
|
1383 |
-
"stop_generation": "停止",
|
1384 |
-
"use_teacache": "TeaCacheを使用",
|
1385 |
-
"teacache_info": "処理速度が速くなりますが、指や手の生成品質が若干低下する可能性があります。",
|
1386 |
-
"negative_prompt": "ネガティブプロンプト",
|
1387 |
-
"seed": "シード値",
|
1388 |
-
"video_length": "動画の長さ(最大1秒)",
|
1389 |
-
"next_latents": "次の潜在変数",
|
1390 |
-
"generated_video": "生成された動画",
|
1391 |
-
"preview": "プレビュー",
|
1392 |
-
"sampling_note": "注意:逆順サンプリングのため、終了動作が開始動作より先に生成されます。開始動作が動画に表示されていない場合は、しばらくお待ちください。後で生成されます。",
|
1393 |
-
"error_message": "エラーメッセージ",
|
1394 |
-
"processing_error": "処理中にエラーが発生しました",
|
1395 |
-
"network_error": "ネットワーク接続が不安定です。モデルのダウンロードがタイムアウトしました。後ほど再試行してください。",
|
1396 |
-
"memory_error": "GPUメモリが不足しています。GPU推論保存メモリの値を大きくするか、動画の長さを短くしてください。",
|
1397 |
-
"model_error": "モデルの読み込みに失敗しました。ネットワークの問題やサーバー負荷が高い可能性があります。後ほど再試行してください。",
|
1398 |
-
"partial_video": "処理中にエラーが発生しましたが、部分的な動画は生成されています",
|
1399 |
-
"processing_interrupt": "処理が中断されましたが、部分的な動画は生成されています"
|
1400 |
-
}
|
1401 |
-
};
|
1402 |
-
|
1403 |
-
// 言語切り替えボタンを作成
|
1404 |
-
const langToggleBtn = document.createElement('button');
|
1405 |
-
langToggleBtn.id = 'language-toggle';
|
1406 |
-
langToggleBtn.textContent = 'English / 英語';
|
1407 |
-
langToggleBtn.onclick = toggleLanguage;
|
1408 |
-
langToggleBtn.style.position = 'fixed';
|
1409 |
-
langToggleBtn.style.top = '10px';
|
1410 |
-
langToggleBtn.style.right = '10px';
|
1411 |
-
langToggleBtn.style.zIndex = '1000';
|
1412 |
-
langToggleBtn.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
|
1413 |
-
langToggleBtn.style.color = 'white';
|
1414 |
-
langToggleBtn.style.border = 'none';
|
1415 |
-
langToggleBtn.style.borderRadius = '4px';
|
1416 |
-
langToggleBtn.style.padding = '5px 10px';
|
1417 |
-
langToggleBtn.style.cursor = 'pointer';
|
1418 |
-
langToggleBtn.style.fontSize = '14px';
|
1419 |
-
document.body.appendChild(langToggleBtn);
|
1420 |
-
|
1421 |
-
// 言語切り替え関数
|
1422 |
-
window.toggleLanguage = function() {
|
1423 |
-
const newLang = window.currentLang === "en" ? "ja" : "en";
|
1424 |
-
window.currentLang = newLang;
|
1425 |
-
|
1426 |
-
// body要素に言語クラスを設定
|
1427 |
-
document.body.classList.remove('lang-ja', 'lang-en');
|
1428 |
-
document.body.classList.add(`lang-${newLang}`);
|
1429 |
-
|
1430 |
-
// ボタンのテキストを更新
|
1431 |
-
langToggleBtn.textContent = newLang === "en" ? '日本語 / Japanese' : 'English / 英語';
|
1432 |
-
|
1433 |
-
applyTranslations();
|
1434 |
-
console.log(`言語を ${newLang} に切り替えました`);
|
1435 |
-
}
|
1436 |
-
|
1437 |
-
// 翻訳を適用する関数
|
1438 |
-
function applyTranslations() {
|
1439 |
-
// 通常のラベル要素の処理
|
1440 |
-
const allLabels = document.querySelectorAll('label, span.label-wrap span, div.wrap span, h1, .gradio-button, .note');
|
1441 |
-
|
1442 |
-
allLabels.forEach(label => {
|
1443 |
-
const text = label.textContent.trim();
|
1444 |
-
|
1445 |
-
// スラッシュ付きのテキストなら分割して処理
|
1446 |
-
if (text.includes('/')) {
|
1447 |
-
// 初回のみ言語ごとの要素を作成する
|
1448 |
-
if (!label.classList.contains('processed-dual-lang')) {
|
1449 |
-
processSlashSeparatedText(label, text);
|
1450 |
-
label.classList.add('processed-dual-lang');
|
1451 |
-
label.classList.add('dual-lang-text');
|
1452 |
-
}
|
1453 |
-
} else {
|
1454 |
-
// 単一言語のテキストの場合、キーを検索して翻訳
|
1455 |
-
const key = getKeyFromText(text);
|
1456 |
-
if (key && translations[window.currentLang][key]) {
|
1457 |
-
label.textContent = translations[window.currentLang][key];
|
1458 |
-
}
|
1459 |
-
}
|
1460 |
-
});
|
1461 |
-
|
1462 |
-
// ボタン要素の特別処理
|
1463 |
-
const startBtn = document.querySelector('#start-button');
|
1464 |
-
if (startBtn) {
|
1465 |
-
startBtn.textContent = translations[window.currentLang].start_generation;
|
1466 |
-
}
|
1467 |
-
|
1468 |
-
const stopBtn = document.querySelector('#stop-button');
|
1469 |
-
if (stopBtn) {
|
1470 |
-
stopBtn.textContent = translations[window.currentLang].stop_generation;
|
1471 |
-
}
|
1472 |
-
|
1473 |
-
// チェックボックスの情報テキスト
|
1474 |
-
const infoTexts = document.querySelectorAll('.wrap p, .checkbox-container .wrap p');
|
1475 |
-
infoTexts.forEach(info => {
|
1476 |
-
const text = info.textContent.trim();
|
1477 |
-
if (text.includes('/')) {
|
1478 |
-
if (!info.classList.contains('processed-dual-lang')) {
|
1479 |
-
processSlashSeparatedText(info, text);
|
1480 |
-
info.classList.add('processed-dual-lang');
|
1481 |
-
info.classList.add('dual-lang-text');
|
1482 |
-
}
|
1483 |
-
} else {
|
1484 |
-
// TeaCacheのinfo文字列を特別に検出
|
1485 |
-
if (text.includes('指や手の生成品質') || text.includes('finger and hand generation')) {
|
1486 |
-
info.textContent = translations[window.currentLang].teacache_info;
|
1487 |
-
}
|
1488 |
-
}
|
1489 |
-
});
|
1490 |
-
|
1491 |
-
// エラーメッセージ処理
|
1492 |
-
document.querySelectorAll('[data-lang]').forEach(el => {
|
1493 |
-
el.style.display = el.getAttribute('data-lang') === window.currentLang ? 'block' : 'none';
|
1494 |
-
});
|
1495 |
-
}
|
1496 |
-
|
1497 |
-
// スラッシュ区切りテキストを処理して、言語ごとの要素を作成
|
1498 |
-
function processSlashSeparatedText(element, text) {
|
1499 |
-
// テキストをスラッシュで分割
|
1500 |
-
const parts = text.split('/');
|
1501 |
-
let jaText = parts[0].trim();
|
1502 |
-
let enText = parts.length > 1 ? parts[1].trim() : '';
|
1503 |
-
|
1504 |
-
// 親要素を取得
|
1505 |
-
const parent = element.parentNode;
|
1506 |
-
|
1507 |
-
// 言語ごとの要素を作成
|
1508 |
-
const jaElement = document.createElement('span');
|
1509 |
-
jaElement.textContent = jaText;
|
1510 |
-
jaElement.classList.add('lang-ja');
|
1511 |
-
|
1512 |
-
const enElement = document.createElement('span');
|
1513 |
-
enElement.textContent = enText;
|
1514 |
-
enElement.classList.add('lang-en');
|
1515 |
-
|
1516 |
-
// オリジナル要素の直後に挿入
|
1517 |
-
insertAfter(jaElement, element);
|
1518 |
-
insertAfter(enElement, jaElement);
|
1519 |
-
}
|
1520 |
-
|
1521 |
-
// 要素の後に新しい要素を挿入するヘルパー関数
|
1522 |
-
function insertAfter(newElement, referenceElement) {
|
1523 |
-
referenceElement.parentNode.insertBefore(newElement, referenceElement.nextSibling);
|
1524 |
-
}
|
1525 |
-
|
1526 |
-
// テキストからキーを取得する関数
|
1527 |
-
function getKeyFromText(text) {
|
1528 |
-
if (!text) return null;
|
1529 |
-
|
1530 |
-
// 複合テキスト(「日本語 / English」形式)を処理
|
1531 |
-
if (text.includes('/')) {
|
1532 |
-
const parts = text.split('/');
|
1533 |
-
const jaText = parts[0].trim();
|
1534 |
-
const enText = parts.length > 1 ? parts[1].trim() : '';
|
1535 |
-
|
1536 |
-
// 日本語テキストからキーを検索
|
1537 |
-
for (const [key, value] of Object.entries(translations.ja)) {
|
1538 |
-
if (value === jaText) return key;
|
1539 |
-
}
|
1540 |
-
|
1541 |
-
// 英語テキストからキーを検索
|
1542 |
-
for (const [key, value] of Object.entries(translations.en)) {
|
1543 |
-
if (value === enText) return key;
|
1544 |
-
}
|
1545 |
-
}
|
1546 |
-
|
1547 |
-
// 単一言語テキストからキーを検索
|
1548 |
-
for (const [key, value] of Object.entries(translations.ja)) {
|
1549 |
-
if (value === text) return key;
|
1550 |
-
}
|
1551 |
-
|
1552 |
-
for (const [key, value] of Object.entries(translations.en)) {
|
1553 |
-
if (value === text) return key;
|
1554 |
-
}
|
1555 |
-
|
1556 |
-
return null;
|
1557 |
-
}
|
1558 |
-
|
1559 |
-
// Gradioの要素が完全に読���込まれるまで少し待ってから実行
|
1560 |
-
function initializeLanguage() {
|
1561 |
-
console.log('言語初期化処理を実行します');
|
1562 |
-
|
1563 |
-
// デフォルト言語を設定
|
1564 |
-
document.body.classList.add(`lang-${window.currentLang}`);
|
1565 |
-
document.body.classList.add('lang-initialized');
|
1566 |
-
|
1567 |
-
// 翻訳を適用
|
1568 |
-
applyTranslations();
|
1569 |
-
}
|
1570 |
-
|
1571 |
-
// 初期化を3回試行(Gradioの読み込みタイミングに合わせるため)
|
1572 |
-
setTimeout(initializeLanguage, 1000);
|
1573 |
-
setTimeout(initializeLanguage, 2000);
|
1574 |
-
setTimeout(initializeLanguage, 3000);
|
1575 |
-
|
1576 |
-
// MutationObserverでDOM変更を監視し、新しい要素にも翻訳を適用
|
1577 |
-
const observer = new MutationObserver(function(mutations) {
|
1578 |
-
let shouldUpdate = false;
|
1579 |
-
|
1580 |
-
mutations.forEach(function(mutation) {
|
1581 |
-
if (mutation.addedNodes.length) {
|
1582 |
-
shouldUpdate = true;
|
1583 |
-
}
|
1584 |
-
});
|
1585 |
-
|
1586 |
-
if (shouldUpdate) {
|
1587 |
-
setTimeout(applyTranslations, 100);
|
1588 |
-
}
|
1589 |
-
});
|
1590 |
-
|
1591 |
-
// 監視設定
|
1592 |
-
observer.observe(document.body, {
|
1593 |
-
childList: true,
|
1594 |
-
subtree: true
|
1595 |
-
});
|
1596 |
-
});
|
1597 |
-
</script>
|
1598 |
-
</div>
|
1599 |
-
""")
|
1600 |
-
|
1601 |
# タイトルにはJavaScriptで切り替えられるようにdata-i18n属性を使用
|
1602 |
gr.HTML("<h1 data-i18n='title'>FramePack - 画像から動画生成</h1>")
|
1603 |
|
@@ -1713,67 +1344,3 @@ with block:
|
|
1713 |
|
1714 |
block.launch()
|
1715 |
|
1716 |
-
# わかりやすいエラー表示HTMLを作成
|
1717 |
-
def create_error_html(error_msg, is_timeout=False):
|
1718 |
-
"""二言語のエラーメッセージHTMLを作成"""
|
1719 |
-
# より親切な日英両言語のエラーメッセージを提供
|
1720 |
-
en_msg = ""
|
1721 |
-
ja_msg = ""
|
1722 |
-
|
1723 |
-
if is_timeout:
|
1724 |
-
en_msg = "Processing timed out, but partial video may have been generated" if "部分的な動画" in error_msg else f"Processing timed out: {error_msg}"
|
1725 |
-
ja_msg = "処理がタイムアウトしましたが、部分的な動画は生成されている可能性があります" if "部分的な動画" in error_msg else f"処理がタイムアウトしました: {error_msg}"
|
1726 |
-
elif "モデル読み込み失敗" in error_msg:
|
1727 |
-
en_msg = "Failed to load models. The Space may be experiencing high traffic or GPU issues."
|
1728 |
-
ja_msg = "モデルの読み込みに失敗しました。Spaceの利用が集中しているか、GPU関連の問題が発生している可能性があります。"
|
1729 |
-
elif "GPU" in error_msg or "CUDA" in error_msg or "メモリ" in error_msg or "memory" in error_msg:
|
1730 |
-
en_msg = "GPU memory insufficient or GPU error. Try increasing GPU memory preservation value or reduce video length."
|
1731 |
-
ja_msg = "GPUメモリが不足しているかGPUエラーが発生しています。GPU推論保存メモリの値を大きくするか、動画の長さを短くしてください。"
|
1732 |
-
elif "サンプリング中にエラー" in error_msg:
|
1733 |
-
if "部分" in error_msg:
|
1734 |
-
en_msg = "Error during sampling process, but partial video has been generated."
|
1735 |
-
ja_msg = "サンプリング中にエラーが発生しましたが、部分的な動画は生成されています。"
|
1736 |
-
else:
|
1737 |
-
en_msg = "Error during sampling process. Unable to generate video."
|
1738 |
-
ja_msg = "サンプリング中にエラーが発生し、動画を生成できませんでした。"
|
1739 |
-
elif "モデルダウンロードタイムアウト" in error_msg or "ネットワーク接続不安定" in error_msg or "ReadTimeoutError" in error_msg or "ConnectionError" in error_msg:
|
1740 |
-
en_msg = "Network connection is unstable, model download timed out. Please try again later."
|
1741 |
-
ja_msg = "ネットワーク接続が不安定で、モデルのダウンロードがタイムアウトしました。後ほど再試行してください。"
|
1742 |
-
elif "VAE" in error_msg or "デコード" in error_msg or "decode" in error_msg:
|
1743 |
-
en_msg = "Error during video decoding or saving process. Try again with a different seed."
|
1744 |
-
ja_msg = "動画のデコードまたは保存中にエラーが発生しました。別のシード値で再試行してください。"
|
1745 |
-
else:
|
1746 |
-
en_msg = f"Processing error: {error_msg}"
|
1747 |
-
ja_msg = f"処理中にエラーが発生しました: {error_msg}"
|
1748 |
-
|
1749 |
-
# 二言語エラーメッセージHTML - 便利なアイコンを追加し、CSSスタイルが適用されることを確認
|
1750 |
-
return f"""
|
1751 |
-
<div class="error-message" id="custom-error-container">
|
1752 |
-
<div class="error-msg-en" data-lang="en">
|
1753 |
-
<span class="error-icon">⚠️</span> {en_msg}
|
1754 |
-
</div>
|
1755 |
-
<div class="error-msg-ja" data-lang="ja">
|
1756 |
-
<span class="error-icon">⚠️</span> {ja_msg}
|
1757 |
-
</div>
|
1758 |
-
</div>
|
1759 |
-
<script>
|
1760 |
-
// 現在の言語に基づいて適切なエラーメッセージを表示
|
1761 |
-
(function() {{
|
1762 |
-
const errorContainer = document.getElementById('custom-error-container');
|
1763 |
-
if (errorContainer) {{
|
1764 |
-
const currentLang = window.currentLang || 'ja'; // デフォルトは日本語
|
1765 |
-
const errMsgs = errorContainer.querySelectorAll('[data-lang]');
|
1766 |
-
errMsgs.forEach(msg => {{
|
1767 |
-
msg.style.display = msg.getAttribute('data-lang') === currentLang ? 'block' : 'none';
|
1768 |
-
}});
|
1769 |
-
|
1770 |
-
// GradioのデフォルトエラーUIが表示されないことを確認
|
1771 |
-
const defaultErrorElements = document.querySelectorAll('.error');
|
1772 |
-
defaultErrorElements.forEach(el => {{
|
1773 |
-
el.style.display = 'none';
|
1774 |
-
}});
|
1775 |
-
}}
|
1776 |
-
}})();
|
1777 |
-
</script>
|
1778 |
-
"""
|
1779 |
-
|
|
|
10 |
|
11 |
os.environ['HF_HOME'] = os.path.abspath(os.path.realpath(os.path.join(os.path.dirname(__file__), './hf_download')))
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
import gradio as gr
|
14 |
import torch
|
15 |
import traceback
|
|
|
932 |
|
933 |
# エラーメッセージがある場合、わかりやすいエラー表示を作成
|
934 |
if error_message:
|
935 |
+
yield output_filename, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
936 |
else:
|
937 |
# 成功時にエラー表示をしない
|
938 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
|
|
946 |
|
947 |
# 部分的に生成された動画がある場合、それを返す
|
948 |
if prev_output_filename:
|
949 |
+
yield prev_output_filename, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
950 |
else:
|
951 |
+
yield None, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
952 |
break
|
953 |
|
954 |
except Exception as e:
|
|
|
956 |
traceback.print_exc()
|
957 |
error_msg = str(e)
|
958 |
|
959 |
+
yield None, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
960 |
|
961 |
process = process_with_gpu
|
962 |
else:
|
|
|
1012 |
|
1013 |
# エラーメッセージがある場合、わかりやすいエラー表示を作成
|
1014 |
if error_message:
|
1015 |
+
yield output_filename, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
1016 |
else:
|
1017 |
# 成功時にエラー表示をしない
|
1018 |
yield output_filename, gr.update(visible=False), gr.update(), '', gr.update(interactive=True), gr.update(interactive=False)
|
|
|
1026 |
|
1027 |
# 部分的に生成された動画がある場合、それを返す
|
1028 |
if prev_output_filename:
|
1029 |
+
yield prev_output_filename, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
1030 |
else:
|
1031 |
+
yield None, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
1032 |
break
|
1033 |
|
1034 |
except Exception as e:
|
|
|
1036 |
traceback.print_exc()
|
1037 |
error_msg = str(e)
|
1038 |
|
1039 |
+
yield None, gr.update(visible=False), gr.update(), gr.update(interactive=True), gr.update(interactive=False)
|
|
|
1040 |
|
1041 |
|
1042 |
def end_process():
|
|
|
1087 |
margin: 0 auto;
|
1088 |
}
|
1089 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1090 |
|
1091 |
/* ページタイトルのスタイル */
|
1092 |
h1 {
|
|
|
1229 |
css = make_custom_css()
|
1230 |
block = gr.Blocks(css=css).queue()
|
1231 |
with block:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1232 |
# タイトルにはJavaScriptで切り替えられるようにdata-i18n属性を使用
|
1233 |
gr.HTML("<h1 data-i18n='title'>FramePack - 画像から動画生成</h1>")
|
1234 |
|
|
|
1344 |
|
1345 |
block.launch()
|
1346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|