mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-06 05:39:12 +00:00
Search by image at path only if query of form "file:/path/to/image"
Previously no query syntax helpers, like the "file:" prefix, were used before checking if query contains file path. This made query to image search brittle to misinterpretation and pointless checking Add test to verify search by image at file works as expected
This commit is contained in:
@@ -136,12 +136,12 @@ def extract_metadata(image_name):
|
||||
|
||||
|
||||
def query(raw_query, count, model: ImageSearchModel):
|
||||
# Set query to image content if query is a filepath
|
||||
if pathlib.Path(raw_query).is_file():
|
||||
query_imagepath = resolve_absolute_path(pathlib.Path(raw_query), strict=True)
|
||||
# Set query to image content if query is of form file:/path/to/file.png
|
||||
if raw_query.startswith("file:") and pathlib.Path(raw_query[5:]).is_file():
|
||||
query_imagepath = resolve_absolute_path(pathlib.Path(raw_query[5:]), strict=True)
|
||||
query = copy.deepcopy(Image.open(query_imagepath))
|
||||
query.thumbnail((640, query.height)) # scale down image for faster processing
|
||||
logger.info(f"Find Images similar to Image at {query_imagepath}")
|
||||
logger.info(f"Find Images by Image: {query_imagepath}")
|
||||
else:
|
||||
query = raw_query
|
||||
logger.info(f"Find Images by Text: {query}")
|
||||
|
||||
Reference in New Issue
Block a user