Commit 5c1cb926 authored by AUTOMATIC's avatar AUTOMATIC
Browse files

fix BLIP failing to import depending on configuration

parent 7ba7f4ed
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ class InterrogateModels:
        return self.loaded_categories

    def load_blip_model(self):
        with paths.Prioritize("BLIP"):
            import models.blip

        files = modelloader.load_models(
+14 −0
Original line number Diff line number Diff line
@@ -38,3 +38,17 @@ for d, must_exist, what, options in path_dirs:
        else:
            sys.path.append(d)
        paths[what] = d


class Prioritize:
    def __init__(self, name):
        self.name = name
        self.path = None

    def __enter__(self):
        self.path = sys.path.copy()
        sys.path = [paths[self.name]] + sys.path

    def __exit__(self, exc_type, exc_val, exc_tb):
        sys.path = self.path
        self.path = None