Spaces:
Sleeping
Sleeping
shivangibithel
commited on
Commit
·
cbb6586
1
Parent(s):
5c4950c
Update app.py
Browse files
app.py
CHANGED
@@ -41,19 +41,19 @@ class_list = list(df['class'])
|
|
41 |
zip_path = "pascal_raw.zip"
|
42 |
zip_file = zipfile.ZipFile(zip_path)
|
43 |
|
44 |
-
|
45 |
-
|
46 |
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 |
-
|
53 |
-
|
54 |
-
|
55 |
-
query_vector = test_xt[0]
|
56 |
-
|
57 |
faiss.normalize_L2(query_vector)
|
58 |
# text_index.nprobe = index.ntotal
|
59 |
text_index.nprobe = 100
|
|
|
41 |
zip_path = "pascal_raw.zip"
|
42 |
zip_file = zipfile.ZipFile(zip_path)
|
43 |
|
44 |
+
text_model = CLIPTextModelWithProjection.from_pretrained("openai/clip-vit-base-patch32")
|
45 |
+
text_tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32")
|
46 |
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 = test_xt[0]
|
56 |
+
query_vector = np.array([query_embedding])
|
57 |
faiss.normalize_L2(query_vector)
|
58 |
# text_index.nprobe = index.ntotal
|
59 |
text_index.nprobe = 100
|