| """ | |
| Usage: | |
| python run.py # interactive mode, paste your text | |
| python run.py "your tip text here" # pass text directly as argument | |
| cat tips.txt | python run.py # pipe from a file | |
| """ | |
| import sys | |
| import json | |
| from inference_local import extract | |
| def main(): | |
| # ββ Mode 1: argument passed directly ββ | |
| if len(sys.argv) > 1: | |
| text = " ".join(sys.argv[1:]) | |
| # ββ Mode 2: piped from stdin (cat file | python run.py) ββ | |
| elif not sys.stdin.isatty(): | |
| text = sys.stdin.read() | |
| # ββ Mode 3: interactive, paste and press Ctrl+D ββ | |
| else: | |
| print("Paste your prediction text below.") | |
| print("Press Ctrl+D (Mac) when done:\n") | |
| text = sys.stdin.read() | |
| result = extract(text) | |
| print(json.dumps(result, indent=2, ensure_ascii=False)) | |
| if __name__ == "__main__": | |
| main() | |