Spaces:
Build error
Build error
Commit
·
ea1e3b9
1
Parent(s):
fde2555
app.py
Browse files
app.py
CHANGED
@@ -42,17 +42,18 @@ def encode_search_query(search_query, model):
|
|
42 |
inputs = tokenizer([search_query], padding=True, return_tensors="pt")
|
43 |
#inputs = processor(text=[search_query], images=None, return_tensors="pt", padding=True)
|
44 |
text_features = model.get_text_features(**inputs).detach().numpy()
|
45 |
-
return
|
46 |
|
47 |
# Find all matched photos
|
48 |
def find_matches(text_features, photo_features, photo_ids, results_count=4):
|
49 |
# Compute the similarity between the search query and each photo using the Cosine similarity
|
|
|
50 |
similarities = (photo_features @ text_features.T).squeeze(1)
|
51 |
# Sort the photos by their similarity score
|
52 |
best_photo_idx = (-similarities).argsort()
|
53 |
# Return the photo IDs of the best matches
|
54 |
matches = [photo_ids[i] for i in best_photo_idx[:results_count]]
|
55 |
-
return
|
56 |
|
57 |
def image_search(search_text, search_image, option):
|
58 |
|
|
|
42 |
inputs = tokenizer([search_query], padding=True, return_tensors="pt")
|
43 |
#inputs = processor(text=[search_query], images=None, return_tensors="pt", padding=True)
|
44 |
text_features = model.get_text_features(**inputs).detach().numpy()
|
45 |
+
return text_features
|
46 |
|
47 |
# Find all matched photos
|
48 |
def find_matches(text_features, photo_features, photo_ids, results_count=4):
|
49 |
# Compute the similarity between the search query and each photo using the Cosine similarity
|
50 |
+
text_features = np.array(text_features)
|
51 |
similarities = (photo_features @ text_features.T).squeeze(1)
|
52 |
# Sort the photos by their similarity score
|
53 |
best_photo_idx = (-similarities).argsort()
|
54 |
# Return the photo IDs of the best matches
|
55 |
matches = [photo_ids[i] for i in best_photo_idx[:results_count]]
|
56 |
+
return matches
|
57 |
|
58 |
def image_search(search_text, search_image, option):
|
59 |
|