@@ -64,19 +64,20 @@ async def get_examples(request):
6464 type , name )
6565 if not file_path :
6666 return web .Response (status = 404 )
67-
67+
6868 file_path_no_ext = os .path .splitext (file_path )[0 ]
6969 examples = []
7070
7171 if os .path .isdir (file_path_no_ext ):
7272 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+
7575 if os .path .isfile (file_path_no_ext + ".txt" ):
7676 examples += ["notes" ]
77-
77+
7878 return web .json_response (examples )
7979
80+
8081@PromptServer .instance .routes .post ("/pysssss/examples/{name}" )
8182async def save_example (request ):
8283 name = request .match_info ["name" ]
@@ -91,7 +92,7 @@ async def save_example(request):
9192 type , name )
9293 if not file_path :
9394 return web .Response (status = 404 )
94-
95+
9596 if not example_name .endswith (".txt" ):
9697 example_name += ".txt"
9798
@@ -105,83 +106,57 @@ async def save_example(request):
105106 return web .Response (status = 201 )
106107
107108
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 )
110113
114+ images = {}
115+ for item_name in names :
111116 file_name = os .path .splitext (item_name )[0 ]
112117 file_path = folder_paths .get_full_path (type , item_name )
113118
114119 if file_path is None :
115- print (f"(pysssss:better_combos) Unable to get path for { type } { item_name } " )
116120 continue
117121
118122 file_path_no_ext = os .path .splitext (file_path )[0 ]
119123
120124 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 } "
124127 break
125128
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 )
131130
132131
133132class LoraLoaderWithImages (LoraLoader ):
134133 RETURN_TYPES = (* LoraLoader .RETURN_TYPES , "STRING" ,)
134+ RETURN_NAMES = (* getattr (LoraLoader , "RETURN_NAMES" ,
135+ LoraLoader .RETURN_TYPES ), "example" )
135136
136137 @classmethod
137138 def INPUT_TYPES (s ):
138139 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 })}
142141 return types
143142
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-
155143 def load_lora (self , ** kwargs ):
156- kwargs ["lora_name" ] = kwargs ["lora_name" ]["content" ]
157144 prompt = kwargs .pop ("prompt" , "" )
158145 return (* super ().load_lora (** kwargs ), prompt )
159146
160147
161148class CheckpointLoaderSimpleWithImages (CheckpointLoaderSimple ):
162149 RETURN_TYPES = (* CheckpointLoaderSimple .RETURN_TYPES , "STRING" ,)
163-
150+ RETURN_NAMES = (* getattr (CheckpointLoaderSimple , "RETURN_NAMES" ,
151+ CheckpointLoaderSimple .RETURN_TYPES ), "example" )
152+
164153 @classmethod
165154 def INPUT_TYPES (s ):
166155 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 })}
170157 return types
171158
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-
183159 def load_checkpoint (self , ** kwargs ):
184- kwargs ["ckpt_name" ] = kwargs ["ckpt_name" ]["content" ]
185160 prompt = kwargs .pop ("prompt" , "" )
186161 return (* super ().load_checkpoint (** kwargs ), prompt )
187162
0 commit comments