SRDdev commited on
Commit
d6f050f
1 Parent(s): f384b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -23
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)[::-1]
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
- if len(query) > 0:
127
- results = image_search(query, corpus)
128
- clicked = clickable_images(
129
- [result[0] for result in results],
130
- titles=[result[1] for result in results],
131
- div_style={
132
- "display": "flex",
133
- "justify-content": "center",
134
- "flex-wrap": "wrap",
135
- },
136
- img_style={"margin": "2px", "height": "200px"},
137
- )
138
- if clicked >= 0:
139
- change_query = False
140
- if "last_clicked" not in st.session_state:
141
- change_query = True
142
- else:
143
- if clicked != st.session_state["last_clicked"]:
144
  change_query = True
145
- if change_query:
146
- st.session_state["query"] = f"[{corpus}:{results[clicked][2]}]"
147
- st.experimental_rerun()
 
 
 
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()