Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -68,7 +68,7 @@ def image_search(query, corpus, max_results=3):
|
|
68 |
dot_product2 = dot_product2 / np.max(dot_product2, axis=0, keepdims=True)
|
69 |
dot_product -= np.max(np.maximum(dot_product2, 0), axis=1)
|
70 |
|
71 |
-
results = np.argsort(dot_product)[
|
72 |
return [
|
73 |
(
|
74 |
df[k].iloc[i]["path"],
|
@@ -122,29 +122,32 @@ def main():
|
|
122 |
query = st.sidebar.text_input("Query", value="lighthouse")
|
123 |
corpus = "Unsplash"
|
124 |
|
|
|
125 |
if st.sidebar.button("Submit"):
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
if
|
141 |
-
change_query =
|
142 |
-
|
143 |
-
if clicked != st.session_state["last_clicked"]:
|
144 |
change_query = True
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
148 |
|
149 |
st.sidebar.info("""
|
150 |
Enter your query and hit enter
|
@@ -155,4 +158,4 @@ def main():
|
|
155 |
""")
|
156 |
|
157 |
if __name__ == "__main__":
|
158 |
-
main()
|
|
|
68 |
dot_product2 = dot_product2 / np.max(dot_product2, axis=0, keepdims=True)
|
69 |
dot_product -= np.max(np.maximum(dot_product2, 0), axis=1)
|
70 |
|
71 |
+
results = np.argsort(dot_product)[-1 : -n_results - 1 : -1]
|
72 |
return [
|
73 |
(
|
74 |
df[k].iloc[i]["path"],
|
|
|
122 |
query = st.sidebar.text_input("Query", value="lighthouse")
|
123 |
corpus = "Unsplash"
|
124 |
|
125 |
+
# Wrap the content inside st.spinner for the "Submit" button
|
126 |
if st.sidebar.button("Submit"):
|
127 |
+
with st.spinner("Searching..."):
|
128 |
+
time.sleep(2) # Simulate a loading delay (replace with actual image search function)
|
129 |
+
if len(query) > 0:
|
130 |
+
results = image_search(query, corpus)
|
131 |
+
clicked = clickable_images(
|
132 |
+
[result[0] for result in results],
|
133 |
+
titles=[result[1] for result in results],
|
134 |
+
div_style={
|
135 |
+
"display": "flex",
|
136 |
+
"justify-content": "center",
|
137 |
+
"flex-wrap": "wrap",
|
138 |
+
},
|
139 |
+
img_style={"margin": "2px", "height": "200px"},
|
140 |
+
)
|
141 |
+
if clicked >= 0:
|
142 |
+
change_query = False
|
143 |
+
if "last_clicked" not in st.session_state:
|
|
|
144 |
change_query = True
|
145 |
+
else:
|
146 |
+
if clicked != st.session_state["last_clicked"]:
|
147 |
+
change_query = True
|
148 |
+
if change_query:
|
149 |
+
st.session_state["query"] = f"[{corpus}:{results[clicked][2]}]"
|
150 |
+
st.experimental_rerun()
|
151 |
|
152 |
st.sidebar.info("""
|
153 |
Enter your query and hit enter
|
|
|
158 |
""")
|
159 |
|
160 |
if __name__ == "__main__":
|
161 |
+
main()
|