@@ -64,19 +64,20 @@ async def get_examples(request):
64
64
type , name )
65
65
if not file_path :
66
66
return web .Response (status = 404 )
67
-
67
+
68
68
file_path_no_ext = os .path .splitext (file_path )[0 ]
69
69
examples = []
70
70
71
71
if os .path .isdir (file_path_no_ext ):
72
72
examples += sorted (map (lambda t : os .path .relpath (t , file_path_no_ext ),
73
- glob .glob (file_path_no_ext + "/*.txt" )))
74
-
73
+ glob .glob (file_path_no_ext + "/*.txt" )))
74
+
75
75
if os .path .isfile (file_path_no_ext + ".txt" ):
76
76
examples += ["notes" ]
77
-
77
+
78
78
return web .json_response (examples )
79
79
80
+
80
81
@PromptServer .instance .routes .post ("/pysssss/examples/{name}" )
81
82
async def save_example (request ):
82
83
name = request .match_info ["name" ]
@@ -91,7 +92,7 @@ async def save_example(request):
91
92
type , name )
92
93
if not file_path :
93
94
return web .Response (status = 404 )
94
-
95
+
95
96
if not example_name .endswith (".txt" ):
96
97
example_name += ".txt"
97
98
@@ -105,83 +106,57 @@ async def save_example(request):
105
106
return web .Response (status = 201 )
106
107
107
108
108
- def populate_items (names , type ):
109
- for idx , item_name in enumerate (names ):
109
+ @PromptServer .instance .routes .get ("/pysssss/images/{type}" )
110
+ async def get_images (request ):
111
+ type = request .match_info ["type" ]
112
+ names = folder_paths .get_filename_list (type )
110
113
114
+ images = {}
115
+ for item_name in names :
111
116
file_name = os .path .splitext (item_name )[0 ]
112
117
file_path = folder_paths .get_full_path (type , item_name )
113
118
114
119
if file_path is None :
115
- print (f"(pysssss:better_combos) Unable to get path for { type } { item_name } " )
116
120
continue
117
121
118
122
file_path_no_ext = os .path .splitext (file_path )[0 ]
119
123
120
124
for ext in ["png" , "jpg" , "jpeg" , "preview.png" , "preview.jpeg" ]:
121
- has_image = os .path .isfile (file_path_no_ext + "." + ext )
122
- if has_image :
123
- item_image = f"{ file_name } .{ ext } "
125
+ if os .path .isfile (file_path_no_ext + "." + ext ):
126
+ images [item_name ] = f"{ type } /{ file_name } .{ ext } "
124
127
break
125
128
126
- names [idx ] = {
127
- "content" : item_name ,
128
- "image" : f"{ type } /{ item_image } " if has_image else None ,
129
- }
130
- names .sort (key = lambda i : i ["content" ].lower ())
129
+ return web .json_response (images )
131
130
132
131
133
132
class LoraLoaderWithImages (LoraLoader ):
134
133
RETURN_TYPES = (* LoraLoader .RETURN_TYPES , "STRING" ,)
134
+ RETURN_NAMES = (* getattr (LoraLoader , "RETURN_NAMES" ,
135
+ LoraLoader .RETURN_TYPES ), "example" )
135
136
136
137
@classmethod
137
138
def INPUT_TYPES (s ):
138
139
types = super ().INPUT_TYPES ()
139
- names = types ["required" ]["lora_name" ][0 ]
140
- populate_items (names , "loras" )
141
- types ["optional" ] = { "prompt" : ("HIDDEN" ,) }
140
+ types ["optional" ] = {"prompt" : ("STRING" , {"hidden" : True })}
142
141
return types
143
142
144
- @classmethod
145
- def VALIDATE_INPUTS (s , lora_name ):
146
- types = super ().INPUT_TYPES ()
147
- names = types ["required" ]["lora_name" ][0 ]
148
-
149
- name = lora_name ["content" ]
150
- if name in names :
151
- return True
152
- else :
153
- return f"Lora not found: { name } "
154
-
155
143
def load_lora (self , ** kwargs ):
156
- kwargs ["lora_name" ] = kwargs ["lora_name" ]["content" ]
157
144
prompt = kwargs .pop ("prompt" , "" )
158
145
return (* super ().load_lora (** kwargs ), prompt )
159
146
160
147
161
148
class CheckpointLoaderSimpleWithImages (CheckpointLoaderSimple ):
162
149
RETURN_TYPES = (* CheckpointLoaderSimple .RETURN_TYPES , "STRING" ,)
163
-
150
+ RETURN_NAMES = (* getattr (CheckpointLoaderSimple , "RETURN_NAMES" ,
151
+ CheckpointLoaderSimple .RETURN_TYPES ), "example" )
152
+
164
153
@classmethod
165
154
def INPUT_TYPES (s ):
166
155
types = super ().INPUT_TYPES ()
167
- names = types ["required" ]["ckpt_name" ][0 ]
168
- populate_items (names , "checkpoints" )
169
- types ["optional" ] = { "prompt" : ("HIDDEN" ,) }
156
+ types ["optional" ] = {"prompt" : ("STRING" , {"hidden" : True })}
170
157
return types
171
158
172
- @classmethod
173
- def VALIDATE_INPUTS (s , ckpt_name ):
174
- types = super ().INPUT_TYPES ()
175
- names = types ["required" ]["ckpt_name" ][0 ]
176
-
177
- name = ckpt_name ["content" ]
178
- if name in names :
179
- return True
180
- else :
181
- return f"Checkpoint not found: { name } "
182
-
183
159
def load_checkpoint (self , ** kwargs ):
184
- kwargs ["ckpt_name" ] = kwargs ["ckpt_name" ]["content" ]
185
160
prompt = kwargs .pop ("prompt" , "" )
186
161
return (* super ().load_checkpoint (** kwargs ), prompt )
187
162
0 commit comments