更新了mainpy 将print替换为了logging
This commit is contained in:
parent
727a5cef7c
commit
900220ea99
12
main.py
12
main.py
@ -30,8 +30,8 @@ from utils.poster_notes_creator import select_additional_images
|
|||||||
def load_config(config_path="poster_gen_config.json"):
|
def load_config(config_path="poster_gen_config.json"):
|
||||||
"""Loads configuration from a JSON file."""
|
"""Loads configuration from a JSON file."""
|
||||||
if not os.path.exists(config_path):
|
if not os.path.exists(config_path):
|
||||||
print(f"Error: Configuration file '{config_path}' not found.")
|
logging.error(f"Error: Configuration file '{config_path}' not found.")
|
||||||
print("Please copy 'example_config.json' to 'poster_gen_config.json' and customize it.")
|
logging.info("Please copy 'example_config.json' to 'poster_gen_config.json' and customize it.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
with open(config_path, 'r', encoding='utf-8') as f:
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
@ -40,23 +40,23 @@ def load_config(config_path="poster_gen_config.json"):
|
|||||||
required_keys = ["api_url", "model", "api_key", "resource_dir", "output_dir", "num", "variants", "topic_system_prompt", "topic_user_prompt", "content_system_prompt", "image_base_dir"]
|
required_keys = ["api_url", "model", "api_key", "resource_dir", "output_dir", "num", "variants", "topic_system_prompt", "topic_user_prompt", "content_system_prompt", "image_base_dir"]
|
||||||
if not all(key in config for key in required_keys):
|
if not all(key in config for key in required_keys):
|
||||||
missing_keys = [key for key in required_keys if key not in config]
|
missing_keys = [key for key in required_keys if key not in config]
|
||||||
print(f"Error: Config file '{config_path}' is missing required keys: {missing_keys}")
|
logging.error(f"Error: Config file '{config_path}' is missing required keys: {missing_keys}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# 验证prompts_dir或prompts_config至少有一个存在
|
# 验证prompts_dir或prompts_config至少有一个存在
|
||||||
if not ("prompts_dir" in config
|
if not ("prompts_dir" in config
|
||||||
or "prompts_config" in config):
|
or "prompts_config" in config):
|
||||||
print(f"Error: Config file '{config_path}' must contain either 'prompts_dir' or 'prompts_config'")
|
logging.error(f"Error: Config file '{config_path}' must contain either 'prompts_dir' or 'prompts_config'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Resolve relative paths based on config location or a defined base path if necessary
|
# Resolve relative paths based on config location or a defined base path if necessary
|
||||||
# For simplicity, assuming paths in config are relative to project root or absolute
|
# For simplicity, assuming paths in config are relative to project root or absolute
|
||||||
return config
|
return config
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
print(f"Error: Could not decode JSON from '{config_path}'. Check the file format.")
|
logging.error(f"Error: Could not decode JSON from '{config_path}'. Check the file format.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading configuration from '{config_path}': {e}")
|
logging.error(f"Error loading configuration from '{config_path}': {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Removed generate_topics_step function definition from here
|
# Removed generate_topics_step function definition from here
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user