File size: 1,774 Bytes
169b607
 
 
 
 
 
 
 
 
 
 
 
 
 
0509eb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a37af7
0509eb5
 
 
 
 
3a37af7
 
 
 
 
0509eb5
 
 
 
3a37af7
 
 
 
 
0509eb5
 
 
 
 
 
 
3a37af7
 
 
 
 
0509eb5
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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