Update image_search.py
Browse files263 unmodified lines264265266267268269157 unmodified lines427428429263 unmodified lines# Optional dataset downloaderfrom download import download_flickr8k_dataset# -------------------------# HuggingFace CLIP Wrapper157 unmodified linesglobal custom_image_pathscustom_image_paths = [os.path.join(folder_path, name) for name in os.listdir(folder_path) if name.lower().endswith((".jpg", ".jpeg", ".png"))]263 unmodified lines264265266267268269270157 unmodified lines428429430431432433434435436437438263 unmodified lines# Optional dataset downloaderfrom download import download_flickr8k_datasetTOP_K = 5# -------------------------# HuggingFace CLIP Wrapper157 unmodified linesglobal custom_image_pathscustom_image_paths = [os.path.join(folder_path, name) for name in os.listdir(folder_path) if name.lower().endswith((".jpg", ".jpeg", ".png"))]def query_by_image(image_path, nn_model, image_paths):image = Image.open(image_path).convert("RGB")tensor = clip_preprocess(image).unsqueeze(0).to(device)with torch.no_grad():image_features = clip_model.encode_image(tensor).cpu().numpy()dists, indices = nn_model.kneighbors(image_features, n_neighbors=TOP_K)return [image_paths[i] for i in indices[0]]
image_search.py+9