Spaces:
Running
Running
Add spinner to search
Browse files
app.py
CHANGED
@@ -36,21 +36,19 @@ model, processor = load_model()
|
|
36 |
query = st.text_input("Enter your query here:")
|
37 |
|
38 |
if st.button("Search"):
|
39 |
-
st.
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
st.image(img)
|
55 |
-
st.write(f"{img_path} ({score:.2f})", help="score")
|
56 |
|
|
|
36 |
query = st.text_input("Enter your query here:")
|
37 |
|
38 |
if st.button("Search"):
|
39 |
+
with st.spinner(f"Searching ROCO test set for {query}..."):
|
40 |
+
inputs = processor(text=[query], images=None, return_tensors="jax", padding=True)
|
41 |
+
|
42 |
+
query_embedding = model.get_text_features(**inputs)
|
43 |
+
query_embedding = np.asarray(query_embedding)
|
44 |
+
query_embedding = query_embedding / np.linalg.norm(query_embedding, axis=-1, keepdims=True)
|
45 |
+
dot_prod = np.sum(np.multiply(query_embedding, image_embeddings), axis=1)
|
46 |
+
topk_images = dot_prod.argsort()[-k:]
|
47 |
+
matching_images = image_list[topk_images]
|
48 |
+
top_scores = 1. - dot_prod[topk_images]
|
49 |
+
#show images
|
50 |
+
for img_path, score in zip(matching_images, top_scores):
|
51 |
+
img = plt.imread(os.path.join(img_dir, img_path))
|
52 |
+
st.image(img)
|
53 |
+
st.write(f"{img_path} ({score:.2f})", help="score")
|
|
|
|
|
54 |
|