-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFlowState_Node.py
More file actions
127 lines (90 loc) · 3.38 KB
/
FlowState_Node.py
File metadata and controls
127 lines (90 loc) · 3.38 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Project: FlowState Node Base Class
# Description: Base node that all FlowState Nodes inherit from, so that they have access to global data and methods.
# Version: 0.0.1
# Author: Johnathan Chivington
# Contact: flowstateeng@gmail.com | youtube.com/@flowstateeng
##
# OUTSIDE IMPORTS
##
import os, sys, time
from datetime import datetime
##
# FS IMPORTS
##
from .FS_Constants import *
##
# BASE FS NODE
##
class FlowState_Node:
def __init__(self, node_name='FlowState Creator Suite Node: MISSING NAME'):
self.system_name = SYSTEM_NAME
self.system_version = SYSTEM_VERSION
self.node_name = node_name
self.errors = {
'checkpoint': [
('Error loading model. Make sure whether you are loading a checkpoint or not.', ),
('Be sure to select the right "model_filetype" for the model you are selecting.', )
],
'passthrough': [
('Error loading model. Cannot use combination of loaded & passthrough models.', ),
('Be sure to either LOAD the model, CLIP & VAE -- OR -- PASS THROUGH the model, CLIP & VAE.', )
],
'ingredients_img': [
('FlowState Chef Ingredients requires at least one image input.', )
]
}
def format_value_error(self, error_type):
msg = self.errors[error_type]
formatted_msg = [self.node_name] + [line[0] for line in msg]
formatted_msg = '\n'.join(formatted_msg)
self.print_status(msg, error=True)
return formatted_msg
def print_system_info(self):
print(
f'\n\n'
f'\n 🌊 {self.system_name} ({self.system_version}) 🌊'
f'\n---------------------------------------'
f'\n\n'
)
def print_status(self, messages, init=False, end=False, error=False):
if init:
print(f'\n\n\n --- STARTING {self.node_name} ---')
print(f'\n')
if error: print('-' * 100)
print(self.node_name)
for msg in messages:
msg_str = f' - {msg[0]}'
if len(msg) > 1:
msg_str += f': {msg[1]}'
print(msg_str)
if error: print('-' * 100)
print(' ')
if end:
print(f'\n --- {self.node_name} COMPLETE --- \n\n\n')
def get_mins_and_secs(self, start_time):
duration = time.time() - start_time
mins = int(duration // 60)
secs = int(duration - mins * 60)
return round(duration, 4), mins, secs
def check_tensor_equality(self, t1, t2, tensor_type='image'):
self.print_status([(f'Checking Tensor ({tensor_type}) Equality...',)])
has_t1 = t1 != None
has_t2 = t2 != None
has_neither = not has_t1 and not has_t2
has_t2_but_not_t1 = has_t2 and not has_t1
has_t1_but_not_t2 = has_t1 and not has_t2
one_missing = has_t2_but_not_t1 or has_t1_but_not_t2
if one_missing:
return False
if has_neither:
return True
same_shape = t1.shape == t2.shape
if not same_shape:
return False
if same_shape:
equal_tensors = t1.equal(t2)
if not equal_tensors:
return False
return True
def get_formatted_time(self):
return datetime.now().strftime('%Y-%m-%d %H-%M-%S.%f')[:-3]