@@ -485,6 +485,49 @@ def load_model(self, model_path) -> None:
485485 print (f'Loaded { self .name } model from { model_path } ' )
486486
487487
488+ class FromFileInterrogator (Interrogator ):
489+ """ Pseudo Interrogator reading preinterrogated tags files """
490+ def __init__ (self , name : str , path : os .PathLike , val = 1.0 ) -> None :
491+ super ().__init__ (name )
492+ self .path = path
493+ self .val = val
494+ self .tags = None
495+
496+ def load (self ) -> None :
497+ print (f'Loading { self .name } from { str (self .path )} ' )
498+ # self.path is a directory
499+ if not os .path .isdir (self .path ):
500+ raise ValueError (f'{ self .path } is not a directory' )
501+ else :
502+ self .tags = {}
503+ for f in os .listdir (self .path ):
504+ self .tags [f ] = {}
505+ self .load_file (f )
506+
507+ def load_file (self , tags_file : str ) -> None :
508+ image_name = str (tags_file ).split ('/' )[- 1 ].split ('.' )[0 ]
509+ with open (tags_file , 'r' ) as f :
510+ for line in f :
511+ for x in map (str .split , line .split (',' )):
512+ if x [0 ] == '(' and x [- 1 ] == ')' and ':' in x :
513+ tag , val = x [1 :- 1 ].split (':' )
514+ self .tags [image_name ][tag ] = float (val )
515+ else :
516+ self .tags [image_name ][x ] = self .val
517+
518+ def unload (self ) -> None :
519+ self .tags = {}
520+
521+ def interrogate (
522+ self ,
523+ image : Image
524+ ) -> Tuple [
525+ Dict [str , float ], # rating confidences
526+ Dict [str , float ] # tag confidences
527+ ]:
528+ return {}, self .tags [image .filename ]
529+
530+
488531class WaifuDiffusionInterrogator (HFInterrogator ):
489532 """ Interrogator for Waifu Diffusion models """
490533 def __init__ (
0 commit comments