Spaces:
Build error
Build error
Commit
·
e9213d0
1
Parent(s):
1ad57bd
app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,7 @@ 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 text_features
|
46 |
|
47 |
# Find all matched photos
|
48 |
def find_matches(text_features, photo_features, photo_ids, results_count=4):
|
@@ -51,7 +51,8 @@ def find_matches(text_features, photo_features, photo_ids, results_count=4):
|
|
51 |
# Sort the photos by their similarity score
|
52 |
best_photo_idx = (-similarities).argsort()
|
53 |
# Return the photo IDs of the best matches
|
54 |
-
|
|
|
55 |
|
56 |
def image_search(search_text, search_image, option):
|
57 |
|
|
|
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 np.array(text_features)
|
46 |
|
47 |
# Find all matched photos
|
48 |
def find_matches(text_features, photo_features, photo_ids, results_count=4):
|
|
|
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 np.array(matches)
|
56 |
|
57 |
def image_search(search_text, search_image, option):
|
58 |
|