mirror of
https://github.com/karl0ss/comfy_fm24_newgens.git
synced 2025-04-29 12:23:39 +01:00
use_gpu for removebg and update/create
This commit is contained in:
parent
70a152261f
commit
e71acc81ed
@ -13,14 +13,19 @@ import logging.config
|
|||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from lib.rtf_parser import RTF_Parser
|
from lib.rtf_parser import RTF_Parser
|
||||||
from lib.remove_bg import remove_bg_from_files_in_dir
|
from lib.remove_bg import remove_bg_from_files_in_dir
|
||||||
from lib.generate_xml import create_config_xml
|
from lib.generate_xml import create_config_xml, append_to_config_xml
|
||||||
from lib.resize_images import resize_images
|
from lib.resize_images import resize_images
|
||||||
|
from lib.xml_reader import extract_from_values
|
||||||
from lib.logging import LOGGING_CONFIG
|
from lib.logging import LOGGING_CONFIG
|
||||||
|
|
||||||
|
# from simple_term_menu import TerminalMenu
|
||||||
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
|
from comfy_api_simplified import ComfyApiWrapper, ComfyWorkflowWrapper
|
||||||
|
|
||||||
logging.config.dictConfig(LOGGING_CONFIG)
|
logging.config.dictConfig(LOGGING_CONFIG)
|
||||||
|
|
||||||
cut = None
|
cut = 500
|
||||||
|
update = False
|
||||||
|
use_gpu = False
|
||||||
|
|
||||||
# Load user configurations
|
# Load user configurations
|
||||||
user_config = configparser.ConfigParser()
|
user_config = configparser.ConfigParser()
|
||||||
@ -145,23 +150,44 @@ def main():
|
|||||||
logging.error("config.json file not found.")
|
logging.error("config.json file not found.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
prompts = generate_prompts_for_players(rtf_file, app_config)
|
# Check for processed
|
||||||
for prompt in tqdm(prompts, desc="Generating Images"):
|
|
||||||
uid = prompt.split(":")[0]
|
|
||||||
comfy_prompt = prompt.split(":")[1]
|
|
||||||
generate_image(
|
|
||||||
uid, comfy_prompt, user_config["general"]["model"], args.num_inference_steps
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
resize_images(output_folder)
|
if update:
|
||||||
remove_bg_from_files_in_dir(output_folder)
|
values_from_config = extract_from_values(f"{user_config['general']['output_dir']}config.xml")
|
||||||
|
# Extract the IDs from list_a
|
||||||
|
ids_in_b = [item for item in values_from_config]
|
||||||
|
|
||||||
create_config_xml(output_folder)
|
# Filter list_a to remove inner lists whose first item matches an ID in list_b
|
||||||
logging.debug("Post-processing complete.")
|
players_to_process = [item for item in rtf_file if item[0] not in ids_in_b]
|
||||||
except Exception as e:
|
else:
|
||||||
logging.error(f"Post-processing failed: {e}")
|
players_to_process = rtf_file
|
||||||
|
except FileNotFoundError:
|
||||||
|
logging.error("config.json file not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
if len(players_to_process) > 0:
|
||||||
|
print(f"Processing {len(players_to_process)} players")
|
||||||
|
logging.info(f"Processing {len(players_to_process)} players")
|
||||||
|
prompts = generate_prompts_for_players(players_to_process, app_config)
|
||||||
|
for prompt in tqdm(prompts, desc="Generating Images"):
|
||||||
|
uid = prompt.split(":")[0]
|
||||||
|
comfy_prompt = prompt.split(":")[1]
|
||||||
|
generate_image(
|
||||||
|
uid, comfy_prompt, user_config["general"]["model"], args.num_inference_steps
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
resize_images(output_folder)
|
||||||
|
remove_bg_from_files_in_dir(output_folder, use_gpu=use_gpu)
|
||||||
|
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:
|
||||||
|
logging.error(f"Post-processing failed: {e}")
|
||||||
|
else:
|
||||||
|
print(f"{len(rtf_file)} players already processed")
|
||||||
|
logging.info(f"{len(rtf_file)} players already processed")
|
||||||
logging.info("Image generation complete for players in RTF file.")
|
logging.info("Image generation complete for players in RTF file.")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user