ITNovaML commited on
Commit
3d2a3a3
1 Parent(s): ba8a15a

Upload 3 files

Browse files
Files changed (3) hide show
  1. cli/ocr.py +22 -0
  2. cli/sparrowdata +7 -0
  3. cli/sparrowdata.py +32 -0
cli/ocr.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+
4
+ def ocr_call(api_url, file_path, post_processing, sparrow_key):
5
+ with open(file_path, "rb") as file:
6
+ # Prepare the payload
7
+ files = {
8
+ 'file': (file.name, file, 'image/jpeg')
9
+ }
10
+
11
+ data = {
12
+ 'image_url': '',
13
+ 'post_processing': post_processing,
14
+ 'sparrow_key': sparrow_key
15
+ }
16
+
17
+ response = requests.post(api_url, data=data, files=files)
18
+ if response.status_code != 200:
19
+ print('Request failed with status code:', response.status_code)
20
+ print('Response:', response.text)
21
+
22
+ return response.text
cli/sparrowdata ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ command -v python3 >/dev/null 2>&1 || { echo >&2 "Python 3 is required but it's not installed. Aborting."; exit 1; }
4
+
5
+ PYTHON_SCRIPT_PATH="sparrowdata.py"
6
+
7
+ python3 "${PYTHON_SCRIPT_PATH}" "$@"
cli/sparrowdata.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import sys
4
+ import json
5
+ from ocr import ocr_call
6
+
7
+
8
+ def ocr(api_url, file_path, sparrow_key):
9
+ result = ocr_call(api_url, file_path, sparrow_key)
10
+ pretty_result = json.dumps(json.loads(result), indent=4)
11
+ print(pretty_result)
12
+
13
+
14
+ if __name__ == "__main__":
15
+ parser = argparse.ArgumentParser(description='Sparrow OCR CLI')
16
+ parser.add_argument('-a', '--api_url', type=str, required=True, help='API URL')
17
+ parser.add_argument('-f', '--file_path', type=str, help='File path')
18
+ parser.add_argument('-p', '--post_processing', type=bool, help='Post processing')
19
+ parser.add_argument('-k', '--sparrow_key', type=str, required=True, help='Sparrow key')
20
+
21
+ args = parser.parse_args()
22
+
23
+ api_url = args.api_url
24
+ file_path = args.file_path
25
+ post_processing = args.post_processing
26
+ sparrow_key = args.sparrow_key
27
+
28
+ if not os.path.exists(file_path):
29
+ print("File does not exist")
30
+ sys.exit(1)
31
+
32
+ ocr(api_url, file_path, post_processing, sparrow_key)