From 528d65c6bd9954cfd96de57de05498dc4c563e0f Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Wed, 20 Nov 2024 11:55:10 +0100 Subject: moved input to another package --- __main__.py | 32 +++++++++++++------------------- modules/input_handlers/__init__.py | 0 modules/input_handlers/stdin_input.py | 9 +++++++++ 3 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 modules/input_handlers/__init__.py create mode 100644 modules/input_handlers/stdin_input.py diff --git a/__main__.py b/__main__.py index 008ceb4..4677b7c 100644 --- a/__main__.py +++ b/__main__.py @@ -7,6 +7,7 @@ from .modules.config import load_config from .modules.hassil.recognize import recognize from .modules.hassil.util import merge_dict from .modules.hassil.intents import Intents, TextSlotList +from .modules.input_handlers.stdin_input import get_input_stdin from .modules.intents import * @@ -37,25 +38,18 @@ def main(): intents = Intents.from_dict(input_dict) - try: - for line in sys.stdin: - line = line.strip() - if not line: - continue - - result = recognize(line, intents, slot_lists=slot_lists) - if result is not None: - result_dict = { - "intent": result.intent.name, - **{e.name: e.value for e in result.entities_list}, - } - print(result_dict) - handler = getattr(globals()[result_dict["domain"]], result_dict["intent"]) - handler(result_dict, config) - else: - print("") - except KeyboardInterrupt: - pass + for input_text in get_input_stdin(): + result = recognize(input_text, intents, slot_lists=slot_lists) + if result is not None: + result_dict = { + "intent": result.intent.name, + **{e.name: e.value for e in result.entities_list}, + } + print(result_dict) + handler = getattr(globals()[result_dict["domain"]], result_dict["intent"]) + handler(result_dict, config) + else: + print("") if __name__ == '__main__': main() \ No newline at end of file diff --git a/modules/input_handlers/__init__.py b/modules/input_handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/modules/input_handlers/stdin_input.py b/modules/input_handlers/stdin_input.py new file mode 100644 index 0000000..044ac0d --- /dev/null +++ b/modules/input_handlers/stdin_input.py @@ -0,0 +1,9 @@ +import sys + +def get_input_stdin(): + for line in sys.stdin: + line = line.strip() + if not line: + continue + + yield line \ No newline at end of file -- cgit v1.2.3-70-g09d2