File size: 758 Bytes
aa93106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import streamlit as st
from PIL import Image as PILImage

def query_and_print_results(image_vdb, query):
    results = 3
    # Query the database
    query_results = image_vdb.query(
        query_texts=[query],
        n_results=results,
        include=['uris', 'distances']
    )

    # Print the results
    for idx, uri in enumerate(query_results['uris'][0]):
        try:
            img = PILImage.open(uri)
            st.image(img, width=300)
        except Exception as e:
            st.error(f"Error loading image {uri}: {e}")

# Example usage (this part is just for illustration and testing, remove it in the actual Streamlit app):
# Assuming image_vdb is already created and query is given
# query_and_print_results(image_vdb, "example query")