Spaces:
Running
Running
Commit
•
087f23f
1
Parent(s):
81e59de
Update app.py
Browse files
app.py
CHANGED
@@ -47,12 +47,14 @@ d = 1024
|
|
47 |
text_index = faiss.index_factory(d, "Flat", faiss.METRIC_INNER_PRODUCT)
|
48 |
faiss.read_index("text_index.index")
|
49 |
|
50 |
-
def T2Isearch(query, k=50):
|
51 |
# Encode the text query
|
52 |
-
inputs = text_tokenizer([query], padding=True, return_tensors="pt")
|
53 |
outputs = text_model(**inputs)
|
54 |
query_embedding = outputs.text_embeds
|
55 |
query_vector = query_embedding.detach().numpy()
|
|
|
|
|
56 |
# query_vector = test_xt[0]
|
57 |
# query_vector = np.array([query_embedding])
|
58 |
faiss.normalize_L2(query_vector)
|
@@ -91,6 +93,7 @@ def T2Isearch(query, k=50):
|
|
91 |
st.image(image, width=600)
|
92 |
|
93 |
query = st.text_input("Enter your search query here:")
|
|
|
94 |
if st.button("Search"):
|
95 |
if query:
|
96 |
-
T2Isearch(query)
|
|
|
47 |
text_index = faiss.index_factory(d, "Flat", faiss.METRIC_INNER_PRODUCT)
|
48 |
faiss.read_index("text_index.index")
|
49 |
|
50 |
+
def T2Isearch(query,focussed_word, k=50):
|
51 |
# Encode the text query
|
52 |
+
inputs = text_tokenizer([query,focussed_word], padding=True, return_tensors="pt")
|
53 |
outputs = text_model(**inputs)
|
54 |
query_embedding = outputs.text_embeds
|
55 |
query_vector = query_embedding.detach().numpy()
|
56 |
+
query_vector = np.concatenate((query_vector[0], query_vector[1]), dtype=np.float32)
|
57 |
+
query_vector = query_vector.reshape(1,1024)
|
58 |
# query_vector = test_xt[0]
|
59 |
# query_vector = np.array([query_embedding])
|
60 |
faiss.normalize_L2(query_vector)
|
|
|
93 |
st.image(image, width=600)
|
94 |
|
95 |
query = st.text_input("Enter your search query here:")
|
96 |
+
focussed_word = st.text_input("Enter focussed word here")
|
97 |
if st.button("Search"):
|
98 |
if query:
|
99 |
+
T2Isearch(query, focussed_word)
|