gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
class Example: """ A example node Class methods ------------- INPUTTYPES (dict): Tell…
- User
class Example: """ A example node
Class methods ------------- INPUT_TYPES (dict): Tell the main program input parameters of nodes. Attributes ---------- RETURN_TYPES (`tuple`): The type of each element in the output tulple. RETURN_NAMES (`tuple`): Optional: The name of each output in the output tulple. FUNCTION (`str`): The name of the entry-point method. For example, if `FUNCTION = "execute"` then it will run Example().execute() OUTPUT_NODE ([`bool`]): If this node is an output node that outputs a result/image from the graph. The SaveImage node is an example. The backend iterates on these output nodes and tries to execute all their parents if their parent graph is properly connected. Assumed to be False if not present. CATEGORY (`str`): The category the node should appear in the UI. execute(s) -> tuple || None: The entry point method. The name of this method must be the same as the value of property `FUNCTION`. For example, if `FUNCTION = "execute"` then this method's name must be `execute`, if `FUNCTION = "foo"` then it must be `foo`. """ def __init__(self): pass @classmethod def INPUT_TYPES(s): """ Return a dictionary which contains config for all input fields. Some types (string): "MODEL", "VAE", "CLIP", "CONDITIONING", "LATENT", "IMAGE", "INT", "STRING", "FLOAT". Input types "INT", "STRING" or "FLOAT" are special values for fields on the node. The type can be a list for selection. Returns: `dict`: - Key input_fields_group (`string`): Can be either required, hidden or optional. A node class must have property `required` - Value input_fields (`dict`): Contains input fields config: * Key field_name (`string`): Name of a entry-point method's argument * Value field_config (`tuple`): + First value is a string indicate the type of field or a list for selection. + Secound value is a config for type "INT", "STRING" or "FLOAT". """ return { "required": { "image": ("IMAGE",), "int_field": ("INT", { "default": 0, "min": 0, #Minimum value "max": 4096, #Maximum value "step": 64, #Slider's step "display": "number" # Cosmetic only: display as "number" or "slider" }), "float_field": ("FLOAT", { "default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, "round": 0.001, #The value represeting the precision to round to, will be set to the step value by default. Can be set to False to disable rounding. "display": "number"}), "print_to_screen": (["enable", "disable"],), "string_field": ("STRING", { "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node "default": "Hello World!" }), }, } RETURN_TYPES = ("IMAGE",) #RETURN_NAMES = ("image_output_name",) FUNCTION = "test" #OUTPUT_NODE = False CATEGORY = "Example" def test(self, image, string_field, int_field, float_field, print_to_screen): if print_to_screen == "enable": print(f"""Your input contains: string_field aka input text: {string_field} int_field: {int_field} float_field: {float_field} """) #do some processing on the image, in this example I just invert it image = 1.0 - image return (image,) - Assistant
def create_excel_file(): import pandas as pd
# Create a dataframe with sample data data = { 'Field': ['image', 'int_field', 'float_field', 'print_to_screen', 'string_field'], 'Description': ['An input image', 'An integer field', 'A float field', 'Print to screen option', 'A string field'], 'Type': ['IMAGE', 'INT', 'FLOAT', 'STRING', 'STRING'], 'Default Value': [None, 0, 1.0, None, 'Hello World!'], 'Minimum Value': [None, 0, 0.0, None, None], 'Maximum Value': [None, 4096, 10.0, None, None], 'Step Value': [None, 64, 0.01, None, None], 'Display Type': [None, 'number', 'number', ['enable', 'disable'], None], 'Multiline': [None, None, None, None, False] } df = pd.DataFrame(data) # Write dataframe to excel file writer = pd.ExcelWriter('custom_nodes.xlsx') df.to_excel(writer, index=False) writer.save() print("Excel file created successfully!")Create the excel file
create_excel_file()
- User
继续
- Assistant
import pandas as pd def load_excel_file(filepath): # Read the excel file into a dataframe df = pd.read_excel(filepath) # Convert the dataframe to a dictionary input_types = {"required": {}} for _, row in df.iterrows(): field_name = row['Field'] field_type = row['Type'] field_config = {} if field_type == 'INT': field_config = { 'default': row['Default Value'], 'min': row['Minimum Value'], 'max': row['Maximum Value'], 'step': row['Step Value'], 'display': row['Display Type'] } elif field_type == 'FLOAT': field_config = { 'default': row['Default Value'], 'min': row['Minimum Value'], 'max': row['Maximum Value'], 'step': row['Step Value'], 'display': row['Display Type'], 'round': row['Step Value'] } elif field_type == 'STRING': field_config = { 'default': row['Default Value'], 'multiline': row['Multiline'] } input_types['required'][field_name] = (field_type, field_config) return input_types # Load the excel file input_types = load_excel_file('custom_nodes.xlsx') print(input_types) - User
根据我提供的实例代码来组织 你的 代码,重写一下
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.