File size: 882 Bytes
760d152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
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()