philippotiger commited on
Commit
760d152
Β·
verified Β·
1 Parent(s): 6f03249

Upload run.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. run.py +31 -0
run.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Usage:
3
+ python run.py # interactive mode, paste your text
4
+ python run.py "your tip text here" # pass text directly as argument
5
+ cat tips.txt | python run.py # pipe from a file
6
+ """
7
+
8
+ import sys
9
+ import json
10
+ from inference_local import extract
11
+
12
+ def main():
13
+ # ── Mode 1: argument passed directly ──
14
+ if len(sys.argv) > 1:
15
+ text = " ".join(sys.argv[1:])
16
+
17
+ # ── Mode 2: piped from stdin (cat file | python run.py) ──
18
+ elif not sys.stdin.isatty():
19
+ text = sys.stdin.read()
20
+
21
+ # ── Mode 3: interactive, paste and press Ctrl+D ──
22
+ else:
23
+ print("Paste your prediction text below.")
24
+ print("Press Ctrl+D (Mac) when done:\n")
25
+ text = sys.stdin.read()
26
+
27
+ result = extract(text)
28
+ print(json.dumps(result, indent=2, ensure_ascii=False))
29
+
30
+ if __name__ == "__main__":
31
+ main()