diff --git a/.gitignore b/.gitignore index b70daee..65a8a3d 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,7 @@ cython_debug/ #.idea/ # mac -.DS_Store \ No newline at end of file +.DS_Store + +# vscode +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 8ee5f16..93b9ce7 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,16 @@ pip3 install open_parser ``` ## :bashfile usage +To use OpenParse via `curl` requests, you can run the following bash command from the root folder of this repository: +``` +bash parse.sh +``` +For example, to extract a table from a PDF file, you can run the following command: ``` -bash open_parser.sh +bash parse.sh gl************************************** /path/to/your/file.pdf "Return the table in a JSON format with each box's key and value." ``` + ## :scroll: Examples OpenParse can extract text, numbers and symbols from PDF, images, etc. Check out each notebook below to run OpenParse within 10 lines of code! diff --git a/extract_parse.sh b/extract_parse.sh new file mode 100644 index 0000000..786591c --- /dev/null +++ b/extract_parse.sh @@ -0,0 +1,29 @@ +#!/bin/bash +source open_parser_base.sh + +if [ "$#" -lt 3 ]; then + echo "Error: Missing arguments + Usage: $0 " + exit 1 +fi + +apiKey="$1" +func="$2" +file_path="$3" + +upload +if [ "$func" == "extract" ]; then + extract +elif [ "$func" == "parse" ]; then + prompt="$4" + mode="$5" + if [ -z "$mode" ] || [ "$mode" == "" ] || [ "$mode" == "advanced" ]; then + textract=true + else + textract=false + fi + upload + parse +fi + +echo "$result" diff --git a/open_parser.sh b/open_parser_base.sh similarity index 80% rename from open_parser.sh rename to open_parser_base.sh index 306da6f..a01ee58 100644 --- a/open_parser.sh +++ b/open_parser_base.sh @@ -1,5 +1,5 @@ -UPLOAD_URL="https://qreije6m7l.execute-api.us-west-2.amazonaws.com/v1/cambio_api/upload" -EXTRACT_URL="https://qreije6m7l.execute-api.us-west-2.amazonaws.com/v1/cambio_api/extract" +UPLOAD_URL="https://qreije6m7l.execute-api.us-west-2.amazonaws.com/v1/cambio_api/upload" +EXTRACT_URL="https://qreije6m7l.execute-api.us-west-2.amazonaws.com/v1/cambio_api/extract" PARSE_URL="https://qreije6m7l.execute-api.us-west-2.amazonaws.com/v1/cambio_api/parse" uid="null" @@ -30,13 +30,6 @@ upload() { exit 1 fi - # res=$(echo "$tmp_data" | jq -r 'to_entries | map("-F \"\(.key)=\(.value)\" \\ ") | .[] ') - # echo "${res[@]}" - # local status=$(curl -X POST \ - # "${res[@]}" \ - # -F "file=@$file_path" \ - # "$tmp_url") - local aws_access_key_id=$(echo "$tmp_data" | jq -r '."AWSAccessKeyId"') local x_amz_security_token=$(echo "$tmp_data" | jq -r '."x-amz-security-token"') local policy=$(echo "$tmp_data" | jq -r '."policy"') @@ -60,8 +53,6 @@ upload() { -F "x-amz-meta-user_prompt=$x_amz_meta_user_prompt" \ -F "file=@$file_path" \ "$tmp_url") - - # echo "upload done" } extract() { @@ -76,7 +67,6 @@ extract() { -d "$payload" \ "$EXTRACT_URL") - # echo "$response" result=$(echo "$response" | jq -r '.result.file_content') } @@ -94,28 +84,5 @@ parse() { -d "$payload" \ "$PARSE_URL") - # echo "$response" result=$(echo "$response" | jq -r '.result') -} - - -apiKey="$1" -func="$2" -file_path="$3" - -upload -if [ "$func" == "extract" ]; then - extract -elif [ "$func" == "parse" ]; then - prompt="$4" - mode="$5" - if [ -z "$mode" ] || [ "$mode" == "" ] || [ "$mode" == "advanced" ]; then - textract=true - else - textract=false - fi - upload - parse -fi - -echo "$result" +} \ No newline at end of file diff --git a/parse.sh b/parse.sh new file mode 100644 index 0000000..c2b4e40 --- /dev/null +++ b/parse.sh @@ -0,0 +1,20 @@ +#!/bin/bash +source open_parser_base.sh + +if [ "$#" -lt 2 ]; then + echo "Error: Missing arguments + Usage: $0 " + exit 1 +fi + +apiKey="$1" +file_path="$2" +prompt="$3" +textract=false + +echo "Parsing $file_path..." + +upload +parse + +echo "$result" \ No newline at end of file