From 6cfff24189ffce3b239c1af2cb744a26a07b9177 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 27 Jul 2024 16:09:57 -0500 Subject: Add symlinks in cwd to results --- README.md | 2 +- client.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ad3fe2..12c6b6c 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ If you don't need PyTorch with GPU support, first run `pip3 install torch torchv This program uses a client-server architecture to watch directories with inotify and keep the model loaded in memory. It takes around 15 seconds to load the model so it wouldn't be great if every query had to wait on that. -Run `python server.py DIRS_TO_INDEX` to start the server. Then, run `python client.py SEARCH_TEXT NUM_RESULTS` to get a list of the most similar files. You can pass this to an image viewer such as `gwenview $(python client.py SEARCH_TEXT NUM_RESULTS)` to get thumbnails of image results. Note that Gwenview doesn't preserve the order of the images. +Run `python server.py DIRS_TO_INDEX` to start the server. Then, run `python client.py SEARCH_TEXT NUM_RESULTS` to get a list of the most similar files. You can pass this list to an image viewer such as Gwenview to view image results. Note that Gwenview doesn't preserve the order of the images. Alternatively, add a third parameter to `python client.py` and it will symlink `res0`, `res1`, and so on to the files on the list. diff --git a/client.py b/client.py index 8c6cbec..4249bcd 100644 --- a/client.py +++ b/client.py @@ -3,4 +3,12 @@ import sys import xmlrpc.client proxy = xmlrpc.client.ServerProxy(f"http://localhost:{os.environ.get("PORT", 8000)}") -print("\n".join(proxy.search(sys.argv[1], sys.argv[2]))) +res = proxy.search(sys.argv[1], sys.argv[2]) +print("\n".join(res)) + +if len(sys.argv) > 3: + for path in os.listdir(): + if path.startswith("res"): + os.unlink(path) + for i, path in enumerate(res): + os.symlink(path, f"res{i}") -- cgit v1.2.3-70-g09d2