Upload run.py with huggingface_hub
Browse files
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()
|