Spaces:
Running
Running
cockolo terada
commited on
Update gradio_tabs/single.py
Browse files- gradio_tabs/single.py +20 -20
gradio_tabs/single.py
CHANGED
@@ -452,7 +452,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
452 |
workbench_state = gr.State([])
|
453 |
merged_preview_state = gr.State({})
|
454 |
|
455 |
-
# ---
|
456 |
def update_workbench_ui(workbench_list: List[Dict]) -> Tuple:
|
457 |
updates = []
|
458 |
for i in range(MAX_WORKBENCH_ITEMS):
|
@@ -514,7 +514,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
514 |
type="filepath", interactive=False
|
515 |
))
|
516 |
with gr.Row():
|
517 |
-
to_workbench_buttons.append(gr.Button("🛠️
|
518 |
audio_item_columns.append(audio_col)
|
519 |
|
520 |
for i in range(ITEMS_PER_ROW - 1):
|
@@ -556,8 +556,8 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
556 |
random_text_mode_slider = gr.Slider(label="分割の単位", minimum=1, maximum=4, value=1, step=1, info="1:形態素, 2:チャンク, 3:文節, 4:節", interactive=True)
|
557 |
random_text_ratio_textbox = gr.Textbox(label="カタカナ化の割合", value="0.5, 1", info="カンマ区切りで複数指定可。指定値からランダムに1つ使用。", interactive=True)
|
558 |
|
559 |
-
with gr.Tab("
|
560 |
-
gr.Markdown("##
|
561 |
|
562 |
workbench_items = []
|
563 |
all_workbench_ui_components = []
|
@@ -588,7 +588,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
588 |
|
589 |
with gr.Row():
|
590 |
merge_preview_button = gr.Button("1.結合&プレビュー", variant="primary")
|
591 |
-
add_merged_to_workbench_button = gr.Button("
|
592 |
delete_originals_checkbox = gr.Checkbox(label="結合時に自動で元ファイルを削除", value=False, interactive=True)
|
593 |
|
594 |
preview_audio_player = gr.Audio(label="結合結果プレビュー", interactive=False, type="filepath")
|
@@ -864,7 +864,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
864 |
|
865 |
return tuple(final_outputs)
|
866 |
|
867 |
-
# ---
|
868 |
def add_to_workbench(
|
869 |
current_status: str,
|
870 |
current_workbench_list: List[Dict],
|
@@ -874,12 +874,12 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
874 |
safe_workbench_list = current_workbench_list or []
|
875 |
|
876 |
if not audio_path or not Path(audio_path).exists():
|
877 |
-
log_messages.append("⚠️ [
|
878 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
879 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
880 |
|
881 |
if any(item['audio_path'] == audio_path for item in safe_workbench_list):
|
882 |
-
log_messages.append("ℹ️
|
883 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
884 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
885 |
|
@@ -908,10 +908,10 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
908 |
path_to_delete.unlink()
|
909 |
except Exception as e:
|
910 |
print(f"Warning: Failed to delete old workbench audio file: {e}")
|
911 |
-
log_messages.append(f"ℹ️
|
912 |
|
913 |
ui_updates = update_workbench_ui(updated_list)
|
914 |
-
log_messages.append("✅
|
915 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
916 |
return (final_status, updated_list) + ui_updates
|
917 |
|
@@ -926,13 +926,13 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
926 |
path_to_delete = Path(item_to_remove['audio_path'])
|
927 |
if path_to_delete.exists() and str(path_to_delete.parent) == tempfile.gettempdir():
|
928 |
path_to_delete.unlink()
|
929 |
-
log_messages.append(f"✅
|
930 |
elif path_to_delete.exists():
|
931 |
-
log_messages.append(f"✅
|
932 |
else:
|
933 |
-
log_messages.append(f"✅
|
934 |
except Exception as e:
|
935 |
-
log_messages.append(f"⚠️
|
936 |
|
937 |
updated_list = [item for i, item in enumerate(safe_workbench_list) if i != index_to_remove]
|
938 |
ui_updates = update_workbench_ui(updated_list)
|
@@ -947,7 +947,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
947 |
):
|
948 |
log_messages = []
|
949 |
if not workbench_list:
|
950 |
-
log_messages.append("⚠️ [結合プレビュー警告]
|
951 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
952 |
return final_status, None, {}
|
953 |
|
@@ -1043,13 +1043,13 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
1043 |
log_messages = []
|
1044 |
safe_workbench_list = current_workbench_list or []
|
1045 |
if not preview_data or "audio_path" not in preview_data:
|
1046 |
-
log_messages.append("⚠️ [
|
1047 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
1048 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
1049 |
|
1050 |
src_path = Path(preview_data["audio_path"])
|
1051 |
if not src_path.exists():
|
1052 |
-
log_messages.append("⚠️ [
|
1053 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
1054 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
1055 |
|
@@ -1081,10 +1081,10 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
1081 |
log_messages.append(f"⚠️ 元の音声ファイル削除中にエラー: {e}")
|
1082 |
|
1083 |
final_workbench_list = [new_merged_item] + remaining_list
|
1084 |
-
log_messages.append(f"✅
|
1085 |
else:
|
1086 |
final_workbench_list = [new_merged_item] + safe_workbench_list
|
1087 |
-
log_messages.append("✅
|
1088 |
|
1089 |
if len(final_workbench_list) > MAX_WORKBENCH_ITEMS:
|
1090 |
item_to_remove = final_workbench_list.pop(-1)
|
@@ -1094,7 +1094,7 @@ def create_synthesis_app(model_holder: TTSModelHolder) -> gr.Blocks:
|
|
1094 |
path_to_delete.unlink()
|
1095 |
except Exception as e:
|
1096 |
print(f"Warning: Failed to delete old workbench audio file: {e}")
|
1097 |
-
log_messages.append(f"ℹ️
|
1098 |
|
1099 |
ui_updates = update_workbench_ui(final_workbench_list)
|
1100 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
|
|
452 |
workbench_state = gr.State([])
|
453 |
merged_preview_state = gr.State({})
|
454 |
|
455 |
+
# --- キープUI更新ヘルパー ---
|
456 |
def update_workbench_ui(workbench_list: List[Dict]) -> Tuple:
|
457 |
updates = []
|
458 |
for i in range(MAX_WORKBENCH_ITEMS):
|
|
|
514 |
type="filepath", interactive=False
|
515 |
))
|
516 |
with gr.Row():
|
517 |
+
to_workbench_buttons.append(gr.Button("🛠️ キープに追加", scale=2))
|
518 |
audio_item_columns.append(audio_col)
|
519 |
|
520 |
for i in range(ITEMS_PER_ROW - 1):
|
|
|
556 |
random_text_mode_slider = gr.Slider(label="分割の単位", minimum=1, maximum=4, value=1, step=1, info="1:形態素, 2:チャンク, 3:文節, 4:節", interactive=True)
|
557 |
random_text_ratio_textbox = gr.Textbox(label="カタカナ化の割合", value="0.5, 1", info="カンマ区切りで複数指定可。指定値からランダムに1つ使用。", interactive=True)
|
558 |
|
559 |
+
with gr.Tab("キープ"):
|
560 |
+
gr.Markdown("## キープ\n読み上げタブで生成した音声をここにストックし、結合や保存ができます。最大8個まで保持できます。")
|
561 |
|
562 |
workbench_items = []
|
563 |
all_workbench_ui_components = []
|
|
|
588 |
|
589 |
with gr.Row():
|
590 |
merge_preview_button = gr.Button("1.結合&プレビュー", variant="primary")
|
591 |
+
add_merged_to_workbench_button = gr.Button("2.キープに追加", variant="primary")
|
592 |
delete_originals_checkbox = gr.Checkbox(label="結合時に自動で元ファイルを削除", value=False, interactive=True)
|
593 |
|
594 |
preview_audio_player = gr.Audio(label="結合結果プレビュー", interactive=False, type="filepath")
|
|
|
864 |
|
865 |
return tuple(final_outputs)
|
866 |
|
867 |
+
# --- キープイベントハンドラ ---
|
868 |
def add_to_workbench(
|
869 |
current_status: str,
|
870 |
current_workbench_list: List[Dict],
|
|
|
874 |
safe_workbench_list = current_workbench_list or []
|
875 |
|
876 |
if not audio_path or not Path(audio_path).exists():
|
877 |
+
log_messages.append("⚠️ [キープ追加エラー] 追加する音声ファイルが見つかりません。")
|
878 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
879 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
880 |
|
881 |
if any(item['audio_path'] == audio_path for item in safe_workbench_list):
|
882 |
+
log_messages.append("ℹ️ この音声はすでにキープに存在します。")
|
883 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
884 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
885 |
|
|
|
908 |
path_to_delete.unlink()
|
909 |
except Exception as e:
|
910 |
print(f"Warning: Failed to delete old workbench audio file: {e}")
|
911 |
+
log_messages.append(f"ℹ️ キープのアイテムが最大数({MAX_WORKBENCH_ITEMS})に達したため、一番古いアイテムを削除しました。")
|
912 |
|
913 |
ui_updates = update_workbench_ui(updated_list)
|
914 |
+
log_messages.append("✅ キープに音声を追加しました。")
|
915 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
916 |
return (final_status, updated_list) + ui_updates
|
917 |
|
|
|
926 |
path_to_delete = Path(item_to_remove['audio_path'])
|
927 |
if path_to_delete.exists() and str(path_to_delete.parent) == tempfile.gettempdir():
|
928 |
path_to_delete.unlink()
|
929 |
+
log_messages.append(f"✅ キープからアイテム #{index_to_remove + 1} を削除し、一時ファイルをクリーンアップしました。")
|
930 |
elif path_to_delete.exists():
|
931 |
+
log_messages.append(f"✅ キープからアイテム #{index_to_remove + 1} を削除しました。(ファイルは保持: {path_to_delete.name})")
|
932 |
else:
|
933 |
+
log_messages.append(f"✅ キープからアイテム #{index_to_remove + 1} を削除しました。(関連ファイルなし)")
|
934 |
except Exception as e:
|
935 |
+
log_messages.append(f"⚠️ キープのアイテム #{index_to_remove + 1} のファイル削除中にエラー: {e}")
|
936 |
|
937 |
updated_list = [item for i, item in enumerate(safe_workbench_list) if i != index_to_remove]
|
938 |
ui_updates = update_workbench_ui(updated_list)
|
|
|
947 |
):
|
948 |
log_messages = []
|
949 |
if not workbench_list:
|
950 |
+
log_messages.append("⚠️ [結合プレビュー警告] キープに音声がありません。")
|
951 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
952 |
return final_status, None, {}
|
953 |
|
|
|
1043 |
log_messages = []
|
1044 |
safe_workbench_list = current_workbench_list or []
|
1045 |
if not preview_data or "audio_path" not in preview_data:
|
1046 |
+
log_messages.append("⚠️ [キープ追加エラー] 追加する結合済み音声がありません。先にプレビューを生成してください。")
|
1047 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
1048 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
1049 |
|
1050 |
src_path = Path(preview_data["audio_path"])
|
1051 |
if not src_path.exists():
|
1052 |
+
log_messages.append("⚠️ [キープ追加エラー] 結合済み音声ファイルが見つかりません。")
|
1053 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|
1054 |
return (final_status, safe_workbench_list) + update_workbench_ui(safe_workbench_list)
|
1055 |
|
|
|
1081 |
log_messages.append(f"⚠️ 元の音声ファイル削除中にエラー: {e}")
|
1082 |
|
1083 |
final_workbench_list = [new_merged_item] + remaining_list
|
1084 |
+
log_messages.append(f"✅ 結合音声をキープに追加し、元の音声(#{idx1+1}, #{idx2+1})を削除しました。")
|
1085 |
else:
|
1086 |
final_workbench_list = [new_merged_item] + safe_workbench_list
|
1087 |
+
log_messages.append("✅ 結合済みの音声をキープの一番上に追加しました。")
|
1088 |
|
1089 |
if len(final_workbench_list) > MAX_WORKBENCH_ITEMS:
|
1090 |
item_to_remove = final_workbench_list.pop(-1)
|
|
|
1094 |
path_to_delete.unlink()
|
1095 |
except Exception as e:
|
1096 |
print(f"Warning: Failed to delete old workbench audio file: {e}")
|
1097 |
+
log_messages.append(f"ℹ️ キープが最大数({MAX_WORKBENCH_ITEMS})に達したため一番古いアイテムを削除しました。")
|
1098 |
|
1099 |
ui_updates = update_workbench_ui(final_workbench_list)
|
1100 |
final_status = (current_status + "\n" + "\n".join(log_messages)).strip()
|