NEXAS commited on
Commit
aa93106
·
verified ·
1 Parent(s): f910e67

Update src/utils/image_qa.py

Browse files
Files changed (1) hide show
  1. src/utils/image_qa.py +23 -20
src/utils/image_qa.py CHANGED
@@ -1,20 +1,23 @@
1
- import streamlit as st
2
- from io import BytesIO
3
- from IPython.display import Image, display
4
- from PIL import Image as PILImage
5
-
6
- def query_and_print_results(image_vdb,query):
7
- results=3
8
- # Query the database
9
- query_results = image_vdb.query(
10
- query_texts=[query],
11
- n_results=results,
12
- include=['uris', 'distances']
13
- )
14
-
15
- # Print the results
16
- for idx, uri in enumerate(query_results['uris'][0]):
17
- img = Image(filename=uri, width=300)
18
- st.image(img) # type: ignore
19
-
20
- # Testing it out
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image as PILImage
3
+
4
+ def query_and_print_results(image_vdb, query):
5
+ results = 3
6
+ # Query the database
7
+ query_results = image_vdb.query(
8
+ query_texts=[query],
9
+ n_results=results,
10
+ include=['uris', 'distances']
11
+ )
12
+
13
+ # Print the results
14
+ for idx, uri in enumerate(query_results['uris'][0]):
15
+ try:
16
+ img = PILImage.open(uri)
17
+ st.image(img, width=300)
18
+ except Exception as e:
19
+ st.error(f"Error loading image {uri}: {e}")
20
+
21
+ # Example usage (this part is just for illustration and testing, remove it in the actual Streamlit app):
22
+ # Assuming image_vdb is already created and query is given
23
+ # query_and_print_results(image_vdb, "example query")