From b74cb9a104f4df9648f35565e6ea5c51b712badf Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sun, 15 Aug 2021 19:10:30 -0700 Subject: [PATCH] Move install.py to new utils dir as it's for cmdline ease of use only --- install.py | 36 ------------------------------ utils/install.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 36 deletions(-) delete mode 100644 install.py create mode 100644 utils/install.py diff --git a/install.py b/install.py deleted file mode 100644 index 14267934..00000000 --- a/install.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python3 -import pathlib -import argparse -import os -import stat - -def get_absolute(path): - return path.expanduser().absolute() - -if __name__ == '__main__': - # Setup Argument Parser - parser = argparse.ArgumentParser(description="Setup the semantic search program") - parser.add_argument('--script-dir', '-s', default="./", type=pathlib.Path, help="The project directory. Default: Current Directory") - parser.add_argument('--install-path', '-i', default="/usr/bin/semantic-search", type=pathlib.Path, help="The directory to install the script. Default: ./embeddings.pt") - parser.add_argument('--model-dir', '-m', default="./", type=pathlib.Path, help="The directory to store the model in. Default: Current Directory") - args = parser.parse_args() - - run_script_content = f'''#!/bin/bash - -# Arrange -eval "$(conda shell.bash hook)" -conda activate samvayati -cd {get_absolute(args.script_dir)} - -# Act -python3 asymmetric.py -j {get_absolute(args.model_dir)}/notes.jsonl.gz -e {get_absolute(args.model_dir)}/notes_embeddings.pt -n 5 --interactive -''' - - # Create Program Script File - with open(get_absolute(args.install_path), 'w') as run_script: - run_script.write(run_script_content) - - # Make Script Executable - absolute_install_path = str(get_absolute(args.install_path)) - st = os.stat(absolute_install_path) - os.chmod(absolute_install_path, st.st_mode | stat.S_IEXEC) diff --git a/utils/install.py b/utils/install.py new file mode 100644 index 00000000..bd63dbf6 --- /dev/null +++ b/utils/install.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import pathlib +import argparse +import os +import stat + + +def get_absolute(path): + return path.expanduser().absolute() + + +def create_script(filepath, content): + # Create Program Script File + with open(get_absolute(filepath, 'w') as run_script: + run_script.write(run_script_content) + + # Make Script Executable + absolute_install_path = str(get_absolute(filepath)) + st = os.stat(absolute_install_path) + os.chmod(absolute_install_path, st.st_mode | stat.S_IEXEC) + + +if __name__ == '__main__': + # Setup Argument Parser + parser = argparse.ArgumentParser(description="Setup the semantic search program") + parser.add_argument('--script-dir', '-s', default="./", type=pathlib.Path, help="The project directory. Default: Current Directory") + parser.add_argument('--install-dir', '-i', default="/usr/bin/", type=pathlib.Path, help="The directory to install the script. Default: ./embeddings.pt") + parser.add_argument('--model-dir', '-m', default="./", type=pathlib.Path, help="The directory to store the model in. Default: Current Directory") + args = parser.parse_args() + + run_server_content = f'''#!/bin/bash + +# Arrange +eval "$(conda shell.bash hook)" +conda activate semantic-search +cd {get_absolute(args.script_dir)} + +# Act +python3 search_types/asymmetric.py -j {get_absolute(args.model_dir)}/notes.jsonl.gz -e {get_absolute(args.model_dir)}/notes_embeddings.pt -n 5 --interactive +''' + + search_cmd_content = f'''#!/bin/bash + +# Arrange +eval "$(conda shell.bash hook)" +conda activate semantic-search +cd {get_absolute(args.script_dir)} + +# Act +python3 main.py -j {get_absolute(args.model_dir)}/notes.jsonl.gz -e {get_absolute(args.model_dir)}/notes_embeddings.pt +''' + + # Create single command to start API server exposing HTTP interface + create_script(f"{args.install_path}run_server"), run_server_content) + + # Create single command for interactive queries over commandline + create_script(f"{args.install_path}semantic-search"), search_cmd_content)