Spaces:
Runtime error
Runtime error
Update src/utils/image_qa.py
Browse files- src/utils/image_qa.py +23 -20
src/utils/image_qa.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|