当前存在海报生成过程中,对于末尾篇数可能存在海报无法找到路径的问题,增加了强制路径创建
This commit is contained in:
parent
b600876368
commit
32562f62e7
14
main.py
14
main.py
@ -214,8 +214,18 @@ def generate_content_and_posters_step(config, run_id, topics_list, output_handle
|
||||
|
||||
# 获取海报元数据路径
|
||||
poster_dir = os.path.join(variant_dir, poster_subdir)
|
||||
metadata_files = [f for f in os.listdir(poster_dir)
|
||||
if f.endswith("_metadata.json") and os.path.isfile(os.path.join(poster_dir, f))]
|
||||
|
||||
# 添加目录存在检查
|
||||
if not os.path.exists(poster_dir):
|
||||
logging.warning(f"海报目录不存在: {poster_dir}, 跳过此变体的额外配图处理")
|
||||
continue
|
||||
|
||||
try:
|
||||
metadata_files = [f for f in os.listdir(poster_dir)
|
||||
if f.endswith("_metadata.json") and os.path.isfile(os.path.join(poster_dir, f))]
|
||||
except Exception as e:
|
||||
logging.warning(f"访问海报目录时出错: {e}, 跳过此变体的额外配图处理")
|
||||
continue
|
||||
|
||||
if metadata_files:
|
||||
poster_metadata_path = os.path.join(poster_dir, metadata_files[0])
|
||||
|
||||
@ -42,13 +42,13 @@
|
||||
{
|
||||
"type": "Object",
|
||||
"file_path": [
|
||||
"./resource/Object/乌镇民宿.txt"
|
||||
"./resource/Object/安吉银润锦江城堡酒店.txt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Description",
|
||||
"file_path": [
|
||||
"./resource/Object/乌镇民宿.txt"
|
||||
"./resource/Object/安吉银润锦江城堡酒店.txt"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Binary file not shown.
@ -2,6 +2,7 @@ import os
|
||||
import json
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
import traceback
|
||||
|
||||
class OutputHandler(ABC):
|
||||
"""Abstract base class for handling the output of the generation pipeline."""
|
||||
@ -122,6 +123,10 @@ class FileSystemOutputHandler(OutputHandler):
|
||||
|
||||
def handle_generated_image(self, run_id: str, topic_index: int, variant_index: int, image_type: str, image_data, output_filename: str, metadata: dict = None):
|
||||
"""处理生成的图像,对于笔记图像和额外配图保存到image目录,其他类型保持原有路径结构"""
|
||||
if not image_data:
|
||||
logging.warning(f"传入的{image_type}图像数据为空 (Topic {topic_index}, Variant {variant_index})。跳过保存。")
|
||||
return
|
||||
|
||||
# 根据图像类型确定保存路径
|
||||
if image_type == 'note' or image_type == 'additional': # 笔记图像和额外配图保存到image目录
|
||||
# 创建run_id/i_j/image目录
|
||||
@ -144,7 +149,15 @@ class FileSystemOutputHandler(OutputHandler):
|
||||
logging.warning(f"未知图像类型 '{image_type}',保存到变体根目录。")
|
||||
subdir = None # 如果类型未知,直接保存到变体目录
|
||||
|
||||
target_dir = self._get_variant_dir(run_id, topic_index, variant_index, subdir=subdir)
|
||||
# 确保目标目录存在
|
||||
variant_dir = os.path.join(self._get_run_dir(run_id), f"{topic_index}_{variant_index}")
|
||||
if subdir:
|
||||
target_dir = os.path.join(variant_dir, subdir)
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
else:
|
||||
target_dir = variant_dir
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
save_path = os.path.join(target_dir, output_filename)
|
||||
|
||||
try:
|
||||
@ -163,9 +176,11 @@ class FileSystemOutputHandler(OutputHandler):
|
||||
logging.info(f"保存{image_type}元数据到: {metadata_path}")
|
||||
except Exception as me:
|
||||
logging.error(f"无法保存{image_type}元数据到{metadata_path}: {me}")
|
||||
traceback.print_exc()
|
||||
|
||||
except Exception as e:
|
||||
logging.exception(f"无法保存{image_type}图像到{save_path}: {e}")
|
||||
traceback.print_exc()
|
||||
|
||||
return save_path
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user