This commit is contained in:
Karl Hudgell 2024-12-14 23:12:04 +00:00
parent e71acc81ed
commit 7bc080c2ac
4 changed files with 46 additions and 16085 deletions

16049
2030New.rtf

File diff suppressed because it is too large Load Diff

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 Emil Mirzayev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -23,7 +23,7 @@ from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
logging.config.dictConfig(LOGGING_CONFIG) logging.config.dictConfig(LOGGING_CONFIG)
cut = 500 cut = 100
update = False update = False
use_gpu = False use_gpu = False
@ -112,6 +112,36 @@ def generate_prompts_for_players(players, app_config):
return prompts return prompts
def post_process_images(output_folder, update, processed_players):
"""
Handles post-processing tasks for generated images.
Args:
output_folder (str): Path to the folder where images are stored.
update (bool): Flag to determine if XML config should be updated.
processed_players (list): List of processed player IDs.
"""
try:
# Resize images to desired dimensions
resize_images(output_folder)
logging.debug("Images resized successfully.")
# Remove background from images using GPU if available
remove_bg_from_files_in_dir(output_folder, use_gpu=use_gpu)
logging.debug("Background removed from images.")
# Update or create configuration XML
if update:
append_to_config_xml(output_folder, processed_players)
logging.debug("Configuration XML updated.")
else:
create_config_xml(output_folder)
logging.debug("Configuration XML created.")
except Exception as e:
logging.error(f"Post-processing failed: {e}")
raise # Re-raise the exception to ensure the script stops if post-processing fails.
def main(): def main():
"""Main function for generating images.""" """Main function for generating images."""
parser = argparse.ArgumentParser(description="Generate images for country groups") parser = argparse.ArgumentParser(description="Generate images for country groups")
@ -135,7 +165,7 @@ def main():
# Parse the RTF file # Parse the RTF file
try: try:
rtf_file = rtf.parse_rtf(args.rtf_file)[:cut] rtf_file = random.sample(rtf.parse_rtf(args.rtf_file),cut)
logging.info(f"Parsed RTF file successfully. Found {len(rtf_file)} players.") logging.info(f"Parsed RTF file successfully. Found {len(rtf_file)} players.")
except FileNotFoundError: except FileNotFoundError:
logging.error(f"RTF file not found: {args.rtf_file}") logging.error(f"RTF file not found: {args.rtf_file}")
@ -153,7 +183,9 @@ def main():
# Check for processed # Check for processed
try: try:
if update: if update:
values_from_config = extract_from_values(f"{user_config['general']['output_dir']}config.xml") values_from_config = extract_from_values(
f"{user_config['general']['output_dir']}config.xml"
)
# Extract the IDs from list_a # Extract the IDs from list_a
ids_in_b = [item for item in values_from_config] ids_in_b = [item for item in values_from_config]
@ -172,17 +204,16 @@ def main():
uid = prompt.split(":")[0] uid = prompt.split(":")[0]
comfy_prompt = prompt.split(":")[1] comfy_prompt = prompt.split(":")[1]
generate_image( generate_image(
uid, comfy_prompt, user_config["general"]["model"], args.num_inference_steps uid,
comfy_prompt,
user_config["general"]["model"],
args.num_inference_steps,
) )
try: try:
resize_images(output_folder) post_process_images(
remove_bg_from_files_in_dir(output_folder, use_gpu=use_gpu) output_folder, update, [item[0] for item in players_to_process]
if update: )
append_to_config_xml(output_folder, [item[0] for item in players_to_process])
else:
create_config_xml(output_folder)
logging.debug("Post-processing complete.")
except Exception as e: except Exception as e:
logging.error(f"Post-processing failed: {e}") logging.error(f"Post-processing failed: {e}")
else: else:

View File

@ -88,5 +88,5 @@
"3": "Long", "3": "Long",
"4": "Bald" "4": "Bald"
}, },
"prompt": "Ultra-realistic close-up headshot of a {skin_tone} skinned male soccer player with a plain background looking at the camera. The player is {age} years old, from {country}, with {facial_characteristics} and {hair} hair. He is facing the camera with a confident expression, wearing a soccer jersey. The lighting is natural and soft, emphasizing facial features and skin texture" "prompt": "Ultra-realistic close-up headshot of a {skin_tone} skinned male soccer player with a plain background looking at the camera with his whole head in shot. The player is {age} years old, from {country}, with {facial_characteristics} and {hair} hair. He is facing the camera with a confident expression, wearing a soccer jersey. The lighting is natural and soft, emphasizing facial features and skin texture"
} }