Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -18,8 +18,6 @@ model = SentenceTransformer('all-mpnet-base-v2')
|
|
18 |
flix_ds = load_dataset("nickmuchi/netflix-shows-mpnet-embeddings", use_auth_token=True)
|
19 |
dataset_embeddings = torch.from_numpy(flix_ds["train"].to_pandas().to_numpy()).to(torch.float)
|
20 |
|
21 |
-
embed = {'embedding': dataset_embeddings}
|
22 |
-
|
23 |
#load cross-encoder for reranking
|
24 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
25 |
|
@@ -33,11 +31,11 @@ def display_df_as_table(model,top_k,score='score'):
|
|
33 |
return df
|
34 |
|
35 |
#function for generating similarity of query and netflix shows
|
36 |
-
def semantic_search(query,
|
37 |
'''Encode query and check similarity with embeddings'''
|
38 |
|
39 |
question_embedding = model.encode(query, convert_to_tensor=True).cpu()
|
40 |
-
hits = util.semantic_search(question_embedding,
|
41 |
hits = hits[0]
|
42 |
|
43 |
##### Re-Ranking #####
|
@@ -115,7 +113,7 @@ with demo:
|
|
115 |
sem_but = gr.Button('Search')
|
116 |
|
117 |
|
118 |
-
sem_but.click(semantic_search,inputs=[query,
|
119 |
|
120 |
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=nickmuchi-netflix-shows-semantic-search)")
|
121 |
|
|
|
18 |
flix_ds = load_dataset("nickmuchi/netflix-shows-mpnet-embeddings", use_auth_token=True)
|
19 |
dataset_embeddings = torch.from_numpy(flix_ds["train"].to_pandas().to_numpy()).to(torch.float)
|
20 |
|
|
|
|
|
21 |
#load cross-encoder for reranking
|
22 |
cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-12-v2')
|
23 |
|
|
|
31 |
return df
|
32 |
|
33 |
#function for generating similarity of query and netflix shows
|
34 |
+
def semantic_search(query,top_k):
|
35 |
'''Encode query and check similarity with embeddings'''
|
36 |
|
37 |
question_embedding = model.encode(query, convert_to_tensor=True).cpu()
|
38 |
+
hits = util.semantic_search(question_embedding, dataset_embeddings, top_k=top_k)
|
39 |
hits = hits[0]
|
40 |
|
41 |
##### Re-Ranking #####
|
|
|
113 |
sem_but = gr.Button('Search')
|
114 |
|
115 |
|
116 |
+
sem_but.click(semantic_search,inputs=[query,top_k],outputs=[bi_output,cross_output],queue=True)
|
117 |
|
118 |
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=nickmuchi-netflix-shows-semantic-search)")
|
119 |
|