def process_string(input_string: str): """ :param input_string: :return: """ parts = input_string.split('/') if len(parts) == 2: first_element = parts[1] complete_string = input_string result = (first_element, complete_string) return result else: return None def extract_parameters(input_string: str) -> dict: """ :param input_string: :return: """ import re parameters: dict = {} input_string: str = input_string.replace("\n", "") if not "Negative prompt:" in input_string: print("Negative prompt not detected") parameters["prompt"] = input_string return parameters parm: list = input_string.split("Negative prompt:") parameters["prompt"] = parm[0] if not "Steps:" in parm[1]: print("Steps not detected") parameters["neg_prompt"] = parm[1] return parameters parm = parm[1].split("Steps:") parameters["neg_prompt"] = parm[0] input_string = "Steps:" + parm[1] # Extracting Steps steps_match = re.search(r'Steps: (\d+)', input_string) if steps_match: parameters['Steps'] = int(steps_match.group(1)) # Extracting Size size_match = re.search(r'Size: (\d+x\d+)', input_string) if size_match: parameters['Size'] = size_match.group(1) width, height = map(int, parameters['Size'].split('x')) parameters['width'] = width parameters['height'] = height # Extracting other parameters other_parameters = re.findall(r'(\w+): (.*?)(?=, \w+|$)', input_string) for param in other_parameters: parameters[param[0]] = param[1].strip('"') return parameters