Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -115,7 +115,9 @@ class NearestNeighbors:
|
|
115 |
|
116 |
model = CLIPTextModelWithProjection.from_pretrained("Searchium-ai/clip4clip-webvid150k")
|
117 |
tokenizer = CLIPTokenizer.from_pretrained("Searchium-ai/clip4clip-webvid150k")
|
118 |
-
|
|
|
|
|
119 |
def search(search_sentence):
|
120 |
inputs = tokenizer(text=search_sentence , return_tensors="pt")
|
121 |
outputs = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
@@ -123,11 +125,8 @@ def search(search_sentence):
|
|
123 |
# Normalizing the embeddings:
|
124 |
final_output = outputs[0] / outputs[0].norm(dim=-1, keepdim=True)
|
125 |
sequence_output = final_output.cpu().detach().numpy()
|
126 |
-
|
127 |
-
|
128 |
-
nn_search.fit(np.packbits((ft_visual_features_database > 0.0).astype(bool), axis=1), o_data=ft_visual_features_database)
|
129 |
-
sims, idxs = nn_search.kneighbors(sequence_output)
|
130 |
-
# print(database_df.iloc[idxs[0]]['contentUrl'])
|
131 |
urls = database_df.iloc[idxs[0]]['contentUrl'].to_list()
|
132 |
AUTOPLAY_VIDEOS = []
|
133 |
for url in urls:
|
|
|
115 |
|
116 |
model = CLIPTextModelWithProjection.from_pretrained("Searchium-ai/clip4clip-webvid150k")
|
117 |
tokenizer = CLIPTokenizer.from_pretrained("Searchium-ai/clip4clip-webvid150k")
|
118 |
+
nn_search = NearestNeighbors(n_neighbors=5, metric='binary', rerank_from=100)
|
119 |
+
nn_search.fit(np.packbits((ft_visual_features_database > 0.0).astype(bool), axis=1), o_data=ft_visual_features_database)
|
120 |
+
|
121 |
def search(search_sentence):
|
122 |
inputs = tokenizer(text=search_sentence , return_tensors="pt")
|
123 |
outputs = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
|
|
125 |
# Normalizing the embeddings:
|
126 |
final_output = outputs[0] / outputs[0].norm(dim=-1, keepdim=True)
|
127 |
sequence_output = final_output.cpu().detach().numpy()
|
128 |
+
|
129 |
+
sims, idxs = nn_search.kneighbors(sequence_output)
|
|
|
|
|
|
|
130 |
urls = database_df.iloc[idxs[0]]['contentUrl'].to_list()
|
131 |
AUTOPLAY_VIDEOS = []
|
132 |
for url in urls:
|