updates UI

This commit is contained in:
mike
2026-06-30 01:07:54 +02:00
parent 61268de34b
commit ad9a2ae078
13 changed files with 1375 additions and 397 deletions

View File

@@ -10,6 +10,7 @@ _model = None
_preprocess = None
_device = None
_lock = threading.Lock()
_gpu_lock = threading.Lock()
def get_model():
global _model, _preprocess, _device
@@ -31,12 +32,13 @@ def get_model():
def generate_embedding(image_path):
model, preprocess, device = get_model()
try:
with Image.open(image_path) as img:
image = preprocess(img.convert("RGB")).unsqueeze(0).to(device)
with torch.no_grad():
image_features = model.encode_image(image)
image_features /= image_features.norm(dim=-1, keepdim=True)
return image_features.cpu().numpy()[0].tolist()
with _gpu_lock:
with Image.open(image_path) as img:
image = preprocess(img.convert("RGB")).unsqueeze(0).to(device)
with torch.no_grad():
image_features = model.encode_image(image)
image_features /= image_features.norm(dim=-1, keepdim=True)
return image_features.cpu().numpy()[0].tolist()
except Exception as e:
print(f"Error generating embedding for {image_path}: {e}")
return None