Spaces:
Build error
Build error
Commit
·
9a9f244
1
Parent(s):
940dcd8
app.py
Browse files
app.py
CHANGED
@@ -75,7 +75,7 @@ with open(emb_filename, 'rb') as fIn:
|
|
75 |
img_names, img_emb = pickle.load(fIn)
|
76 |
|
77 |
def display_matches(indices):
|
78 |
-
best_matched_images = [Image.open(
|
79 |
return best_matched_images
|
80 |
|
81 |
def image_search(search_text, search_image, option):
|
@@ -87,7 +87,7 @@ def image_search(search_text, search_image, option):
|
|
87 |
#text_features = encode_search_query(search_text, model, device)
|
88 |
text_emb = model.encode([search_text], convert_to_tensor=True)
|
89 |
similarity = util.cos_sim(img_emb, text_emb)
|
90 |
-
return
|
91 |
# Find the matched Images
|
92 |
#matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
93 |
#matched_results = util.semantic_search(text_emb, img_emb, top_k=4)[0]
|
@@ -112,9 +112,9 @@ def image_search(search_text, search_image, option):
|
|
112 |
#matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
113 |
#similarity = util.cos_sim(image_emb, img_emb)
|
114 |
#matched_results = util.semantic_search(image_emb, img_emb, 4)[0]
|
115 |
-
|
116 |
-
similarity = util.cos_sim(img_emb,
|
117 |
-
return
|
118 |
|
119 |
gr.Interface(fn=image_search,
|
120 |
inputs=[gr.inputs.Textbox(lines=7, label="Input Text"),
|
|
|
75 |
img_names, img_emb = pickle.load(fIn)
|
76 |
|
77 |
def display_matches(indices):
|
78 |
+
best_matched_images = [Image.open(IMAGES_DIR / img_names[top_k_best_image]) for top_k_best_image in torch.topk(similarity, 2, 0).indices]
|
79 |
return best_matched_images
|
80 |
|
81 |
def image_search(search_text, search_image, option):
|
|
|
87 |
#text_features = encode_search_query(search_text, model, device)
|
88 |
text_emb = model.encode([search_text], convert_to_tensor=True)
|
89 |
similarity = util.cos_sim(img_emb, text_emb)
|
90 |
+
return display_matches(similarity)
|
91 |
# Find the matched Images
|
92 |
#matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
93 |
#matched_results = util.semantic_search(text_emb, img_emb, top_k=4)[0]
|
|
|
112 |
#matched_images = find_matches(text_features, photo_features, photo_ids, 4)
|
113 |
#similarity = util.cos_sim(image_emb, img_emb)
|
114 |
#matched_results = util.semantic_search(image_emb, img_emb, 4)[0]
|
115 |
+
imageg_emb = model.encode([Image.fromarray(search_image)], convert_to_tensor=True)
|
116 |
+
similarity = util.cos_sim(img_emb, image_emb)
|
117 |
+
return display_matches(similarity)
|
118 |
|
119 |
gr.Interface(fn=image_search,
|
120 |
inputs=[gr.inputs.Textbox(lines=7, label="Input Text"),
|