NEXAS commited on
Commit
71840d3
·
verified ·
1 Parent(s): 081e551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -35,7 +35,6 @@ def add_background_image(image_path):
35
  def display_images(image_collection, query_text, max_distance=None, debug=False):
36
  """
37
  Display images in a Streamlit app based on a query.
38
-
39
  Args:
40
  image_collection: The image collection object for querying.
41
  query_text (str): The text query for images.
@@ -54,19 +53,18 @@ def display_images(image_collection, query_text, max_distance=None, debug=False)
54
  # Combine uris and distances, then sort by URI in ascending order
55
  sorted_results = sorted(zip(uris, distances), key=lambda x: x[0])
56
 
57
- # Filter and display images
58
- for uri, distance in sorted_results:
 
 
59
  if max_distance is None or distance <= max_distance:
60
- if debug:
61
- st.write(f"URI: {uri} - Distance: {distance}")
62
  try:
63
  img = PILImage.open(uri)
64
- st.image(img, width=300)
 
65
  except Exception as e:
66
- st.error(f"Error loading image {uri}: {e}")
67
- else:
68
- if debug:
69
- st.write(f"URI: {uri} - Distance: {distance} (Filtered out)")
70
 
71
 
72
 
@@ -272,7 +270,7 @@ def page_2():
272
  st.markdown(f"```markdown\n{response}\n```")
273
 
274
  st.markdown("### Images")
275
- display_images(image_collection, query, max_distance=1.55, debug=True)
276
 
277
  st.markdown("### Videos")
278
  frame = inputs["frame"]
 
35
  def display_images(image_collection, query_text, max_distance=None, debug=False):
36
  """
37
  Display images in a Streamlit app based on a query.
 
38
  Args:
39
  image_collection: The image collection object for querying.
40
  query_text (str): The text query for images.
 
53
  # Combine uris and distances, then sort by URI in ascending order
54
  sorted_results = sorted(zip(uris, distances), key=lambda x: x[0])
55
 
56
+ # Display images side by side, 3 images per row
57
+ cols = st.columns(3) # Create 3 columns for the layout
58
+
59
+ for i, (uri, distance) in enumerate(sorted_results):
60
  if max_distance is None or distance <= max_distance:
 
 
61
  try:
62
  img = PILImage.open(uri)
63
+ with cols[i % 3]: # Use modulo to cycle through columns
64
+ st.image(img, use_column_width=True)
65
  except Exception as e:
66
+ st.error(f"Error loading image: {e}")
67
+
 
 
68
 
69
 
70
 
 
270
  st.markdown(f"```markdown\n{response}\n```")
271
 
272
  st.markdown("### Images")
273
+ display_images(image_collection, query, max_distance=1.55, debug=False)
274
 
275
  st.markdown("### Videos")
276
  frame = inputs["frame"]