Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parse.sh, update README #20

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@ cython_debug/
#.idea/

# mac
.DS_Store
.DS_Store

# vscode
.vscode/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ 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 <your apiKey> <file path> <prompt for parse (optional, default="")>
```

For example, to extract a table from a PDF file, you can run the following command:
```
bash open_parser.sh <your apiKey> <job type: extract | parse> <file path> <prompt for parse (optional, default="")> <parse mode (optional, default=basic): basic | advanced>
bash parse.sh gl************************************** /path/to/your/file.pdf "Return the table in a JSON format with
each box's key and value."
CambioML marked this conversation as resolved.
Show resolved Hide resolved
```

## :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!
Expand Down
29 changes: 29 additions & 0 deletions extract_parse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
source open_parser_base.sh

if [ "$#" -lt 3 ]; then
echo "Error: Missing arguments
Usage: $0 <api_key> <job type: extract | parse> <file path> <prompt for parse (optional, default="")> <parse mode (optional, default=basic): basic | advanced>"
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"
39 changes: 3 additions & 36 deletions open_parser.sh → open_parser_base.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"')
Expand All @@ -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() {
Expand All @@ -76,7 +67,6 @@ extract() {
-d "$payload" \
"$EXTRACT_URL")

# echo "$response"
result=$(echo "$response" | jq -r '.result.file_content')
}

Expand All @@ -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"
}
21 changes: 21 additions & 0 deletions parse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
source open_parser_base.sh

# Check if number of arguments is not equal to 3
CambioML marked this conversation as resolved.
Show resolved Hide resolved
if [ "$#" -lt 2 ]; then
echo "Error: Missing arguments
Usage: $0 <apiKey> <file_path> <prompt (optional, default="")>"
exit 1
fi

apiKey="$1"
file_path="$2"
prompt="$3"
textract=false

echo "Parsing $file_path..."

upload
parse

echo "$result"
Loading