Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed Install and Traceback Issue with utils.py #135

Open
PyrateGFXProductions opened this issue Dec 20, 2024 · 1 comment
Open

Failed Install and Traceback Issue with utils.py #135

PyrateGFXProductions opened this issue Dec 20, 2024 · 1 comment

Comments

@PyrateGFXProductions
Copy link

I noticed that the node was failing to install and throwing the following error so I fixed it.

Traceback (most recent call last):
  File "F:\ComfyUI_Windows_portable\ComfyUI\nodes.py", line 2073, in load_custom_node
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-IF_AI_tools\__init__.py", line 10, in <module>
    from .IFImagePromptNode import IFImagePrompt
  File "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-IF_AI_tools\IFImagePromptNode.py", line 14, in <module>
    from .utils import (
ImportError: cannot import name 'save_combo_settings' from 'ComfyUI-IF_AI_tools.utils' (F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-IF_AI_tools\utils.py)

Cannot import F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-IF_AI_tools module for custom nodes: cannot import name 'save_combo_settings' from 'ComfyUI-IF_AI_tools.utils' (F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-IF_AI_tools\utils.py)

I fix it by adding the following code to utils.py


def save_combo_settings(settings, directory):
    """
    Save combo settings to a JSON file in the specified directory.
    
    Args:
        settings (dict): The settings to save.
        directory (str): The directory where the settings file will be saved.
    
    Returns:
        str: The path to the saved settings file.
    """
    try:
        if not os.path.exists(directory):
            os.makedirs(directory)

        settings_file_path = os.path.join(directory, 'combo_settings.json')
        with open(settings_file_path, 'w') as f:
            json.dump(settings, f, indent=4)  # Save with pretty formatting

        logger.info(f"Settings saved to {settings_file_path}")
        return settings_file_path
    except Exception as e:
        logger.error(f"Error saving combo settings: {str(e)}")
        return None

def load_combo_settings(directory):
    """
    Load combo settings from a JSON file in the specified directory.
    
    Args:
        directory (str): The directory where the settings file is located.
    
    Returns:
        dict: The loaded settings or an empty dict if the file does not exist.
    """
    settings_file_path = os.path.join(directory, 'combo_settings.json')
    if not os.path.exists(settings_file_path):
        logger.warning(f"No settings file found at {settings_file_path}")
        return {}  # Return an empty dict if the file does not exist

    try:
        with open(settings_file_path, 'r') as f:
            settings = json.load(f)
        logger.info(f"Settings loaded from {settings_file_path}")
        return settings
    except Exception as e:
        logger.error(f"Error loading combo settings: {str(e)}")
        return {}

def create_settings_from_ui_IFImagePromptNode(data):
    """
    Create settings from the UI input data.
    
    Args:
        data (dict): The input data from the UI.
    
    Returns:
        dict: The created settings.
    """
    settings = {
        "llm_provider": data.get("llm_provider", ""),
        "llm_model": data.get("llm_model", ""),
        "base_ip": data.get("base_ip", "localhost"),
        "port": data.get("port", "11434"),
        "user_prompt": data.get("user_prompt", ""),
        "strategy": data.get("strategy", "normal"),
        "max_tokens": data.get("max_tokens", 2048),
        "temperature": data.get("temperature", 0.7),
        "top_k": data.get("top_k", 40),
        "top_p": data.get("top_p", 0.9),
        "repeat_penalty": data.get("repeat_penalty", 1.1),
        "seed": data.get("seed", 0),
        "aspect_ratio": data.get("aspect_ratio", "1:1"),
        # Add other settings as needed
    }
    logger.info("Settings created from UI input")
    return settings

@nikolaiusa
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants