fix BLIP failing to import depending on configuration

This commit is contained in:
AUTOMATIC 2023-01-24 00:24:17 +03:00
parent 7ba7f4ed6e
commit 5c1cb9263f
2 changed files with 16 additions and 1 deletions

View File

@ -83,7 +83,8 @@ class InterrogateModels:
return self.loaded_categories
def load_blip_model(self):
import models.blip
with paths.Prioritize("BLIP"):
import models.blip
files = modelloader.load_models(
model_path=os.path.join(paths.models_path, "BLIP"),

View File

@ -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