Spaces:
Runtime error
Runtime error
| 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") | |